Skip to content

Instantly share code, notes, and snippets.

@reagent
reagent / nav_link.rb
Created April 11, 2012 14:24 — forked from greypants/README.markdown
Versatile nav_link helper for adding 'selected' class to navigation elements
class Family < ActiveRecord::Base
def self.with_discontinued_accessories
joins(:products).where({
:products => {
:accessory => true,
:production_status => 'discontinued',
:active => true,
:parent_id => nil
}
@reagent
reagent / gist:2645366
Created May 9, 2012 15:15
Grumble grumble...
class Breadcrumb
include ActionView::Helpers::TagHelper
def initialize
@crumbs = []
end
def append(name, link)
@crumbs << Breadcrumb::Crumb.new(name, link)
end
@reagent
reagent / gist:3100660
Created July 12, 2012 20:14 — forked from paulirish/gist:3098860
Open Conference Expectations

Open Conference Expectations

LOL

@reagent
reagent / past_orders.rb
Created September 12, 2012 20:19 — forked from efatsi/past_orders.rb
methodology comparison
def find_suggestions_for(restaurant)
past_orders = []
orders.each {|o| past_orders << o if o.restaurant == restaurant }
past_orders
end
def find_suggestions_for(restaurant)
orders.inject([]) do |result, order|
result << order if order.restaurant == restaurant
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct Person {
char *name;
};
struct Person *create_person_stack(char *name)
{
#include <stdio.h>
#include <string.h>
struct Person {
char *name;
};
int main(int argc, char *argv[])
{
int i = 0;
@reagent
reagent / strdup.c
Created September 20, 2012 21:15
implementation of strdup() from glibc
/* Copyright (C) 1991, 1996, 1997, 1998, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@reagent
reagent / strdup.c
Created September 20, 2012 21:19
implementation of strdup() from BSD libc
/* $OpenBSD: strdup.c,v 1.6 2005/08/08 08:05:37 espie Exp $ */
/*
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
@reagent
reagent / encode-test
Created September 26, 2012 15:31
Test harness for David's encode.c program
#!/usr/bin/env ruby
# Usage: ./encode-test /path/to/encode.c
require 'fileutils'
def directory(path)
path = File.expand_path(path)
if File.directory?(path)
path