Blog @nicoschuele.com


Set up Rails and PostgreSQL easily on OS X Mavericks

About a year ago, I wrote a tutorial about installing a Ruby on Rails development environment on OS X Mountain Lion. Here's an updated and easier version to set up Ruby, Rails and PostgreSQL on a fresh install of OS X 10.9 Mavericks.

Command line tools

Previously, you had to install the full version of Apple Xcode. Not anymore. Still, you will need to install the command line tools before going further. Open a terminal window and type this:

xcode-select --install

You will be prompted with a dialog containing 3 options: get Xcode, not now, Install. Select Install and wait for the operation to complete. This will install utilities like Git. Even if you don't use Git, you will need it to install RVM. Let's do that now.

RVM and why you need it

In order to develop using the Rails framework, you need to have a Ruby interpreter installed on your machine. The good news is that OS X comes pre-installed with one. The bad news is that it is an older version than the one we need.

Ruby Version Manager or RVM for short is a very useful piece of software that will allow us to have multiple versions of Ruby (and Rails and any other Gem) on our machine. Think of RVM as a virtual environments manager which will house specific versions of Ruby. You can then switch between versions at will.

Open a terminal and type the following command (you may need to enter your password at some point):

curl -L get.rvm.io | bash -s stable

Get Ruby

Now that RVM is installed on your machine, we can install a newer version of Ruby. We'll use version 2.1.2. If your terminal is still open, close it and relaunch it. When you open a terminal window, some scripts are executed and installing RVM added some. We need them.

Issue the following command (you will also need to enter your password during the install):

rvm install 2.1.2

Now, we'll make 2.1.2 the default Ruby. Just enter this command:

rvm use 2.1.2 --default

Install PostgreSQL

I see that many advocates the use of the Postgres.app. I personally don't like to use it as the config files don't get stored in a standard location and this location tends to change with updates to the Postgres.app. Instead, we'll install PostgreSQL using homebrew. Homebrew is a package manager for OS X similar to apt-get on Linux. You don't have to install it, it was done automatically when we installed RVM previously.

In a terminal window, issue the following command to make sure we are using the latest version of homebrew:

brew update

Then, we can install PostgreSQL with:

brew install postgresql

Start/Stop PostgreSQL easily (optional)

This step is not necessary if you know your way around PostgreSQL but I find it makes starting the PostgreSQL server and stopping it easier. Edit the hidden file .bash_profile located in ~/. Add the following lines at the end:

alias pg_start="pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start"
alias pg_stop="pg_ctl -D /usr/local/var/postgres stop -s -m fast"

Now, if you close and reopen your terminal, you'll be able to start PostgreSQL by issuing pg_start and stop it with pg_stop.

pgAdmin

You can also install pgAdmin, an excellent GUI administration tool for PostgreSQL. Get it here: www.pgadmin.org/download/macosx.php.

To connect to your PostgreSQL server from pgAdmin, make sure the server is running (pg_start if you took the previous optional step). Launch pgAdmin. You will need to fill in the name (I use local), the server name localhost and the username which is your OS X username. Leave the password blank.

Install Rails

Installing Rails is now trivial and you can install it like any other gem by issuing:

gem install rails

Here is a template for your Rails database.yml in order to connect your app to PostgreSQL rather than the default SQLite:

development:
  adapter: postgresql
  encoding: utf8
  database: database_name_dev
  username: your_osx_username
  host: localhost

test:
  adapter: postgresql
  encoding: utf8
  database: database_name_test
  username: your_osx_username
  host: localhost

production:
  adapter: postgresql
  encoding: utf8
  database: database_name
  username: database_username
  password: database_password
  port: <server_port>
  host: <server_address>

Editor

There are many text editors and IDE's for Ruby, Python and JavaScript development out there. I really like the open-source TextMate 2. Get it here: api.textmate.org/downloads/release. Hilton Lipschitz has an excellent tutorial on boosting your productivity with TextMate 2.

Shameless plug

Now, you have a complete development environment for Ruby and Rails. Why not test out RailsBricks to develop Rails apps faster? Install it with gem install railsbricks. You can also speed up your Git workflow with qwikGit. Get it with gem install qwikgit.


RailsBricks updated to 2.1.0

I have been quite busy these past months but I took the time to update RailsBricks to version 2.1.0. Have a look at the changes in the RailsBricks news.

What is RailsBricks already?

