Skip to content

Instantly share code, notes, and snippets.

View boxofrad's full-sized avatar

Dan Upton boxofrad

View GitHub Profile
@boxofrad
boxofrad / things.c
Created September 14, 2013 21:44
Function that "returns" an array of structs
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
struct Thing { char *name; };
void get_things(int *number_of_things, struct Thing **things)
{
int num = 10;
struct Thing *tmp = malloc(sizeof(struct Thing) * num);
@boxofrad
boxofrad / gist:6522269
Last active December 22, 2015 19:49
Rickroll your co-workers
aliases=(cd ls pwd git rails rake bundle exit ssh rvm ebenv vi vim)
rickroll() {
open 'http://www.youtube.com/watch?v=dQw4w9WgXcQ'
}
for command in ${aliases[*]}
do
alias $command=rickroll
done
@boxofrad
boxofrad / application_controller.rb
Created August 13, 2013 08:48
Handy controller profiling code
around_filter :profile
def profile
if params[:profile] && result = RubyProf.profile { yield }
out = StringIO.new
RubyProf::GraphHtmlPrinter.new(result).print out, :min_percent => 0
self.response_body = out.string
else
yield
end
class Something
def some_method(param)
@param = param
100.times { puts "Hello #{param}" }
end
end
@boxofrad
boxofrad / gist:4946574
Created February 13, 2013 17:49
Rawnet ASCII
:G1.
:L:1C;
if;;;iC,
Ci;::;;ti
iL;;, .;;tLC. .CCG
;C;;: .i;C;tt .,,. ,:::,. ... .,, .:;i;, .:;;:. CCCG
ffii: ;iiiiiC. :CCCCCCCi 1CCCCCCCCCL. CCCC: CCCC. fCCC: .CGCCCCCCCG1 :CCCCCCCCGL. .CCCCCCCCCC
:G1ii. :ii,:1iC. 1CCCCLt1ff ;CL1:,,:tCCCC, tCCCL :CCCCC CCCC. 1GCCGL;;tCCCCC. CCCCC;,,iCCCG; .CCCCffff1
1C11: ;1: :11C .CCCC; . :CCCL .CCCC, LCCCCC; tCCC1 .GCCG, LCCC1 LCCCi .CCCL .CCCG,
1Ltt, 1. itft .CCCC. iLCCCCCCCCCL 1CCCL iCCCLCCC .CCCC ,GCCG. 1CCCf .GCCCLLLLLCGCCCf .CCCG,
@boxofrad
boxofrad / gist:2397041
Created April 16, 2012 08:14
Mirror scrolling of 2 differently sized HTML elements
function mirrorScroll(el1, el2) {
var el1TotalHeight = el1[0].scrollHeight;
var el2TotalHeight = el2[0].scrollHeight;
var totalHeightRatio = el2TotalHeight / el1TotalHeight;
var el1WindowHeight = el1.height();
var el2WindowHeight = el2.height();
var windowHeightRatio = el2WindowHeight / el1WindowHeight;
var el1PixelsScrolled = el1.scrollTop();