Skip to content

Instantly share code, notes, and snippets.

View czarneckid's full-sized avatar

David Czarnecki czarneckid

View GitHub Profile
@czarneckid
czarneckid / gist:1166184
Created August 23, 2011 19:12
Enable warnings in irb as well using -W
dczarnecki-agora:~ dczarnecki$ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.6.0]
dczarnecki-agora:~ dczarnecki$ irb -W
ruby-1.9.2-p180 :001 > def hello
ruby-1.9.2-p180 :002?> p 'world'
ruby-1.9.2-p180 :003?> end
=> nil
ruby-1.9.2-p180 :004 > hello
"world"
=> "world"
@czarneckid
czarneckid / Akismet.rb
Created September 2, 2011 17:54
The first Ruby I wrote. Yikes!
# Akismet
#
# Author:: David Czarnecki
# Copyright:: Copyright (c) 2005 - David Czarnecki
# License:: BSD
class Akismet
require 'net/HTTP'
require 'uri'
@czarneckid
czarneckid / gist:1287184
Created October 14, 2011 13:58
Colorizing my BASH prompt
parse_git_branch() {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\ →\ \1/'
}
export PS1='\[\e[1;37m\][\[\e[1;35m\]\u\[\e[1;37m\]@\[\e[1;32m\]\h\[\e[1;37m\]:\[\e[1;36m\]\w\[\e[1;33m\]$(parse_git_branch)\[\e[1;37m\]]$ \[\e[0m\]'
@czarneckid
czarneckid / gist:1536207
Created December 29, 2011 21:08
Installing older or specific versions of Homebrew formulas

We first want to take a look at what versions are installed for a given formula, brew info FORMULA. Let's take a look at the versions of Redis that are installed.

@czq. ➜  Formula rvm:() git:(master) brew info redis
redis 2.4.5
http://redis.io/
/usr/local/Cellar/redis/2.4.4 (9 files, 460K)
/usr/local/Cellar/redis/2.4.5 (9 files, 460K) *
...
@czarneckid
czarneckid / service
Created January 18, 2013 19:28 — forked from brentkirby/service
#!/bin/bash -e
#
# Since unicorn creates a new pid on restart/reload, it needs a little extra love to
# manage with runit. Instead of managing unicorn directly, we simply trap signal calls
# to the service and redirect them to unicorn directly.
#
# To make this work properly with RVM, you should create a wrapper for the app's gemset unicorn.
#
function is_unicorn_alive {

Zero downtime deploys with unicorn + nginx + runit + rvm + chef

Below are the actual files we use in one of our latest production applications at Agora Games to achieve zero downtime deploys with unicorn. You've probably already read the GitHub blog post on Unicorn and would like to try zero downtime deploys for your application. I hope these files and notes help. I am happy to update these files or these notes if there are comments/questions. YMMV (of course).

Other application notes:

  • Our application uses MongoDB, so we don't have database migrations to worry about as with MySQL or postgresql. That does not mean that we won't have to worry about issues with the database with indexes being built in MongoDB or what have you.
  • We use capistrano for deployment.

Salient points for each file:

@czarneckid
czarneckid / Rails 4 Upgrade Notes.md
Created August 28, 2013 05:05
Rails 4 Upgrade Notes

Rails 4 Upgrade Notes

I recently completed our upgrade to Rails 4. Below are various notes and links that may help you if you are upgrading your application to Rails 4. YMMV.

Overview

There is a good Rails Guide on upgrading, with a specific section on upgrading from Rails 3.2 to Rails 4.0. First, a bit about our specific application and the technologies used, pre-Rails 4 upgrade:

  • Rails 3.2.14
  • Ruby 2.0.0-p247
@czarneckid
czarneckid / gist:6524608
Created September 11, 2013 14:41
Ruby Attr Antipattern timing
class Demo
def initialize(something)
@something = something
end
def based_on_something
@something * 2
end
end
@czarneckid
czarneckid / init.sls
Created October 10, 2013 00:25
SaltStack application runit configuration
# Setup the application's runit directory
/etc/sv/application:
file.directory:
- mode: 0755
- user: someuser
- group: someuser
- recurse:
- user
- group
- mode
@czarneckid
czarneckid / sample_controller.rb
Created December 5, 2013 21:59
UITextView and horizontal scrolling?
class SampleController < UIViewController
def viewDidLoad
super
self.view.backgroundColor = UIColor.whiteColor
@text_view = UITextView.alloc.initWithFrame(UIScreen.mainScreen.applicationFrame)
@text_view.text = sample_text
@text_view.editable = false
@text_view.showsHorizontalScrollIndicator = true