RailsBricks is an app generator I created to speed up Ruby on Rails development. RailsBricks is open-source. By the way, this site was built with RailsBricks!

Install RailsBricks

To get RailsBricks, just install it like you would install any other gem with gem install railsbricks.

Happy Ruby on Rails coding!


Week 31 in Tech

Mozilla appoints Chris Beard as CEO

Chris Beard moves from interim CEO to permanent CEO:

the board has reviewed many internal and external candidates—and no one we met was a better fit.

I wonder if those who were very vocal against Brendan Eich also stopped using JavaScript.

Cortana versus Siri

In a new ad from Microsoft, Cortana makes fun of Siri. Seems Microsoft is learning from Samsung in the ads department. When promoting a product, always make sure you compare it to an Apple one.

Raspberry Pi for Windows developers

Here's Microsoft's take on the Raspberry Pi: the $300 Sharks Cove. It is currently available for pre-order.

This "Windows compatible hardware development board" is designed to facilitate development of software and drivers for mobile devices that run Windows, such as phones, tablets, and similar System on a Chip (SoC) platforms.

Still, at $300, I wouldn't pitch it against a $100 Raspberry Pi.

New MacBook Pros

Apple refreshed its MacBook Pros lineup. Faster processors and more RAM.

Some numbers from an iOS indie developer

Jared Sinclair wrote an interesting perspective on iOS indie development regarding his experience with Unread.

I tend to disagree with the conclusion, though:

I conclude from all this that anyone who wants to make a satisfying living as an independent app developer should seriously consider only building apps based on sustainable revenue models.

I don't think the model of paid-upfront apps is a bad one. I think building yet another RSS reader when the App Store is filled with them is a bad model. The name Unread in itself is not a good one as when searching for RSS, Unread doesn't even show in the first 10 results. Remember: build (new) things people want and stay away from yet another note-taking, todo-list, rss-reader app if you really want to make a profit.

Apple CDN goes live

It seems Apple quietly launched their own CDN network as reported by Dan Rayburn.

Right now they control the entire customer experience, except for the way content is delivered to their devices, and they are quickly working to change that.

That's a good thing. Hope it can improve the speed of services such as iTunes Match and App Store search.

Less profit than expected in Q2 for Samsung

Samsung just released its Q2 numbers.

Operating profit for the quarter was 7.19 trillion, a 15-percent drop from a quarter ago.

Quick! Time to make another ad bashing Apple products!


Week 30 in Tech

Navigating the corporate speak

I really loved the analysis of Satya Nadella's email to potentially laid-off employees by Lee Hutchinson writing for Ars Technica. This part nails it:

The last sentence takes the anonymous could-be-from-any-company cake, though: Microsoft will "focus on breakthrough innovation that expresses and enlivens... digital work and digital life experiences." If you parse that, it turns out that what the e-mail says is "we will try to sell more things by making good things that people like."

Xcode beta 4

Xcode beta 4 was released. It adds public, internal and private modifiers to the Swift language and corrects many issues.

Brick: a complete beginner course on app development

This week, we announced Brick. It is a web-based course on app development for Mac and iOS with the Swift programming language. Intended for the complete beginner to programming, it is also suitable for seasoned developers wanting to learn the intricacies of developing for the Apple platforms.

Windows Phone going after the low-end market

According to analytics, the best selling Windows Phone are the low-end ones. Microsoft seems to continue with the strategy and announced the Lumia 530, a cut-down version of the Lumia 630.

Apple files a patent for an iTime smartwatch

According to Wired UK, Apple filed a patent for a smartwatch design named iTime. A possible announcement for September?

Amazon announces a $126 million loss in quarterly earnings

The whole quarterly financial breakdown is here. Well, their newly launched physical shopping cart didn't seem to help.

Continuity explained

Very good piece from Ars Technica: Explaining Continuity. If AirDrop, Handoff, iBeacon, etc... are still a black box to you, this article will shed some light.

Yosemite public beta is out

If you feel like bricking your Mac, the Mac OS X 10.10 public beta is out. Get it here. Or maybe, install it on a separate partition or in a VM ;-)


Swift is a great first language for beginners

With Guillaume and Kyra we formed Team Brick in order to teach programming for Apple OS X and iOS using the new Swift language. It is named Brick and it is intended at the complete beginner. No prior programming experience required.

I see a lot of questions online that are a variation of "Is Swift suited as a first language for a complete beginner?". Opinions differ but I personally think it is a great language to learn how to code. Here is why.

