The Setup

    30 Sep 2012

    I needed a script to quickly setup a development environment on my MacBook Pro.

    I read about a GitHub tool called “The Setup”, but unfortunately it is not yet open source. Because of that, after some research, I found a Thoughtbout project, laptop, which has the same purpose, so I decided to fork it and create my own Setup.

    It automates a lot of boring tasks installing:

    • GitHub SSH-keys
    • Ruby through RVM
    • rails gem
    • heroku gem
    • mysql2 gem
    • pg gem
    • mongodb gem
    • foreman gem
    • capistrano gem
    • Homebrew
    • MySQL
    • Postgres
    • MongoDB
    • ack
    • tmux
    • ImageMagick
    • QT
    • Heroku plugins

    In the future I would add the setup of Sublime Text 2 and .dotfiles.

    You can find it on my GitHub: The Setup

    Truths about programming

    28 Sep 2012

    Great post with many interesting facts:

    Averaging over the lifetime of the project, a programmer spends about 10-20% of his time writing code, and most programmers write about 10-12 lines of code per day that goes into the final product, regardless of their skill level. Good programmers spend much of the other 90% thinking, researching, and experimenting to find the best design. Bad programmers spend much of that 90% debugging code by randomly making changes and seeing if they work. […]

    ####

    […] Good programmers are not afraid to refactor (rewrite) their code to reach the ideal design. Bad programmers write code which lacks conceptual integrity, non-redundancy, hierarchy, and patterns, and so is very difficult to refactor. It’s easier to throw away bad code and start over than to change it.

    ####

    Programming is hard work. It’s an intense mental activity. Good programmers think about their work 24/7. They write their most important code in the shower and in their dreams. Because the most important work is done away from a keyboard, software projects cannot be accelerated by spending more time in the office or adding more people to a project.

    Ruby CloudApp Roulette

    25 Sep 2012

    Every time I start to learn a new language, I have fun writing a Cloud App Roulette.
    It is a little script that generates Cloud App-like URLs checking if they are valid, to obtain a list of public images and files uploaded by anyone.

    I coded my own Cloud App Roulette in Java first, then PHP, Javascript, C and Objective-C. Now I wrote it in Ruby as well, just to keep up :)

    With these few lines I learned a lot of useful things:

    • different variables’ scope, globals and privates
    • map function
    • read a status of a page
    • multithreading, semaphores and synchronized blocks

    ####

    Databases' passwords

    20 Sep 2012

    I push the source code of this blog both on GitHub and to my EC2 instance, where it runs.

    The file config/database.yml stores sensible informations like database’s passwords, and I didn’t want to push it on GitHub.
    After a quick search on stackoverflow I didn’t find any answer to my problem, but then I solved it.
    I don’t know if it is the best way, but this is what I did.

    Since I don’t have to modify the file database.yml, I copied it to my EC2 instance and then I added it to .gitignore.
    Then, I added a capistrano’s task in deploy.rb, to link database.yml to the current directory of deployment:

    # copy db config
    after "deploy:update_code", :copy_db_config
    desc "copy db config file"
    task :copy_db_config do
      run "ln -s ~/path/where/I/copied/database.yml #{release_path}/config/database.yml"
    end
    

    Hope this help.

    Sublime Text 2

    19 Sep 2012

    After MacroMates announced that TextMate 2 was available on GitHub, I (wrongly) concluded that it was probably going to be abandoned.

    Because of that, I began to consider other text editors, and my attention was caught by Sublime Text 2.
    Now it’s my main text editor, and here there are few tweaks that let you to improve it.

    Enable Sublime in command line

    If you want to use Sublime in your terminal, you can add a symbolic link to its executable:

    sudo ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/bin/subl
    

    Type subl --help to check if it works.

    Custom icon

    Honestly, the Sublime icon sucks.
    I replaced it with a new one and then I created a script to automate the change.

    • Download the icon with the script here
    • Run unzip sbicon
    • Execute the script ./mac_replace_icons

    Install Package Manager

    Like TextMate, also Sublime has its packages. You can install the Package Manager pressing ^+` to open Sublime’s console and copying this string

    import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())); open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()); print 'Please restart Sublime Text to finish installation'
    

    After relaunch it, you can add new packages pressing ++P and selecting Package Control: Install Package.

    There are a lot of packages for almost everything you need, and a lot of TextMate packages are now available for Sublime.

    Install custom theme and color schemes

    Sublime it’s not exactly beautiful. It’s pretty ugly. Because of that I installed the Soda theme to make this more Mac-like.

    You can install it through package manager and to enable it you have to add the line below to your user’s settings +,

    {
        "theme": "Soda Light.sublime-theme"   }
    

    There are two different variant of this theme, Light and Dark, both beautiful.

    You can use the default Sublime’s chrome-like tabs, but I prefer Soda’s more squared custom tabs

    "soda_classic_tabs": false
    

    With Soda I installed also a custom colour schemes, you can download them here.
    Unzip and place the extracted .tmtheme files in the Sublime’s Packages/User folder. You can find it under Preferences/Browse Packages.

    To activate one of them, add the line

    "color_scheme": "Packages/User/Monokai Soda.tmTheme"
    

    in your user’s settings.

    image

    Beautiful, I know :P

    Custom syntax-based prefs

    This is the last tip. If you want to have preferences based on programming language you are using (like 2 spaces tabs in Ruby), open the file and set your preferences in Preferences/Settings - More/Syntax Specific

    EDIT

    The twitter user @iduke84 shared with me its script to open selected files with Sublime Text 2.

    Give it a try!