Skip to content

Instantly share code, notes, and snippets.

View andys's full-sized avatar

Andrew Snow andys

View GitHub Profile
[mysqld]
innodb_flush_method=nosync
default-storage-engine = innodb
innodb_flush_log_at_trx_commit = 0
innodb_doublewrite = 0
@andys
andys / backupdaily.sh
Created May 20, 2014 04:21
ZFS snapshot backup
#!/usr/bin/bash
for fs in dir1 dir2 dir3 ; do
srcfs="tank/$fs"
dstfs="backup/$fs"
oldsnap=`zfs list -H -r -t snapshot $dstfs |cut -f1 | grep '0000$' | sort | tail -1 | sed -e 's/.*@//'`
newsnap=`zfs list -H -r -t snapshot $srcfs |cut -f1 | grep '0000$' | sort | tail -1 | sed -e 's/.*@//'`
if [ x$newsnap != x ] ; then
if [ x$oldsnap != x ] ; then
echo "$fs: from fat/san/$fs@$oldsnap to $newsnap if needed..."
@andys
andys / keybase.md
Created November 18, 2014 03:34
keybase.md

Keybase proof

I hereby claim:

  • I am andys on github.
  • I am andy_snow (https://keybase.io/andy_snow) on keybase.
  • I have a public key whose fingerprint is A57D BDF8 5F6F AD3E A4E7 C310 D56D D97F 4C98 0A03

To claim this, I am signing this object:

@andys
andys / ubuntu puppet server passenger install.txt
Created November 18, 2010 07:15
Steps for installing puppet master in Ubuntu 10.04 with ruby 1.8 and passenger
Puppet Install steps for Ubuntu 10.04, ruby 1.8, and passenger
apt-get -y update
apt-get -y dist-upgrade
reboot
############################################
apt-get -y install build-essential
apt-get -y install bsubversion apache2 libcurl4-openssl-dev libssl-dev mysql-server
@andys
andys / gist:758283
Created December 29, 2010 06:55
javascript scroll to an element if it isn't visible
function scroll_to_if_not_visible(finder) {
var postop = $(finder).offset().top, win = $(window);
var posbottom = postop + $(finder).height();
if (posbottom > (win.height() + win.scrollTop())) {
$(finder).get(0).scrollIntoView(false);
}
else if (postop < win.scrollTop()) {
$(finder).get(0).scrollIntoView(true);
}
vars = Variables()
vars.Add(BoolVariable('DEBUG', 'Set to disable optimizations', 1))
vars.Add(BoolVariable('PIC', 'Set to 1 for to always generate PIC code', 0))
env = Environment(variables = vars)
debug = env['DEBUG']
@andys
andys / gist:1057780
Created July 1, 2011 02:50
Disabling Garbage Collection around every rails request
class ApplicationController < ActionController::Base
around_filter :disable_garbage_collection
def disable_garbage_collection
unless @use_garbage_collection
GC.disable
begin
yield
ensure
@andys
andys / gist:1686172
Created January 27, 2012 00:42
Yo I heard you liked parents in your parents
# rails generate model region name:string parent_id:integer
class Region < ActiveRecord::Base
belongs_to :parent, :class_name => self.to_s
def parent_name
parent.name
end
class Parent
def add(x,y)
x + y
end
end
class Child < Parent
def add
super
end
end
@andys
andys / gist:5217920
Last active December 15, 2015 06:39
example of filtering scope in controller
class PlayersController < ActiveController::Base
before_filter :player_scope, except: :create
def index
respond_with(@players = @scope.all)
end
def show
respond_with(@player = @scope.find(params[:id])
end