Programming, not hacking

First, there's a distinction that needs to be made: hacking bits and pieces together after completing a few video lessons on popular online training outlets in order to quickly produce a MVP is not programming. Understanding what programming is requires a certain amount of theoretical knowledge and becoming a proficient programmer requires to know how to apply these concepts.

With that out of the way, let's continue to see why Swift is an excellent choice for people wanting to seriously learn how to write programs.

Environment

To write code, you need a development environment. The most basic one is composed of a text editor and an interpreter or a compiler. Setting up a proper development environment can sometimes be a pain, especially when one needs to download and configure multiple packages, make sure they are compatible with each other and keep them individually updated. Seasoned programmers don't break a sweat to manage their environment but this is typically a point where novice struggle. Want to know everything required to set up Ruby on Rails on a Mac? Have a look at one of my previous guide and you'll get a sense of all the steps involved.

If you take Ruby and/or Python, two languages heavily recommended to learn how to code, once you are done setting them up, you will also need a certain level of familiarity with the command-line interface. Again, to many beginners, this is quite cryptic. Notice that at that point, you haven't yet started to learn how to code.

Some languages offer what is known as an Integrated Development Environment or IDE for short. It is a special kind of software whose purpose is to ...write software. IDE usually include an editor, a compiler, a debugger and plenty of nice and useful features for coders such as code completion (meaning that you start typing a word and the IDE can autocomplete it). Swift development is done using an IDE. It is made by Apple, it's free and it's named Xcode.

Setting up a Swift development environment is as easy as visiting the Mac App Store, looking for Xcode and clicking on "Install". Done.

Helping hand

Beginners make mistakes. A lot. Whether it comes from a misplaced comma, a bracket that wasn't closed properly or simply from issuing a wrong instruction in the code. Languages such as JavaScript, Ruby or Python are not good at catching these mistakes as you write your code. That is due to their interpreted nature. Most of the time, you'll only know you've made a mistake when you attempt to run your program only to see it fail miserably with a cryptic error message such as Undefined method '' for nil:NilClass. Not super friendly for a beginner, right?

On the other hand, Swift is capable of highlighting such mistakes as you are typing your code. Again, this is due to the language compiled nature and the use of the Xcode IDE. Not only Swift requires you to be very explicit in your instructions, it can also warn you that you are currently typing something that is not quite correct. If it can't catch a mistake as you type, as it sometimes happens, it will happen at compile time before you execute your program and usually issue a relevant and easy to understand error message. This is, in my opinion, more novice-friendly.

Basic programming concepts

As said earlier, becoming a programmer requires to understand a lot of basic concepts. One such concept is known as data types. In a nutshell, it means that a computer must know which type of data you are feeding it: a number, text, dates, etc.

Interpreted languages such as Ruby and Python are quite popular because they effectively abstract such concepts. In theory, this allows for a boost in productivity by not having to care about these but in practice, it often results in sloppily written code that turns out to be difficult to maintain and troubleshoot. For example, a programmer familiar with the concept of data types and the way a computer uses them will be more productive. On the other hand, because these languages abstract the concept, it is difficult to explain it to a novice and then have the novice truly understand what (s)he is doing.

Swift, to some extent, lets you choose if you want to be explicit about data types (type annotation) or if you want the compiler to take care of that for you (type inference). This is excellent for beginners as they are able to grasp the concepts at first and then are given the possibility to take shortcuts.

Advanced concepts

Swift is a very modern language. It features some quite advanced concepts such as closures, generics, extension methods, type inference, functional programming patterns, and many more. A beginner is unlikely to need these at first but as (s)he continues to learn, they'll come in handy in order to craft great apps for the Apple ecosystem without having the need to switch to another language that would allow for more functionalities.

Object-Oriented

Swift is an object-oriented language. Today, most languages are but they implement the object-oriented programming (OOP) concepts differently. A typically bad candidate to learn programming the object-oriented way is JavaScript. There are many advocating JavaScript as a first language but in my opinion, the basic concepts of object-oriented programming are very hard to explain (and understand) using JavaScript.

On the other hand, Swift adheres perfectly to the OOP key characteristics which are polymorphism, encapsulation and inheritance. It makes teaching and understanding the concept of objects in programming quite simple. You can easily translate Cat is an Animal in Swift.

Financial consideration

Everybody learns how to code for a different reason but at some point, many want to benefit from the countless hours spent learning. Swift allows you to jump in a thriving ecosystem by letting you publish (and sell!) your completed apps on the Mac App Store and on the iOS App Store.

