Skip to content

Instantly share code, notes, and snippets.

int main(int argc, char *argv[])
{
int val = 5;
switch(val) {
case 0: do {
case 5:
printf("Got here, value is %d\n", val);
case 4:
printf("Got here, value is %d\n", val);
class Bar
def initialize(name)
@name = name
end
def to_str
@name
end
class EmailCollection
include Enumerable
delegate :each, :to => :email_addresses
def initialize(raw_email_addresses)
@raw_email_addresses = raw_email_addresses
end
def valid_emails
select {|e| e.match(email_regex) }
@reagent
reagent / email.rb
Created October 17, 2012 04:51 — forked from efatsi/email.rb
class Email
def initialize(address)
@address = address
end
def address
@address.strip
end
class Particpant < AR::Base
delegate :require_name?, :require_email?, :require_phone?, :to => :project, :allow_nil => true
with_options :on => :update do
validates_presence_of :name, :if => :require_name?
validates_presence_of :email, :if => :require_email?
validates_presence_of :phone, :if => :require_phone?
end
@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
@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 / 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
#include <stdio.h>
#include <string.h>
struct Person {
char *name;
};
int main(int argc, char *argv[])
{
int i = 0;
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct Person {
char *name;
};
struct Person *create_person_stack(char *name)
{