Skip to content

Instantly share code, notes, and snippets.

View samwho's full-sized avatar
🦀
Still in love with Rust.

Sam Rose samwho

🦀
Still in love with Rust.
View GitHub Profile
#!/usr/bin/env php
<?php
// Ewww a global variable!
$parsed_fixtures = array();
function parse_fixture($table, $values) {
global $parsed_fixtures;
$parsed_fixtures[$table][] = $values;
}
@samwho
samwho / .vimrc
Created August 1, 2011 11:13
My .vimrc file.
" Syntax highlighting on
syntax on
set t_Co=256
colors zenburn
set go-=m " Hide menu
set go-=T " Hide toolbar
set nu! " Line numbers
set hidden " Hide buffers when switching rather than closing them
@samwho
samwho / facebook_puzzle.rb
Created August 2, 2011 02:37
Solution to the puzzle Facebook gave me.
$words = [
'hello',
'there',
'yello',
'bob',
'tom',
'mabel',
'says',
'hi',
'secret',
@samwho
samwho / .gitignore
Created July 21, 2012 12:39
Shifting Thoughts and Gist.io
.session.vim
@samwho
samwho / mandom.rb
Last active December 12, 2015 07:59
Short Ruby script to open a man page at random.
man_pages = `manpath`.chomp.split(':').inject([]) do |memo, path|
memo += Dir[File.join(path, 'man*', '*')]
end.select { |path| path.match(/.*?\.[1-9]$/) }
exec "man #{man_pages[rand(man_pages.length)]}"
@samwho
samwho / strings.rb
Created June 16, 2013 17:18
Looking for expletives in Mac OSX binary files.
WORDLIST = [
"fuck",
"shit",
"cunt",
"wtf",
"wank",
"crap",
"hell",
"lame",
"rubbish",
@samwho
samwho / test_interspersity.rb
Created August 5, 2013 13:57
Interspersity test
def test_interspersity array
# Calculate the ideal average distance between elements by summing how many of
# each element exist and then dividing the length of the array by that number.
ideal_avg_distance = Hash.new(0)
array.each { |elem| ideal_avg_distance[elem] += 1 }
ideal_avg_distance.keys.each do |k|
ideal_avg_distance[k] = array.length.to_f / ideal_avg_distance[k]
end
# Gather up all of the indices that each element appears at.
@samwho
samwho / random_regex.rb
Created October 30, 2013 18:15
/dev/random regexes
devrand = File.open("/dev/random", 'r')
valid = 0
invalid = 0
at_exit do
puts "\n\n\n\n#{valid}/#{valid + invalid}"
end
while chunk = devrand.read(64)
@samwho
samwho / symbols.rb
Created December 15, 2013 20:48
Know your symbols!
# Ruby creates symbols at many different points in execution. Symbols occupy
# between 4 and 8 bytes in memory. Check using this code:
#
# #include <ruby/ruby.h>
# #include <stdio.h>
#
# int main(int argc, char* argv[]) {
# printf("%d\n", sizeof(ID));
# return 0;
# }
This file has been truncated, but you can view the full file.
INFO global: Vagrant version: 1.9.0
INFO global: Ruby version: 2.2.5
INFO global: RubyGems version: 2.4.5.1
INFO global: VAGRANT_EXECUTABLE="C:\\HashiCorp\\Vagrant\\embedded\\gems\\gems\\vagrant-1.9.0\\bin\\vagrant"
INFO global: VAGRANT_INSTALLER_EMBEDDED_DIR="C:\\HashiCorp\\Vagrant\\embedded"
INFO global: VAGRANT_INSTALLER_ENV="1"
INFO global: VAGRANT_INSTALLER_VERSION="2"
INFO global: VAGRANT_LOG="debug"
INFO global: VAGRANT_OLD_ENV_ACLOCAL_PATH="C:\\Program Files\\Git\\mingw64\\share\\aclocal;C:\\Program Files\\Git\\usr\\share\\aclocal"
INFO global: VAGRANT_OLD_ENV_ALLUSERSPROFILE="C:\\ProgramData"