Skip to content

Instantly share code, notes, and snippets.

@mathie
mathie / config.pp
Created July 1, 2013 14:48
Since Puppet stopped passing environment variables down to subprocesses (like, say, `apt-get install`), I've occasionally run into problems where a package postinst script relies on something in the environment. The PostgreSQL package (on Ubuntu 12.04 at least) is one such beast. It relies on the current locale (gleamed from the environment) to …
class postgresql::server::config {
exec {
'postgresql-drop-cluster':
command => '/usr/bin/pg_dropcluster --stop 9.1 main',
onlyif => "/usr/bin/psql -c '\\l+' |awk '/template0/ { print \$5 }' |grep 'SQL_ASCII'",
user => postgres,
notify => Exec['postgresql-create-cluster'];
'postgresql-create-cluster':
command => '/usr/bin/pg_createcluster --locale=en_GB.UTF-8 9.1 main',
@alex-zige
alex-zige / gist:5795358
Last active June 8, 2023 07:49
Rails Rspec API Testing Notes

Rails Rspec APIs Testing Notes

Folders Structure

  spec
  |--- apis #do not put into controllers folder. 
        |--- your_api_test_spec.rb  
  |--- controllers
  |--- models
  |--- factories
 |--- views
@willurd
willurd / web-servers.md
Last active April 20, 2025 00:42
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@anthonysterling
anthonysterling / destroy-vagrant.sh
Created May 22, 2013 09:48
Finds all running Vagrant instances, recursively, from with in the current folder. It then shuts them down, deletes the VM, and removes the .vagrant file.
#!/usr/bin/env bash
for config in `find . -type f -name .vagrant`
do
uuid=`cat "$config" | php -r 'echo json_decode(fgets(STDIN))->active->default;'`
if VBoxManage showvminfo $uuid > /dev/null 2>&1; then
if VBoxManage showvminfo $uuid --machinereadable | egrep -q 'VMState="running|paused|stuck"'; then
VBoxManage controlvm $uuid poweroff
fi
VBoxManage unregistervm $uuid --delete
rm -f "$config"
@bf4
bf4 / README.md
Last active December 15, 2015 18:19
RubyTapas non-video files Downloader
@kenn
kenn / gist:5105175
Last active December 11, 2024 19:08
Unicorn memory usage improvement with Ruby 2.0.0

Unicorn memory usage improvement with Ruby 2.0.0

Here's a preliminary experiment to see how much memory is saved with the new copy-on-write friendly (bitmap marking) GC.

Calculated by memstats.rb https://gist.github.com/kenn/5105061 on Debian x86_64.

Master process:

# ./memstats.rb 20547
@fernandoaleman
fernandoaleman / gist:5083680
Last active October 17, 2023 12:02
How to update VirtualBox Guest Additions with vagrant
# Start the old vagrant
$ vagrant init centos-6.3
$ vagrant up
# You should see a message like:
# [default] The guest additions on this VM do not match the install version of
# VirtualBox! This may cause things such as forwarded ports, shared
# folders, and more to not work properly. If any of those things fail on
# this machine, please update the guest additions and repackage the
# box.

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:

@pootsbook
pootsbook / habtm_not_null.php
Created December 2, 2012 20:21
Ignore records with no attached records
$options['joins'] = array(
array('table' => 'images_news_articles',
'alias' => 'ImagesNewsArticle',
'type' => 'left outer',
'conditions' => array(
'NewsArticle.id = ImagesNewsArticle.news_article_id'
)
),
array('table' => 'images',
'alias' => 'Image',
@ryanb
ryanb / issues_with_modules.md
Created November 29, 2012 22:38
Points on how modules can make code difficult to read.

My issues with Modules

In researching topics for RailsCasts I often read code in Rails and other gems. This is a great exercise to do. Not only will you pick up some coding tips, but it can help you better understand what makes code readable.

A common practice to organize code in gems is to divide it into modules. When this is done extensively I find it becomes very difficult to read. Before I explain further, a quick detour on instance_eval.

You can find instance_eval used in many DSLs: from routes to state machines. Here's an example from Thinking Sphinx.

class Article < ActiveRecord::Base