Skip to content

Instantly share code, notes, and snippets.

View johnhaitas's full-sized avatar

John Haitas johnhaitas

View GitHub Profile
@johnhaitas
johnhaitas / rake-zlib-error
Created November 9, 2011 18:32
rake gem install error - zlib
% rvm pkg install zlib
% rvm install 1.9.3 --with-zlib-dir=~/.rvm/usr
% rvm use 1.9.3
% gem install rake
ERROR: Loading command: install (LoadError)
cannot load such file -- zlib
ERROR: While executing gem ... (NameError)
uninitialized constant Gem::Commands::InstallCommandERROR: Loading command: install (LoadError)
cannot load such file -- zlib
ERROR: While executing gem ... (NameError)
@johnhaitas
johnhaitas / game-of-life.rb
Created December 5, 2011 16:51
Conway's Game of Life in Ruby
def neighbors(cell)
neighbors = []
x = cell[0]
y = cell[1]
(x-1..x+1).each do |xx|
(y-1..y+1).each do |yy|
next if xx==x && yy==y
neighbors.push([xx,yy])
end
end
@johnhaitas
johnhaitas / saving-time.rb
Created December 5, 2011 17:27
"Saving Time" solution in Ruby
a='o'*12
a[gets.to_i%12]=?h
a[m=$_[3,2].to_i/5]=a[m]<?o??x:?m
b=Array.new(11){" "*17}
12.times{|i|t=i*0.523-1.57;b[(5+4.9*Math.sin(t)).round][(8+8*Math.cos(t)).round]=a[i]}
b.map{|l|puts l.rstrip}
@johnhaitas
johnhaitas / delete_older_than_example.pl
Created December 21, 2011 20:20
Perl - delete files in folder older than ...
#!/usr/bin/perl
use File::Find;
my $backup_root = "/path/to/folder"
# purge backups older than AGE in days
my @file_list;
my @find_dirs = ($backup_root); # directories to search
my $now = time(); # get current time
my $days = 30; # how many days old
@johnhaitas
johnhaitas / gist:3156488
Created July 21, 2012 17:27
conditionals for conditional binding events for browsers in FixedColumns
if ( !$.browser.mozilla )
{
// Bind 'scroll' for most browsers
} else {
// Bind 'scroll' for Mozilla browsers
}
if ( $.browser.safari )
{
// Bind 'mousewheel' for Safari
@johnhaitas
johnhaitas / gist:3169923
Created July 24, 2012 13:29
browser detector for FixedColumns
"_fnDetectBrowser": function ()
{
var ua = navigator.userAgent.toLowerCase();
// userAgent RegExp
var rwebkit = /(webkit)[ \/]([\w.]+)/,
ropera = /(opera)(?:.*version)?[ \/]([\w.]+)/,
rmsie = /(msie) ([\w.]+)/,
rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/,
rsafari = /(safari)[ \/]([\w.]+)/,
@johnhaitas
johnhaitas / gist:4693189
Last active December 12, 2015 01:39
convert NSDictionary/NSMutableDictionary to literal syntax Xcode Find/Replace regex
[aDictionary objectForKey:@"Key"] -> aDictionary[@"Key"]
=========================================================
Find
\[(\w+) *objectForKey: *(@"\w+") *\]
Replace
\1\[\2\]
@johnhaitas
johnhaitas / gist:5967724
Created July 10, 2013 16:20
Insert git commit hash into Info.plist at the end of build process
#!/bin/sh
# insert_git_hash.sh
# ToGoOrder
#
# Created by John Haitas on 7/9/13.
#
# Location of Info.plist in build product
INFOPLISTPATH="${TARGET_BUILD_DIR}/${EXECUTABLE_NAME}.app/Info.plist"
@johnhaitas
johnhaitas / gist:5967801
Created July 10, 2013 16:28
cleaned up the script to insert git hash into Info.plist
#!/bin/sh
# insert_git_hash.sh
# ToGoOrder
#
# Created by John Haitas on 7/9/13.
#
# Location of Info.plist in build product
INFOPLISTPATH="${TARGET_BUILD_DIR}/${EXECUTABLE_NAME}.app/Info.plist"
#!/bin/sh
# insert_git_hash.sh
# ToGoOrder
#
# Created by John Haitas on 7/9/13.
#
# Location of Info.plist in build product
INFOPLISTPATH="${TARGET_BUILD_DIR}/${EXECUTABLE_NAME}.app/Info.plist"