The culture associated with other languages (again, Ruby and Python or even the NodeJS platform) is mostly open-source. It is rather rare to see an app written in Ruby being sold (and would even be frown upon). On the other hand, it is common for iOS developers to sell their creations on the App Store.

Soon but not right now, though

There's one caveat, though. Swift is a great first language to learn how to code, yes. But not right now. That is because the language itself is currently in a beta phase and won't be officially released before September 2014. At this moment, the core of the language is still undergoing heavy changes, sometimes weekly. That would make it quite difficult for a novice to start learning it.

When Apple officially releases Swift, if you are still looking at learning how to code, I'd recommend that you consider Swift as your first programming language. Oh, and maybe that you take a look at Brick as we are betting on Swift to teach you how to become a great coder!


Week 29 in Tech

I'm trying a new thing on this blog: the week in tech. News that caught my eyes between Fridays and that I find relevant from a developer's perspective. The intent is to have a short digest which shouldn't take more than 5 minutes to read. If the audience justifies it, I'll make a separate outlet for it. Of course, feedback is welcome!

Microsoft eliminating up to 14% of its workforce

This made the news this week:

Microsoft Corp. said it will eliminate as many as 18,000 jobs, the largest round of cuts in its history, as Chief Executive Officer Satya Nadella integrates Nokia Oyj’s handset unit and slims down the software maker.

Among the first business units to get axed, Xbox Entertainement Studios. That means that there won't be any original shows for Xbox as initially announced by the company.

The full story here.

A new Apple and IBM partnership to focus on the enterprise

Times have changed since the 1984 ad: Apple and IBM announced a new partnership to help bring iOS devices in the enterprise.

The combination will create apps that can transform specific aspects of how businesses and employees work using iPhone and iPad, allowing companies to achieve new levels of efficiency, effectiveness and customer satisfaction—faster and easier than ever before.

The first thing that came to my mind was iAS 400.

Guess what! Tizen-powered phone delayed!

Originally announced for a September 2013 release, the Samsung Z which should be the first Tizen-powered phone has again been delayed by Samsung. No release date announced, though.

Microsoft boasts huge scope for growth to partners

Excerpt from Microsoft keynote at the Worldwide Partner Conference, on Ars Technica:

More broadly, Turner said that Microsoft has just a 14 percent share of all devices when one counts smartphones and tablets alongside PCs, and that this represents a huge opportunity for the company and its partners.

Does that mean that companies with 0% market share have even a larger growth opportunity? Interesting way to present numbers!

Apple publishes a blog on Swift

As stated in the first entry, the only one at this time (emphasis mine):

We have big plans for the Swift language, including improvements to syntax, and powerful new features. And as Swift evolves, we will provide tools in Xcode to help you migrate your source code forward.

This is yet another hint at retiring Objective-C as the first citizen language for any Apple-related development in the future.

Xcode 6 beta 3 available to anyone

Anybody can get Xcode 6 beta 3. No need for a paid developer subscription.

Yet another Apple-bashing ad from Samsung

Not even a month after the wall huggers anti-iPhone ad, Samsung now takes a stab at the iPad with yet another Apple-bashing ad. What if, for a change, Samsung would boast about its unique features without always feeling the need for a comparison with the competition? Stay classy.


Batch convert CRLF to LF

Ever worked with people using Windows machines while you are on Mac or Linux? Have you ever had issues with line endings formatting? Or even worse, reached the infamous Git error:

fatal: CRLF would be replaced by LF in ......

A quick script

So I wrote an absolutely not awesome script that converts DOS CRLF line endings with Unix LF line endings. just save this in a file named crlf2lf:

#! /bin/sh
for x
do
    echo "Converting $x ..."
    tr -d '\015' < "$x" > "convert.$x"
    mv "convert.$x" "$x"
    echo "$x done."
done

Simple! Don't forget to chmod u+x crlf2lf and if you want to use it on all the files within a directory, just do this:

crlf2lf *

...and that's it!

Extend it

I published the script on Github. Not because it's beautiful or complicated but because it would be fun if people would extend it to do more, like make it recursive and so on.

image


Discovering Markdown

I'm late to the party. Very late. 10 years late. Because the latest official release of Markdown dates back to 2004. Recently, I've been spending my nights writing technical documents, with a lot of embedded code and just made the switch from writing them directly in HTML to writing them in Markdown. Here's a brief tutorial on Markdown, how it can help you write faster and my current setup.

