Skip to content

Instantly share code, notes, and snippets.

View wearethefoos's full-sized avatar

Wouter de Vos wearethefoos

View GitHub Profile
@wearethefoos
wearethefoos / CakePHP: Access SessionComponent from everywhere
Created February 11, 2011 17:43
A question a lot of people seem to ask about the CakePHP Session Component is how to access it from e.g. a Model. There are quite a few suggestions to be found on Google, but none of them strike me as very elegant. I came up with this one, and it works fr
App::import('Core', 'Controller');
App::import('Component', 'Session');
$Controller = new Controller();
$Session = new SessionComponent();
$Session->startup($Controller);
$Session->read('Auth.User');
@wearethefoos
wearethefoos / OSX Lion pecl and pear.mdown
Created September 8, 2011 10:27
Native OSX Lion pecl and pear config
$ sudo /usr/bin/php /usr/lib/php/install-pear-nozlib.phar

$ cat >> ~/.bashrc <<'EOF' 

alias pear="php /usr/lib/php/pear/pearcmd.php" 
alias pecl="php /usr/lib/php/pear/peclcmd.php" 
EOF

$ . ~/.bashrc
@wearethefoos
wearethefoos / varnish3.rb
Created February 23, 2012 10:48 — forked from hmsk/varnish3.rb
Install Varnish-3.0.2 on OSX with homebrew
require 'formula'
class Varnish3 <Formula
url 'http://repo.varnish-cache.org/source/varnish-3.0.2.tar.gz'
homepage 'http://www.varnish-cache.org/'
md5 'c8eae0aabbe66b6daabdf3a1f58cd47a'
depends_on 'pkg-config' => :build
depends_on 'pcre' => :build
@wearethefoos
wearethefoos / 0-Readme.md
Created November 23, 2012 14:39
Fixed Rbenv Ruby 1.9.3 falcon patch with CFLAGS for Rackspace Cloud servers

Rbenv Ruby 1.9.3 p194 - Falcon patched on Rackspace Ubuntu 12.04 LTS (Precise Pangolin)

Install these packages:

  $ apt-get install build-essential zlib1g zlib1g-dev \
     libreadline6 libreadline6-dev libssl-dev libyaml-dev \
     libffi-dev libgdbm-dev libx11-dev aptitude libtidy-dev \
     libxml2-dev libevent-dev libev-dev autoconf
@wearethefoos
wearethefoos / commands.sh
Last active December 17, 2015 07:09
Install Ruby 2.0, Nginx, Postgres, Passenger, NodeJS, ElasticSearch on Ubuntu 12.10
# Install Ruby 2.0
apt-get -y update
apt-get -y -m install build-essential zlib1g-dev libssl-dev libreadline-gplv2-dev libyaml-dev libxslt1-dev libxml2-dev libcurl4-openssl-dev libffi-dev libgdbm-dev libncurses5-dev
cd /tmp
wget http://ftp.ruby-lang.org/pub/ruby/ruby-2.1.0.tar.gz
tar xzvf ruby-2.1.0.tar.gz
cd ruby-2.1.0/
./configure --prefix=/usr/local
make

Percona and Rails

From the Percona site:

Percona XtraDB Cluster is a high availability and high scalability solution for MySQL users. Percona XtraDB Cluster integrates Percona Server with the Galera library of high availability solutions in a single product package. Percona XtraDB Cluster enables users to save money through:

  • Less downtime and higher availability
  • Reduced investment in high availability architectures
  • Lower DBA training and education costs
  • No investment in third-party, high availability solutions
@wearethefoos
wearethefoos / rendering.rb
Created June 18, 2013 12:07
Render templates without double render errors
# render in before_filter
before_filter
render 'template' and return
end
# Render conditional
def index
respond_to do |format|
# Prefix to C-a
set -g prefix C-a
unbind C-b
bind C-a send-prefix
# Vim bindings
set -g status-keys vi
# Use vim keybindings in copy mode
setw -g mode-keys vi
@wearethefoos
wearethefoos / check_resque_current.sh
Last active December 27, 2015 18:39
Check with bash whether your Resque workers run from the current release folder.
releases=`ps aux | grep resque- | sudo pwdx \`awk '{print $2}'\` | sed 's/\(.*\)\/path\/to\/releases\/\(.*\)/\2/' | sed 's/.*No such process//'`
current_release=`readlink /path/to/current | sed 's/\/path\/to\/releases\/\(.*\)/\1/'`
for r in $releases; do
if [ $r = $current_release ]; then
echo 'yes'
else
echo 'no'
fi
def assets_same_since?(old_assets_version = nil)
return false if old_assets_version.nil? || old_assets_version.empty?
return false if ENV['FORCE_ASSETS_COMPILATION']
changed = %x(git diff #{old_assets_version}.. \
vendor/assets/ \
app/assets/ \
config/javascript_translations.yml \
config/javascript.yml | wc -l).chomp