Coding VenturesJekyll2014-08-19T23:47:53+00:00http://codingventures.com/Kerem Karatalhttp://codingventures.com/you@email.com
http://codingventures.com/articles/Custom-Views-In-XCode-6
http://codingventures.com/articles/Custom-Views-In-XCode-62014-08-20T00:00:00-00:002014-08-20T00:00:00+00:00Kerem Karatalhttp://codingventures.comyou@email.com<p>Using custom views in Interface Builder have been traditionally pretty non-eventful. All you would get was a simple white box when you insert your custom view into XCode. XCode 6 brings in a whole new set of capabilities for custom view development. In a similar vein to what you can do in playgrounds, you can develop a custom view in XCode 6 and get immediate visual feedback as you are building your code. I built a simple project which has 2 custom views. You can find the full source code at my <a href="https://github.com/keremk/soundcloud_player">github repo</a>. For this project, I decided to build some different versions of the ever so popular SoundCloud waveforms as my custom views. The first one is the familiar rectangular waveform view (WaveformView). The second one is wraps the waveform around a circular path (PolarAreaView). And of course, I picked Swift as my language to build these.</p>
<p><img src="/images/xcode6-project-s1.png" alt="Interface Builder Custom Views" /></p>
<p>As you can see in the above screenshot, I am showing the custom view in my storyboard layout side by side with the code behind it in the assistance view. If you have enough screen real estate this is the preferred way of building your view. As you modify your code, you will notice that the view will change and adopt to what you are writing in almost realtime. (Almost depending how powerful your Mac is). The trick to open the PolarAreaView in the assistant editor is to use Option+Shift+Click on the file name of the view, which will give you an option to pick where you want to open that file. Then you can pick the assistant editor area to have them display side by side.</p>
<p><img src="/images/xcode6-assistant-editor.png" alt="Show Where to Open the File" /></p>
<p>There are few things that are noteworthy to mention. First of all, the views need to be created in a custom framework which is also another new feature in iOS 8. This way, XCode 6 can load the framework where the custom view is located, and run it inside the Storyboard to render it.</p>
<p>Second, you need to mark your class as <code>IBDesignable</code>, which will tell XCode 6 that your view can be shown live rendered: </p>
<pre><code> @IBDesignable
public class PolarAreaView: UIView {
...
}
</code></pre>
<p>Once you add these, the view will start showing up in the storyboard editor as shown in the screenshots. If you look at the screenshot carefully, you will also notice that there are some new custom properties in the rightmost pane under the Polar Area View. These properties are also marked in the code using <code>IBInspectable</code>:</p>
<pre><code> @IBInspectable
public var innerRadius:CGFloat = 5.0 {
didSet { updateLayerProperties() }
}
@IBInspectable
public var nonHighlightedColor: UIColor = UIColor.lightGrayColor() {
didSet { updateLayerProperties() }
}
</code></pre>
<p>Notice that if the property is of type <code>UIColor</code>, XCode will show a rich color picker. Also note that you would need to implement the <code>didSet</code> callbacks in the properties to update the <code>CALayer</code> properties in order to reflect the changes in the view.</p>
<p>Another thing you may need to do is to implement a method called <code>prepareForInterfaceBuilder</code>. XCode will call this method before the view is shown so that you can provide things like fake data. In the below code, I am providing fake radius values for the <code>PolarAreaView</code>.</p>
<pre><code> override public func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
radii = [0.32142857142857145,
0.8285714285714286,
0.8571428571428571,
0.7714285714285715]
}
</code></pre>
<p>In terms of the custom views, I used <code>CALayer</code> instead of overriding <code>drawRect</code> which is known to give better performance. The other interesting tidbit is using the mask property with a <code>CAShapeLayer</code>, which provides pretty fast way to display highlighted colors, instead of recreating the paths everytime the gesture recognizer updates the covered/uncovered portion.</p>
<p>Building custom views became a lot of fun in XCode 6! </p>
<p><a href="http://codingventures.com/articles/Custom-Views-In-XCode-6">Custom Views in XCode 6</a> was originally published by Kerem Karatal at <a href="http://codingventures.com">Coding Ventures</a> on August 20, 2014.</p>
http://codingventures.com/articles/Dating-Swift
http://codingventures.com/articles/Dating-Swift2014-06-22T00:00:00-00:002014-06-21T00:00:00+00:00Kerem Karatalhttp://codingventures.comyou@email.com<p>This year Christmas arrived in June for the iOS developers. Out of nowhere, Apple introduced a surprise new language, Swift. Following its introduction, there has been a lot of blog posts on it. So I figured, I should contribute as well.</p>
<p>When I am learning something new, I like to take on a mission and go from there. In this case, my mission is to take the extremely verbose NSDate, NSDateComponents, NSCalendar APIs and provide wrappers using the niceties provided by Swift. Dealing with date computations is a pretty regular requirement for many applications. Reducing the cognitive load on dealing with those computations is a worthy mission to take on. Ruby’s ActiveSupport provides some very useful <a href="http://guides.rubyonrails.org/active_support_core_extensions.html#extensions-to-date">extensions</a> to deal with many Date calculations. It is now possible to bring the same level of syntactic sugar for Date calculations to iOS using Swift. This is also a great exercise on understanding building Domain Specific Languages (DSL) on top of Swift and learning more about some of the features Swift introduces.</p>
<h2 id="expressing-days-months-years">Expressing days, months, years</h2>
<p>Writing readable and concise code is always a great win. Well, out-of-the-box in Objective-C, dealing with Date APIs does not really lend itself to a very concise code. (For Objective-C, there is a great project called <a href="https://github.com/supermarin/ObjectiveSugar">ObjectiveSugar</a> that adds simplifying syntactic sugar.)</p>
<p>So let’s start with expressing days, months, years etc. in a very readable format. How about something like 3.days, 4.months, 2.years ?</p>
<p>Luckily literal integers are of struct type <code>Int</code> in Swift. So you can extend them, just like you can extend any other types.</p>
<pre><code> extension Int {
var days: NSTimeInterval {
let DAY_IN_SECONDS = 60 * 60 * 24
var days:Double = Double(DAY_IN_SECONDS) * Double(self)
return days
}
}
</code></pre>
<p>Voila! Now you can type <code>3.days</code> and you will get the corresponding <code>NSTimeInterval</code> that describes 3 days. </p>
<h2 id="calculating-dates">Calculating dates</h2>
<p>Now that we extended the <code>Int</code> type to return <code>NSTimeInterval</code> for days, months, years etc. we can start making some date calculations. </p>
<pre><code> NSDate.date()
</code></pre>
<p>returns today’s date. Let’s try and calculate </p>
<pre><code> NSDate.date() - 2.months
</code></pre>
<p>If we use a similar extension to the above <code>Int</code> extension, unfortunately we will not be taking into account the correct number of days in a month for the last 2 months. Our months extension will just assume that every month is 30 days, and return the number of seconds for 30 days. And then if we just use the <code>dateByAddingTimeInterval</code> method on <code>NSDate</code>, we won’t get our expected result. To solve this problem, as you know from the Cocoa APIs, we need to use <code>NSDateComponents</code> and explicitly indicate that we are subtracting months. In order to do that, we need to differentiate between one month worth of seconds vs. thirty day worth of seconds. Type system comes to the rescue:</p>
<p>Let’s introduce simple new type called TimeInterval:</p>
<pre><code> struct TimeInterval {
var interval: Int
var unit: TimeIntervalUnit
init(interval: Int, unit: TimeIntervalUnit) {
self.interval = interval
self.unit = unit
}
}
</code></pre>
<p>where the TimeIntervalUnit is the below enumeration:</p>
<pre><code> enum TimeIntervalUnit {
case Seconds, Minutes, Hours, Days, Months, Years
func dateComponents(interval: Int) -> NSDateComponents {
var components:NSDateComponents = NSDateComponents()
switch (self) {
case .Seconds:
components.second = interval
case .Minutes:
components.minute = interval
case .Days:
components.day = interval
case .Months:
components.month = interval
case .Years:
components.year = interval
default:
components.day = interval
}
return components
}
}
</code></pre>
<p>Notice how we can add functions to enumerations! In this case our function simply creates an <code>NSDateComponents</code> object and maps enumerations to the <code>NSDateComponent</code> types.</p>
<p>With that we can now change our extension to <code>Int</code> to return <code>TimeInterval</code> instead of the <code>NSTimeInterval</code> :</p>
<pre><code> extension Int {
var months: TimeInterval {
return TimeInterval(interval: self, unit: TimeIntervalUnit.Months);
}
}
</code></pre>
<p>And now with that we can create a new operator overload for dates to take <code>TimeInterval</code> as the right operand:</p>
<pre><code> @infix func - (let left:NSDate, let right:TimeInterval) -> NSDate {
var calendar = NSCalendar.currentCalendar()
var components = right.unit.dateComponents(-right.interval)
return calendar.dateByAddingComponents(components, toDate: left, options: nil)
}
</code></pre>
<p>So now the below gives us the correct date (exactly one month from today, not 30 days):</p>
<pre><code> var lastMonth = NSDate.date() - 1.months
</code></pre>
<p>Well now that we have a strong type called Month, wouldn’t it be great if we can do this too?</p>
<pre><code> var twoMonthsAgo = 2.months.ago
</code></pre>
<p>And of course, it is doable as well, lets go back to TimeInterval:</p>
<pre><code> struct TimeInterval {
var interval: Int
var unit: TimeIntervalUnit
var ago: NSDate {
var calendar = NSCalendar.currentCalendar()
let today = NSDate.date()
var components = unit.dateComponents(-self.interval)
return calendar.dateByAddingComponents(components, toDate: today!, options: nil)
}
init(interval: Int, unit: TimeIntervalUnit) {
self.interval = interval
self.unit = unit
}
}
</code></pre>
<h2 id="comparing-dates">Comparing dates</h2>
<p>Cocoa also has very verbose APIs to compare 2 dates with each other, and this presents another perfect reason to once again use operator overloads:</p>
<pre><code> @infix func < (let left:NSDate, let right: NSDate) -> Bool {
var result:NSComparisonResult = left.compare(right)
var isEarlier = false
if (result == NSComparisonResult.OrderedAscending) {
isEarlier = true
}
return isEarlier
}
</code></pre>
<p>So now this is much better and more readable (at least in my opinion) than using the <code>NSOrderAscending</code>, <code>NSOrderDescending</code> stuff…</p>
<pre><code> var lastMonth = NSDate.date() - 1.months
if (lastMonth < NSDate.date()) {
println("Last month is earlier than this month!")
}
</code></pre>
<h2 id="simple-date-helpers">Simple date helpers</h2>
<p>While we are at it, wouldn’t it be great to introduce quick helpers for well known colloquial date accessors, like yesterday, last week, tomorrow etc.? That is also easy, let’s see how we can build out yesterday. Here we will be adding a class function instead of an instance one to the <code>NSDate</code></p>
<pre><code> extension NSDate {
class func yesterday() -> NSDate {
return NSDate.date() - 1.days
}
}
</code></pre>
<p>And voila! </p>
<pre><code> var yesterday = NSDate.yesterday()
</code></pre>
<h2 id="formatting-dates">Formatting Dates</h2>
<p>Another painful API is the verbose NSDateFormatter APIs to format <code>NSDate</code> to <code>String</code> and back. Wouldn’t it be great if there was a function like toS: (using camel casing in Swift, as opposed to the to_s in Ruby)</p>
<pre><code> var formatted = yesterday.toS("mm/dd/yyyy")
</code></pre>
<p>Well easy:</p>
<pre><code> extension NSDate {
func toS(let format:String) -> String? {
var formatter:NSDateFormatter = NSDateFormatter()
formatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
formatter.timeZone = NSTimeZone()
formatter.dateFormat = format
return formatter.stringFromDate(self)
}
}
var yesterday = NSDate.yesterday().toS("MM/dd")
</code></pre>
<p>And here is the inverse:</p>
<pre><code> extension String {
func toDate(let format:String = "dd/MM/yyyy") -> NSDate? {
var formatter:NSDateFormatter = NSDateFormatter()
formatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
formatter.timeZone = NSTimeZone()
formatter.dateFormat = format
return formatter.dateFromString(self)
}
}
var withFormat = "12/01/2014".toDate(format: "MM/dd/yyyy")
var usingDefaultFormat = "12/01/2014".toDate()
</code></pre>
<h2 id="one-more-thing">One more thing</h2>
<p>So there is always one more thing (Or we always hoped there is). This one is not about date APIs but something else we use all the time; iterating over a range, you know the good old for loops we used to use before blocks and functional concepts were in. Well, Swift introduces a great new built-in feature called Ranges. So you can write code like:</p>
<pre><code> for i in (0..7) {
println("Hello \i")
}
</code></pre>
<p>Well that is nice, but not as nice as:</p>
<pre><code> (0..7).each { println("\$0") }
</code></pre>
<p>Can we do that in Swift? Yep! For that we need to extend the <code>Range</code> built-in type with a new function called <code>each</code>. This function will take a closure with a generic type (where we pass in the iteration index) and returns void. Here it is:</p>
<pre><code> extension Range {
func each(iterator : (T) -> ()) {
for i in self {
iterator(i)
}
}
}
</code></pre>
<p>And here is a controversial (may be going too far with operator overloading) but fun one. Do you want to append to the end of a string using a « operator? (Like Ruby)</p>
<pre><code> @infix func <<<T> (inout left: T[], let right: T) {
left.append(right)
}
var input = Int[]()
(0..10).each { input << $0 }
</code></pre>
<h2 id="conclusion">Conclusion</h2>
<p>In short, Swift gives us a very expressive set of language tools to create concise and useful APIs. The current Cocoa API set is not yet making use of these language features. So using APIs like NSDate out-of-the-box is still a pain in the ass. But the good news is, building your own wrappers on top of the existing Cocoa APIs is very easy and a lot fun. Apple will probably introduce more native Swift APIs (probably starting with Foundation APIs) in the next year. But in the meantime, we can build our own with very little effort as well.</p>
<p>You can access the full playground for this <a href="https://gist.github.com/keremk/c6da4c24953eb66f21b2">gist here</a>.</p>
<p>Have fun!</p>
<p><a href="http://codingventures.com/articles/Dating-Swift">Dating Swift</a> was originally published by Kerem Karatal at <a href="http://codingventures.com">Coding Ventures</a> on June 21, 2014.</p>
http://codingventures.com/articles/Should-Engineering-Managers-Code
http://codingventures.com/articles/Should-Engineering-Managers-Code2014-01-18T00:00:00-00:002014-01-18T00:00:00+00:00Kerem Karatalhttp://codingventures.comyou@email.com<p>There is a <a href="https://news.ycombinator.com/item?id=7057651">heated discussion</a> going on in Hacker News, started after an <a href="http://www.drdobbs.com/architecture-and-design/engineering-managers-should-code-30-of-t/240165174">article</a> written by <a href="http://www.eliothorowitz.com/">Eliot Horowitz</a>, CTO of <a href="http://www.mongodb.org/">MongoDB</a>. He claims that engineering managers should code 30% of their time and then goes on to give good tips on how to go about finding the time. In the usual Hacker News style, this created a very heated debate where the top comment is: “This is ridiculous… And honestly, this is just BS.”. One common thread mentioned in the discussions is the sports analogy (NFL, MLB). In this case, the engineering manager role is compared to the various levels of sports coaches. And the argument goes something like this: Just as it is ridiculous for a coach to play alongside the players or train with them in the field, it is also ridiculous for engineering managers to code alongside the team. They have too many things to do as a manager, and spending time on coding is surely not time well spent!</p>
<p>Even though, there is some merit in the analogy between sports teams and software teams, I think the comparison of the specific duties or elements are not appropriate. Yes, a sports coach does not play in the field. But have you ever seen one who does not show up to the game? A sports coach always stays with their team during the game, running around giving directions, reading their and the opposing teams’ plays. They actively participate in that game, by being there shouting, running, yelling if necessary. Well sports is a very different beast than software development. So I am not going to attempt to partition elements of a sports team or a game, and try to compare those elements one by one to elements of a software development project. The actual comparison need to stay at the level of intent. At a meta level, a successful coach is always committed to the team and the game. Similarly a successful general is always committed to his soldiers in the battlefield, charging the enemy and fighting alongside them. So in that sense, an effective engineering manager needs to be 100% involved with their team and the product. Then the question is: Is coding a must-have activity in order to be 100% involved with your team? </p>
<p>In a software project, the only truth lies in the code. The documentations rot (or not exist in many cases), the diagrams never get redrawn after the code is implemented. The complexity of a software project lies in the way it is implemented. You cannot just say: “Well it makes sense that component A calls component B and not vice-versa” and assume that is the case. So the point is not about knowing how to code or having been a coder before. You could even be an active coder, working on your own pet projects or company research initiatives. The point is to intimately know the codebase you are managing. If you are a startup CTO, the chances are you probably built a good portion of it, so you would know it quite well. You can probably keep yourself up-to-date with relatively lesser effort. However, if you get hired as an engineering manager to a codebase, you have not worked on, then you have your work cut-out for you. Without knowing that codebase, you will not deeply understand whether you need to pay that technical debt or not. </p>
<p>There is only one way to truly understand what is going on, and that is to get your hands dirty. You will need to setup a development machine, checkout the codebase and run your first build. But that is just a starter, in order to learn something you will need to actually do it. You would soon need to poke some parts, yank some other parts, break your (own) build, add a few baby features, fix a few bugs perhaps. The thing is, this is not different than, what a new developer in the team would do to come up to speed with the codebase. So it is not about knowing how to code or having coded before. It is about knowing that particular codebase you are working on. Only then you can know the strengths and weaknesses of that codebase first hand. You will have a better feel for when to pay the technical debt and understand how to go about estimating what it would take to add a new feature. And only then you will be truly part of your team. You will be able to defend your team against unreasonable demands. You will be truly accountable for what you and your team produce. As for analogies go, which one sounds like a more effective leader that you are likely to follow in the battlefield? One that is standing tall on his horse with a drawn out sword or the one that stays in his palace talking to his generals and waiting for the pigeon to arrive with the news?</p>
<p>So does it take 30% of your time to get immersed and keep being immersed in your codebase? Well it depends. It may even take more than that initially, if you are brought into an existing and large codebase. But it is a price that needs to be paid. Otherwise you will be driving in blind. Hey, who said being an engineering manager is simple?</p>
<p><a href="http://codingventures.com/articles/Should-Engineering-Managers-Code">Should Engineering Managers Code?</a> was originally published by Kerem Karatal at <a href="http://codingventures.com">Coding Ventures</a> on January 18, 2014.</p>
http://codingventures.com/articles/Getting-Started-with-Python
http://codingventures.com/articles/Getting-Started-with-Python2013-12-27T00:00:00-00:002013-12-27T00:00:00+00:00Kerem Karatalhttp://codingventures.comyou@email.com<p>A week or so ago, I had to come up with a solution to export a cleaner version of our data stored in our application database. We are using Postgres as our database and making use of the <a href="http://clarkdave.net/2013/06/what-can-you-do-with-postgresql-and-json/">JSON storage</a> and <a href="http://www.postgresql.org/docs/9.0/static/hstore.html">HSTORE key-value storage</a> for our application needs. But when it comes to exporting our data for analysis, having columns with JSON and HSTORE encoded key-value pairs is not convenient. So I decided to take the opportunity to dive into using Python. After all, Python is quickly becoming <a href="http://www.r-bloggers.com/the-homogenization-of-scientific-computing-or-why-python-is-steadily-eating-other-languages-lunch/">the de-facto language for data science</a>. </p>
<p>However I am a noob when it comes to Python. As such, this blog post is intended for noobs like me. I will try to explain how to setup a development environment for Python and give some tips on where to get started in learning Python for data science. I am also assuming that this is not your first language and you are probably a professional programmer who is fluent in one-or-more languages, and good with the command-line. If so, let’s start:</p>
<h2 id="what-to-install">What to install?</h2>
<p>When you start googling around, you will run into many alternatives. Your first decision is going to be around using Python 2.7 or 3.3, which turns out to be not backwards compatible. Yes, it definitely sounds like <a href="https://speakerdeck.com/pyconslides/python-3-dot-3-trust-me-its-better-than-python-2-dot-7-by-dr-brett-cannon">Python 3.3 is better than 2.7</a> and after 5 years it is probably time to move. Looks like most popular packages including the machine learning package <a href="https://github.com/scikit-learn/scikit-learn/commit/22dbecccff5b856d1db0c97310f542fbc5df4f64">scikit-learn</a> has made the move to Python 3.3+ this year, so we should be good. </p>
<p>The second decision is in choosing a package manager/distribution. The most common choice is to use <a href="https://pip.readthedocs.org/en/latest/">PIP</a>. But as I was searching around, I found out about another alternative specifically geared towards scientific computing. It is called <a href="http://www.continuum.io/blog/conda">Conda</a> and it sounded like a pretty convenient way to quickly setup my system with a set of data science related packages. Even though the default installation comes with 2.7, they also support <a href="http://continuum.io/blog/anaconda-python-3">Python 3.2+</a>. Also once you start using Conda, you don’t have to worry about leaving behind PIP. Apparently Conda falls back to PIP, if it can not find the distribution package you are looking for. <a href="http://stackoverflow.com/questions/18640305/how-to-keep-track-of-pip-installed-packages-in-an-anaconda-conda-env">This Stackoverflow thread</a> has more on that.</p>
<p>The third decision is to figure out your development environment, text editor to use etc. I am a big fan of <a href="http://www.sublimetext.com/3">Sublime Text</a> and I decided to keep using that. My terminal choice is <a href="http://www.iterm2.com/#/section/home">iTerm</a>, shell choice is <a href="https://github.com/robbyrussell/oh-my-zsh">zsh</a> and finally as the debugger/REPL environment, I settled on <a href="http://ipython.org/">iPython</a>. More on that later… </p>
<p>If you like IDEs better, Jetbrains has a version of their IDE for Python development, called <a href="http://www.jetbrains.com/pycharm/">PyCharm</a>.There is a free community edition as well as a paid one, which comes with various framework support including Django etc. I also recently bumped into a brand new OSX native Python IDE that claims to be inspired by XCode called <a href="http://celestialteapot.com/exedore/">Exedore</a>. I have not had a chance to try it out myself, but if you are interested, there is a free trial.</p>
<p><a href="http://continuum.io/downloads">Anacondo distribution</a> contains all the interesting packages as well as the iPython and iPython Notebook. It is free and probably the most straight forward way to get started. I picked the GUI package installer amongst the choices for Mac OSX. When you first install it, you need to set your path, so that it reads from the <code>anaconda/bin</code> path instead. </p>
<h2 id="replhttpenwikipediaorgwikireade28093evale28093printloop-environment---ipython"><a href="http://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop">REPL</a> Environment - iPython</h2>
<p>Being used to the Ruby goodies, including the Ruby REPL called <a href="http://pryrepl.org/">pry</a>, my first instinct is to look for a good REPL environment. And iPython delivers on that. Especially when learning a new language as well as testing out some quick thoughts, <a href="https://speakerdeck.com/conradirwin/repl-driven-development-with-pry">REPL driven development</a> is very productive. Plus you can also use iPython for debugging your scripts.</p>
<p>Let’s say, you have a simple Hello World script like below in file <code>hello_world.py</code></p>
<div class="highlight"><pre><code class="language-python" data-lang="python"><span class="lineno">1</span> <span class="kn">from</span> <span class="nn">IPython.core.debugger</span> <span class="kn">import</span> <span class="n">Tracer</span><span class="p">;</span> <span class="n">breakpoint</span> <span class="o">=</span> <span class="n">Tracer</span><span class="p">()</span>
<span class="lineno">2</span>
<span class="lineno">3</span> <span class="n">output</span> <span class="o">=</span> <span class="s">"Hello World"</span>
<span class="lineno">4</span> <span class="n">breakpoint</span><span class="p">()</span>
<span class="lineno">5</span> <span class="k">print</span> <span class="n">output</span></code></pre></div>
<p>Then if you open up your ipython shell, and call the magic command <code>%run hello_world.py</code>, you will stop at the breakpoint you defined on line 5:</p>
<p>```</p>
<pre><code> In [5]: %run hello_world.py
> /Users/foo/PyTest/hello_world.py(5)<module>()
3 output = "Hello World"
4 breakpoint()
----> 5 print output
</code></pre>
<p>```</p>
<p>To learn more about iPython, you can read the <a href="http://ipython.org/ipython-doc/dev/interactive/tutorial.html">tutorial</a> on the official iPython site.</p>
<h2 id="ipython-notebook">iPython Notebook</h2>
<p>Going through iPython documentation, I also bumped into another great tool called the iPython Notebook. Let’s say you come up with a cool analysis of your data and you would like to share the code, the math behind it, inline explanation of what your code does and finally the full output of running your code, including graphs. That is where iPython Notebook comes handy. You can use the <a href="http://nbviewer.ipython.org/">public viewer</a> to share your notebooks with other people if you don’t mind it being available publicly. This is especially great for public presentations, where you can go through your code and its output and explain it to your audience and then make it available to them after your presentation. You can also set up a private <a href="http://nbviewer.ipython.org/github/Unidata/tds-python-workshop/blob/master/ipython-notebook-server.ipynb">internal server</a> as well. If you like to host it in the cloud instead, there are some good <a href="https://gist.github.com/iamatypeofwalrus/5183133">step-by-step instructions</a> on how to do that on AWS. Or you can try out some 3rd party <a href="http://www.continuum.io/wakari">hosted</a> <a href="http://www.picloud.com/">solutions</a> for privately sharing your notebooks.</p>
<p>To get this setup on your computer, all you need to do is to run <code>ipython notebook</code> which starts a new server locally and fires up your browser. In the browser session, you can then create new notebooks, load existing ones and save them for later usage. The notebook file format is a single json with the .ipynb extension. To share your notebooks publicly, all you need to do is to create a new public gist on Github and copy its GistID to the page you see at <a href="http://nbviewer.ipython.org">http://nbviewer.ipython.org</a>. You can also convert your notebooks to other formats using the <a href="http://ipython.org/ipython-doc/stable/interactive/nbconvert.html#nbconvert">nbconvert tool</a> for non-interactive viewing.</p>
<h2 id="learning-python">Learning Python</h2>
<p>Now that, you set up your environment and learned how to share your code with your colleagues and friends, it is now time to do some actual coding. There is a list of learning python sources on the <a href="https://wiki.python.org/moin/BeginnersGuide/Programmers">python.org</a> wiki, but my favorite is the <a href="https://developers.google.com/edu/python/">Google Python Class</a>. Another even shorter intro for experienced developers is <a href="http://www.stavros.io/tutorials/python/">10-minute Intro to Python</a>.</p>
<p>Once you get a quick grasp of Python, if you are doing some data science work, I highly recommend <a href="http://www.gregreda.com/2013/10/26/intro-to-pandas-data-structures/">this tutorial</a> for using <a href="http://pandas.pydata.org/">Pandas</a>. After reading that tutorial and once you get used to using iPython and iPython Notebook, you will probably stop using Excel for many of your basic data manipulations. </p>
<p>If you have access to the <a href="https://ssl.safaribooksonline.com/trial">Safari Books Online Bookshelf</a>, I would also recommend adding <a href="http://shop.oreilly.com/product/0636920023784.do">Python for Data Analysis</a> and <a href="http://shop.oreilly.com/product/9780596529321.do">Programming Collective Intelligence</a> to your bookshelf to get going with Data Science using Python. Another really cool resource is an online book called <a href="http://nbviewer.ipython.org/github/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/blob/master/Prologue/Prologue.ipynb">Probabilistic Programming and Bayesian Methods for Hackers</a>. The whole book is interactive and is rendered with the iPython Notebook Viewer!</p>
<p>And one final tip, if you are looking for an interactive alternative to <a href="http://matplotlib.org/">Matplotlib</a>, check out the up-and-coming library <a href="http://bokeh.pydata.org/">Bokeh</a>.</p>
<p><a href="http://codingventures.com/articles/Getting-Started-with-Python">Getting Started with Python and Data Science</a> was originally published by Kerem Karatal at <a href="http://codingventures.com">Coding Ventures</a> on December 27, 2013.</p>
http://codingventures.com/articles/Moving-To-Github-Pages-And-Jekyll
http://codingventures.com/articles/Moving-To-Github-Pages-And-Jekyll2013-12-26T00:00:00-00:002013-12-26T00:00:00+00:00Kerem Karatalhttp://codingventures.comyou@email.com<p>When I decided to start blogging again, I realized that my blogging engine of choice at the time, Wordpress, was aging. I was getting emails from Dreamhost that, I should tend to my blog since it appeared to be hacked. On top of all that, the design of my site was aging and it needed to be updated to a <a href="http://coding.smashingmagazine.com/2011/01/12/guidelines-for-responsive-web-design/">responsive design</a>.</p>
<p>Instead of staying with Wordpress and Dreamhost, updating my designs and cleaning up the hacked pages, I decided to switch to an entirely new system. As I was looking for a new blogging engine, I decided to move to a statically generated system. There are quite a few alternatives out there at the moment. Some of them are <a href="http://blog.bmannconsulting.com/node-static-site-generators">node based</a> and some are <a href="https://www.ruby-toolbox.com/categories/static_website_generation">Ruby based</a>. Since Github pages support the popular Ruby based <a href="http://jekyllrb.com">Jekyll</a> (which was originally built by Tom Preston-Werner anyways) natively, I decided to go with that. However if you are a Javascript/Node.js fan, you may also want to try out the popular <a href="http://wintersmith.io/">Wintersmith</a>. As a quick note, I also looked into using <a href="http://octopress.org/">Octopress</a>, which is a bundling of some plugins, some convenient rake tasks and templating system for Jekyll. But for now, I decided to stay on Jekyll itself.</p>
<p>To set this up, there is a quick set of instructions on the <a href="http://pages.github.com/">Github Pages</a> site. Or even better, someone just very recently wrote a <a href="http://24ways.org/2013/get-started-with-github-pages/">step by step instructions</a> on how to set your system up with Jekyll and Github Pages. Note that Github pages support 2 types of web sites - Project and User/Organization. In this case, I set up a User/Organization site which is appropriate for a blog and you can only have one of those per Github account. BTW, did I already say that setting up Github Pages is free?</p>
<p>To create and edit content, I am using my favorite editor <a href="http://www.sublimetext.com/3">Sublime Text</a> and a markdown previewer called <a href="http://markedapp.com/">Marked</a>. However I initially bumped into Marked in the Mac Appstore and purchased it from there. I then, realized that the one on the AppStore is an older version (1.3.x) and it is not updated there anymore. So in order to get proper syntax highlighting support as well as <a href="http://marked2app.com/">many other great features</a>, you need to purchase it from their web site. The markdown code block support on the Mac AppStore version of the app is unfortunately buggy. I am now testing their web site version. By the way, the markdown syntax on Github is slightly <a href="https://help.github.com/articles/github-flavored-markdown">different</a>. There is also a <a href="https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet">great markdown cheatsheet</a>, I use quite often. </p>
<p>Finally, I wanted to pick a ready-made template for my site. These days, I really like the styles of <a href="https://medium.com/">Medium</a> and <a href="https://svbtle.com/">Svbtle</a>. After a bit of googling around, I bumped into <a href="http://mmistakes.github.io/so-simple-theme/">this template</a> and decided to make it my own.</p>
<p><a href="http://codingventures.com/articles/Moving-To-Github-Pages-And-Jekyll">Moving to Github Pages and Jekyll</a> was originally published by Kerem Karatal at <a href="http://codingventures.com">Coding Ventures</a> on December 26, 2013.</p>
http://codingventures.com/articles/First-Post
http://codingventures.com/articles/First-Post2013-12-25T00:00:00-00:002013-12-25T00:00:00+00:00Kerem Karatalhttp://codingventures.comyou@email.com<p>After over 4 years of not blogging, this Christmas holiday, I decided to give it another shot. This time, I will try to make a <a href="http://www.amazon.com/The-Power-Habit-What-Business-ebook/dp/B0055PGUYU">habit</a> of it and will track my blogging frequency using a pretty cool app called <a href="https://lift.do/">Lift</a>. </p>
<p>So what am I planning to blog about?</p>
<ul>
<li>Tech tips and tricks: Favorite tools, frameworks, learning new languages…</li>
<li>Programming journal: If I spent time on learning something, I will try to document what I learned here. My programming interests are in Ruby, ObjectiveC (iOS development), Python (Data Science), Scala (just starting to learn…)</li>
<li>Opinions on software development …</li>
<li>Startup life…</li>
<li>Lifehacks… </li>
</ul>
<p>I changed my blogging engine and hosting providers from Wordpress and Dreamhost to static HTML based <a href="http://jekyllrb.com/">Jekyll</a> and <a href="http://pages.github.com/">Github Pages</a>. More on that in my upcoming post on <a href="/articles/Moving-To-Github-Pages-And-Jekyll/">Switching to Github Pages</a>…</p>
<p>So since I changed my blogging platform, the question was what to do with my old posts. Most of them are rather old and not relevant anymore so I dropped them off as I migrated. However I am going to include one of my posts, that is still getting some sizeable traffic, with a quick updated set of links.</p>
<p><a href="http://codingventures.com/articles/First-Post">First Post After 4 Years...</a> was originally published by Kerem Karatal at <a href="http://codingventures.com">Coding Ventures</a> on December 25, 2013.</p>