Skip to content

Instantly share code, notes, and snippets.

@latortuga
latortuga / rails.rb
Created October 18, 2009 17:32
A bunch of handy ruby and rails snippets
# This is used in Rails migrations to update ActiveRecord after adding/removing a column from a table
# so that the column can be used in the migration. Doesn't take any arguments, will update the AR
# model that it is called on.
ActiveRecord#reset_column_information
# Reload rails env while in script/console
reload!
# Rails field types
# :type MySQL type options
@latortuga
latortuga / gemfromgit.md
Created October 26, 2010 23:00
Install gem from git
$ git clone git://github.com/author/gem_name
$ cd gem_name

install dependencies, sudo gem install xxx

$ rake gem

$ sudo gem install pkg/gem_name-1.1.1.gem

@latortuga
latortuga / gitsvn.md
Created October 26, 2010 23:07
Git-svn tricks

Some of this is pulled directly from the git-svn man page.

Push a local git-branch to a new remote new-svn-branch

git svn branch new-svn-branch

now there is a new remote tracking branch, confirm with git branch -r to push local git-branch changes to the new svn branch git checkout git-branch git rebase --onto new-svn-branch OR from master (this seems to work better) git rebase --onto new-svn-branch master git-branch

@latortuga
latortuga / refresh_css.js
Created October 27, 2010 19:26 — forked from mikelikespie/refresh_css.js
CSS reload bookmarklet
/*
Add a bookmark to this
javascript:(function(){var c=document.getElementsByTagName("link");for(var d=0;d<c.length;d++){var a=c[d];if(a.type=="text/css"){var e="css_buster_"+Math.floor(Math.random()*1000000000);var g=a.href.split("?",1);var f;if(g.length>1){var b=g[1].indexOf("&")==-1;if(b){f=e}else{f=g[1]+"&"+e}}else{f=e}a.href=g[0]+"?"+f}}})();
*/
(function() {
var links = document.getElementsByTagName('link');
for (var i = 0; i < links.length; i++) {
var l = links[i];
if (l.type == 'text/css') {
@latortuga
latortuga / interview question
Created October 28, 2010 16:05
An interesting interview question
Given a set of numbers from 0 to 2^n-1, with one missing, how would you find the missing number in one pass through the set and using at most n bits of extra storage
@latortuga
latortuga / webapp.rb
Created November 16, 2010 19:49 — forked from igrigorik/webapp.rb
require 'rubygems'
require 'rack'
class Object
def webapp
class << self
define_method :call do |env|
func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?)
[200, {}, send(func, *attrs)]
end
@latortuga
latortuga / git-differ.sh
Created January 5, 2011 17:55
git tricks
"TortoiseMerge.exe" "$2" "$5" | cat
#!/usr/bin/env python
"""
fabfile.py
Copyright (c) 2011 Giovanni Collazo
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@latortuga
latortuga / typo.txt
Created April 12, 2011 01:06
Possible typo in postfix setup guide
I think I found a typo in your guide and I wanted to draw your attention to it.
In the section Data > Add users and domains > Adding template, one of your SQL lines looks like the following:
INSERT INTO users (id,name,maildir,clear) VALUES
('email@address','short description','foldername/',encrypt('password') );
I think that instead of 'clear' as the last field being inserted into, you meant 'crypt' because you are encrypting a password.
@latortuga
latortuga / about.md
Created August 9, 2011 15:47 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer