Skip to content

Instantly share code, notes, and snippets.

View boxofrad's full-sized avatar

Dan Upton boxofrad

View GitHub Profile
@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();
@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,
class Something
def some_method(param)
@param = param
100.times { puts "Hello #{param}" }
end
end
@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
@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 / 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 / captiveportal-register.php
Created November 1, 2013 12:29
pfSense 2.0 captive portal self registration
<?php
require_once("functions.inc");
require_once("config.lib.inc");
require_once("auth.inc");
if ($_POST) {
$a_user = &$config['system']['user'];
unset($input_errors);
$pconfig = $_POST;
@boxofrad
boxofrad / nth.rb
Last active December 31, 2015 08:29
require 'io/console'
Signal.trap(:SIGINT) { exit }
puts "CTRL-C to quit...\n"
print 'Password: '
password = STDIN.noecho(&:gets)
puts
@boxofrad
boxofrad / gist:8492161
Created January 18, 2014 15:46
Install curl and wget on pfSense
setenv PACKAGESITE ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8-stable/Latest/
/usr/sbin/pkg_add -r curl
/usr/sbin/pkg_add -r wget
class Calc
NUMBERS = %w[one two three four five six seven eight nine ten]
def initialize(number = 0, meth = nil)
@number = number
@meth = meth
end
NUMBERS.each_with_index do |number, index|
define_method(number) do