View get_tokens.sh
$ cd `gem which parser`/..
$ ag -oa ':t[A-Z_]+' | ruby -ne 'print $_.split(/::/).last' | sort -u | pbcopy
View deploy.sh
#!/usr/bin/env bash -l
timestamp="$(date '+%Y-%m-%d-%k:%M:%S')"
archive_name="${timestamp}.tar.gz"
ruby_version=""
pem_file="$HOME/.ssh/JoshAdmin.pem"
remote_user="ec2-user"
remote_host="ec2-54-167-223-244.compute-1.amazonaws.com"
remote_path="/home/$remote_user/app/"
View fourier.rb
module Fourier
extend self
extend Math
include Math
def to(fx)
n = fx.length
n.times.map do |u|
real = imaginary = 0
fx.each_with_index do |(f_real, f_imaginary), k|
View list.c
#include <stdio.h>
#include <stdlib.h>
// (4, head) <-- base of the list
// /
// / ("c") -> ("d") -> ("e")
// ("b")----/
struct node {
View pg_diff_tables.rb
# UPDATE: I've stopped putting updates into this gist
# as it's starting to get into the internal structure of our db
# Instead, you need to get the link to the private gist.
# You can ask me or Matt for it.
# -----------------------------
# CURRENT STATUS:
# * handles composite primary keys
View composition_vs_inheritance.rb
require 'sinatra/base'
require 'rspec/autorun'
require 'capybara/dsl'
class MyApp < Sinatra::Base
enable :inline_templates
get '/users/:id' do
"User number #{params[:id]}"
end
View program.c
// After you think you understand this program, try writing it yourself until
// you can get it to work, the first time, without error ^_^
//
// ALSO: remember:
// $ gcc program.c # compile
// $ ./a.out # run
// We'll get `printf` from standard input/output's header file
#include <stdio.h>
View 1.black_magic_converting_a_ruby_object_to_a_string.rb
# ========== READ THIS LAST ==========
# It prob won't make sense, anyway, as there's a lot of implicit nuance.
# I don't even fully understand the flags I'm setting it to.
public def to_s!
require 'fiddle'
Fiddle::Pointer.new(2*object_id)[0, 16] =
[5373957, 2*String.object_id].pack('q2') # flags & class
end
# ========== SETUP ==========
View omg.c
#include <stdio.h>
/* $ ./a.out Erin
// registers (stored on the CPU)
stack pointer: 0x02
base pointer: 0x00
program counter: 0043
// "the stack" ("working" memory, ie for a given function)
View accidentally_renames_instance_variables.rb
require 'fiddle'
public def class=(new_class)
obj_ptr = Fiddle::Pointer.new 2*self.object_id
klass_ptr = Fiddle::Pointer.new 2*new_class.object_id
obj_ptr[8, 8] = klass_ptr.ref[0, 8]
end
class A
attr_accessor :a, :b, :c
end