Skip to content

Instantly share code, notes, and snippets.

@nwjsmith
nwjsmith / gist:78305
Created Mar 12, 2009
Some macros for making system calls less verbose
View gist:78305
#define TRY_ASSIGN(v, x) do { \
v = x; \
if (v == -1) { \
fprintf(stderr, # x ": %s\n", strerror(errno)); \
exit(EXIT_FAILURE); \
} \
} while (0)
#define TRY(x) do { int unused; TRY_ASSIGN(unused, x); } while (0)
View gist:210240
alias ssh_gaul="export TERM=xterm && ssh USER_NAME@obelix.gaul.csd.uwo.ca"
View untitled.txt
Fib(0 * 10): 0
Fib(1 * 10): 55
Fib(2 * 10): 6765
Fib(3 * 10): 832040
Fib(4 * 10): 102334155
Fib(5 * 10): 12586269025
Fib(6 * 10): 1548008755920
Fib(7 * 10): 190392490709135
Fib(8 * 10): 23416728348467685
Fib(9 * 10): 2880067194370816120
View untitled.c
byte * fib(byte *prev, byte *curr, int n)
{
byte *next;
// Fib(0) = 0
if (n == 0) { return prev; }
next = sum(prev, curr);
if (n > 2) {
return fib(curr, next, n - 1);
} else {
return next;
We couldn’t find that file to show.
View gist:318526
Run the following commands
==========================
wget "http://kernel.org/pub/software/scm/git/git-1.7.0.1.tar.bz2"
tar xvf git-1.7.0.1.tar.bz2
mkdir $HOME/local/
cd git-1.7.0.1
./configure --prefix=$HOME/local/
make
make install
We couldn’t find that file to show.
View gist:389415
# Credit to Brandon Keepers
# http://opensoul.org/2007/2/9/automatically-backing-up-your-remote-database-on-deploy
require 'yaml'
desc "Backup the remote production database"
task :backup, :roles => :db, :only => { :primary => true } do
filename = "#{application}.dump.#{Time.now.to_i}.sql.bz2"
file = "/tmp/#{filename}"
env = ENV['RAILS_ENV'] || 'development'
on_rollback { delete file }
View .vimrc
" Use Vim settings, rather than Vi settings
set nocompatible
" Use The Pope's awesome pathogen.vim to load plugins
call pathogen#runtime_append_all_bundles()
" Automatically detect filetypes
filetype on
" Use syntax highlighting
View t
ruby-1.9.2-rc1 > f = Father.new
=> #<Father id: nil, name: nil, created_at: nil, updated_at: nil>
ruby-1.9.2-rc1 > f.name = "Dave"
=> "Dave"
ruby-1.9.2-rc1 > s = Son.new :name => "Nate"
=> #<Son id: nil, name: "Nate", father_id: nil, created_at: nil, updated_at: nil>
ruby-1.9.2-rc1 > f.son
f.son_ids f.sons f.sons= f.son_ids=
ruby-1.9.2-rc1 > f.sons << s
=> [#<Son id: nil, name: "Nate", father_id: nil, created_at: nil, updated_at: nil>]