Skip to content

Instantly share code, notes, and snippets.

View ashleyconnor's full-sized avatar
🏠
Working from home

Ashley Connor ashleyconnor

🏠
Working from home
View GitHub Profile
@ashleyconnor
ashleyconnor / gist:2695320
Created May 14, 2012 17:50
Bitcoin compiler errors OSX 10.7
[src (master)]$ make -f makefile.osx USE_IPV6=1
../share/genbuild.sh obj/build.h
llvm-g++ -c -g -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter -DMAC_OSX -DMSG_NOSIGNAL=0 -DUSE_IPV6 -DUSE_UPNP=1 -DHAVE_BUILD_INFO -I"/Users/ashleyconnor/Development/bitcoin/bitcoin/src" -I"/Users/ashleyconnor/Development/bitcoin/bitcoin/src"/obj -I"/usr/local/Cellar/berkeley-db4/4.8.30/include" -I"/usr/local/include/" -MMD -o obj/version.o version.cpp
llvm-g++ -c -g -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter -DMAC_OSX -DMSG_NOSIGNAL=0 -DUSE_IPV6 -DUSE_UPNP=1 -DHAVE_BUILD_INFO -I"/Users/ashleyconnor/Development/bitcoin/bitcoin/src" -I"/Users/ashleyconnor/Development/bitcoin/bitcoin/src"/obj -I"/usr/local/Cellar/berkeley-db4/4.8.30/include" -I"/usr/local/include/" -MMD -o obj/checkpoints.o checkpoints.cpp
In file included from main.h:10,
from checkpoints.cpp:10:
net.h: In member function ‘void CNode::EndMessage()’:
net.h:354: warning: invalid access to non-static data member ‘
@ashleyconnor
ashleyconnor / gist:2701731
Created May 15, 2012 13:24
flask-babel error using Khmer locale
>>> from flaskext.babel import refresh; refresh()
>>> khmer = format_datetime(datetime(1987, 10, 10, 18, 00), 'full')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/ashleyconnor/.virtualenvs/flask/lib/python2.7/site-packages/flaskext/babel.py", line 317, in format_datetime
return _date_format(dates.format_datetime, datetime, format, rebase)
File "/Users/ashleyconnor/.virtualenvs/flask/lib/python2.7/site-packages/flaskext/babel.py", line 382, in _date_format
return formatter(obj, format, locale=locale, **extra)
File "/Users/ashleyconnor/.virtualenvs/flask/lib/python2.7/site-packages/babel/dates.py", line 505, in format_datetime
locale=locale)) \
@ashleyconnor
ashleyconnor / ruby.rb
Created July 23, 2012 11:13
Ruby Test Cart
require 'bigdecimal'
class Item
attr_accessor :code, :name, :price
def initialize(code, name, price)
@code = code
@name = name
@price = BigDecimal.new("#{price}")
@ashleyconnor
ashleyconnor / guide.sh
Created December 8, 2012 17:47 — forked from teamon/guide.sh
Pow + nginx configuration aka give me back my 80 port!
# Install pow
$ curl get.pow.cx | sh
# Install powder
$ gem install powder
# See that firewall is fucked
$ sudo ipfw show
00100 0 0 fwd 127.0.0.1,20559 tcp from any to me dst-port 80 in <- THIS ONE!!!
65535 81005 28684067 allow ip from any to any
# encoding: UTF-8
Capistrano::Configuration.instance(:must_exist).load do
namespace :rails do
desc "Open the rails console on one of the remote servers"
task :console, :roles => :app do
hostname = find_servers_for_task(current_task).first
exec "ssh -l #{user} #{hostname} -t 'source ~/.profile && #{current_path}/script/rails c #{rails_env}'"
end
end

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:

# Use: it { should accept_nested_attributes_for(:association_name).and_accept({valid_values => true}).but_reject({ :reject_if_nil => nil })}
RSpec::Matchers.define :accept_nested_attributes_for do |association|
match do |model|
@model = model
@nested_att_present = model.respond_to?("#{association}_attributes=".to_sym)
if @nested_att_present && @reject
model.send("#{association}_attributes=".to_sym,[@reject])
@reject_success = model.send("#{association}").empty?
end
model.send("#{association}").clear
@ashleyconnor
ashleyconnor / go_getter.go
Created May 21, 2014 21:25
Go Getter - Go program that fetches a webpage and outputs to STDOUT
package main
import (
"fmt"
"net/http"
"io/ioutil"
"os"
)
func main() {
@ashleyconnor
ashleyconnor / unicorn
Last active August 29, 2015 14:06 — forked from shapeshed/unicorn
#!/bin/sh
set -e
# Example init script, this can be used with nginx, too,
# since nginx and unicorn accept the same signals
# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/path/to/your/app/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
ENVIRONMENT=production
@ashleyconnor
ashleyconnor / gist:8cfecc5eeea300f69bcc
Created September 18, 2014 15:36
Context Validations
class Article
with_options on: :view do |on_view|
on_view.validate :has_been_published
on_view.validate :is_not_spam
end
def viewable?
valid? :view
end