Skip to content

Instantly share code, notes, and snippets.

@karlseguin
karlseguin / gist:852817
Created March 3, 2011 14:08
simulate typing into an input
function simType(input, value)
{
var characters = value.split('');
var i = 0;
var id = setInterval(function()
{
input.value += characters[i++];
if (i == characters.length) { clearInterval(id); }
}, 75);
};
@karlseguin
karlseguin / gist:856331
Created March 5, 2011 12:48
mogade.com nginx setup
gem install passenger
wget http://sysoev.ru/nginx/nginx-0.8.54.tar.gz
tar -xvf nginx-0.8.54.tar.gz
rm -fr nginx-0.8.54.tar.gz
wget https://github.com/agentzh/headers-more-nginx-module/tarball/v0.14 --no-check-certificate
tar -xvf v0.14
rm -rf v0.14
mv agentzh-headers-more-nginx-module-2cbbc15/ more-headers-module
cd nginx-0.8.54/
@karlseguin
karlseguin / gist:878191
Created March 20, 2011 08:18
shitty msdn example
// I goto: http://msdn.microsoft.com/en-us/data/gg685467
//and this is one of the first thing I see...*horrible*
[HttpPost]
public ActionResult Create(Blog newBlog)
{
try
{
using (var db = new BlogContext())
{
@karlseguin
karlseguin / gist:923076
Created April 16, 2011 12:16
Rails ORM for MongoDB
module Document
extend ActiveSupport::Concern
module ClassMethods
def collection
Store[self.to_s.tableize]
end
def find_by_id(id)
found = collection.find_one(IdGenerator.from_string(id))
found.nil? ? nil : self.new(unmap(found))
end
@karlseguin
karlseguin / gist:927798
Created April 19, 2011 13:46
Which is the best test?
it "sorts the result by ascending date" do
User.should_receive(:find).with(anything(), hash_including(:sort => [:date, Mongo::ASCENDING]))
User.most_recent
end
#vs
# some common and fixed data for the entire fixture
# I'm pulling this out because I don't want the setup to seem like a big deal, because I don't think it is
def setup
@karlseguin
karlseguin / gist:939470
Created April 24, 2011 10:22
select_index monkeypatch
class Array
def select_index
values = []
self.each_index{|i| values << self[i] if yield i }
values
end
end
@karlseguin
karlseguin / gist:974008
Created May 16, 2011 06:25
Just can't help myself...
it "deletes the leaderboard" do
leaderboard = Factory.create(:leaderboard)
Leaderboard.count.should == 1 #just can't help myself
leaderboard.destroy
Leaderboard.count.should == 0
end
@karlseguin
karlseguin / gist:1051210
Created June 28, 2011 14:11
Content of my killed HN post
original existed at: http://news.ycombinator.com/item?id=2703771 (comments still exist)
Perhaps grumpiness has got the best of me this morning, but this is at least the second time that I've seen the "Our office is too big -- we need some badass hackers to fill it up", job posting on HN and something about it grates me the wrong way.
First, the formatting is brutal. It is possibly a markup language I simply don't recognize – but then, neither does HN. The different roles blend into each other, the spacing is all uniform removing any visual grouping.
Second, the content is childish. It screams (to me) of either unprofessionalism or fake-cool. What's "TONS" of experience? What does "physically live at a ton of smb's" mean? Are you saying the product is already in use by a lot of business that hire mostly fat employees? What's an "extremely small core dev team"? 1? Scaling "really big stuff"? Like a mountain? Finally, the salary description includes "blah blah blah".
Here's a writing tip, words that end in
@karlseguin
karlseguin / gist:1080254
Created July 13, 2011 13:01
My First Go Test
import ("testing")
func TestEmptyReturnsTrueWhenEmpty(t *testing.T) {
if (new(LinkedList).IsEmpty() == false) {
t.Fatal("Expecting list to be empty")
}
}
@karlseguin
karlseguin / gist:1080295
Created July 13, 2011 13:35
Forward-only linked list in go
package hatch
type Element struct {
next *Element
Value interface{}
}
func (e *Element) Next() (*Element) { return e.next }
type LinkedList struct {