Markup

The basic idea behind a markup language is to arrange logically bits and pieces of data, usually text, by annotating them. There are many markup languages such as HTML, LaTex and XML. Markdown is itself a markup language.

Easy to read, easy to write

Markdown was created by Apple-centric blogger John Gruber with contributions from the late Aaron Swartz. The idea behind it is to let writers easily compose texts that would be converted to valid HTML. A text written in Markdown is easy to read and easy to write. Contrary to HTML, elements don't need to be wrapped in opening and closing tags.

Have a look

Let's just compare 3 times the same text. Once in plain text, once in HTML and once in Markdown.

plain text

This is the title
This is a subtitle
The following word should be rendered in italic and this one in bold.
Look at an unordered list:
Item 1
Item 2
Item 3
This is a piece of code that displays <Hello World> in the console:
public static Main(){
Console.WriteLine("<Hello World>");
}
And this is a link to my site.

HTML

<h1>This is the title</h1>

<h2>This is a subtitle</h2>

<p>The following word should be rendered in <em>italic</em> and this one in <strong>bold</strong>.</p>

<p>Look at an unordered list:</p>

<ul>
    <li>Item 1</li>
    <li>Item 2</li>
    <li>Item 3</li>
</ul>


<p>This is a piece of code that displays <code>&lt;Hello World&gt;</code> in the console:</p>

<pre><code>public static Main(){
    Console.WriteLine("&lt;Hello World&gt;");
}
</code></pre>

<p>And this is a <a href="http://www.nicoschuele.com">link</a> to my site.</p>

Note the amount of tags needed to render this properly in HTML. Also note that the < character, for example, needs to be converted to &lt; in order to be displayed correctly when wrapped inside <code> tags. If you need to write code samples on a blog, that's a drag.

Markdown

# This is the title

## This is a subtitle

The following word should be rendered in *italic* and this one in **bold**.

Look at an unordered list:

* Item 1
* Item 2
* Item 3

This is a piece of code that displays `<Hello World>` in the console:

    public static Main(){
        Console.WriteLine("<Hello World>");
    }

And this is a [link][1] to my site.

[1]: http://www.nicoschuele.com

Much cleaner, easier to read, faster to write. And you know what? The HTML example above was generated from this same Mardown sample!

The result

And this is the produced output from the Markdown code above:

Output

Different flavors

The vanilla version of Markdown sparked some augmented versions. The most well-known are the Github Flavored Markdown (also known as GFM) and Multimarkdown. They each have their own additions to the basic Markdown syntax, for example, Multimarkdown has the capability to add footnotes.

Even if you are new to Markdown, chances are that you already encountered it. It is used to edit posts on StackOverflow, Reddit and GitHub, to name a few.

What you need

First, you'll need to learn the syntax. It should take you about 30 mins for it. Yup, it's that simple. Have a look at the reference.

Then, all you need is a plain text editor and start writing! Personally, I use a nice free app on OS X called MOU with a dark theme. It as a right pane showing you a live preview of your formatted text. With it you can also copy as HTML and your Markdown text will be stored in HTML format in your clipboard. MOU also allows you to generate formatted PDF directly. I might switch to LightPaper, though, but hadn't yet had the chance to write something significant with it. This is what MOU looks like:

Mou App

Sometimes, when on Windows, for example, I use a free online editor called StackEdit. It has the same features as MOU and can save files to your Dropbox.

Switching

Since I switched to Markdown from HTML to write, I really get my writings done much faster. So yeah, I'm late to the game but I enjoy it nonetheless. I've even modified the editor feature on my blog to use Markdown rather than HTML.


Displaying posts 1 - 8 of 76 in total




Brick
A comprehensive course on programming, focusing on Mac OS X and iOS devices using the Swift programming language.
RailsBricks
An app generator I created to speed up Ruby on Rails development. RailsBricks is open-source. By the way, this site was built with RailsBricks!
HowToCode.io
I founded HowToCode.io to teach high quality web development, for free. The aim is to take students from novice to employable.
Trakx
I love lists. I create many and for everything, really. Trakx is built with RailsBricks and is my own list management tool. It is free and anybody can sign up.
qwikGit
Speeding up Git common actions by wrapping them in single switches. For example, to add, commit, merge and then push to a remote repository, just type qgit -cmp instead of a long serie of Git commands.