Skip to content

Instantly share code, notes, and snippets.

View tsnow's full-sized avatar

Tim Snowhite tsnow

  • Palantir
  • Washington, DC
View GitHub Profile
@tsnow
tsnow / README.md
Created February 1, 2013 19:00
Ridecharge C# JSON Parsing Assignment

Spend 5 literal minutes thinking about:

  • How much time you have to devote to this exercise?
  • How can you verify that your solution is correct?

Then:

  1. Fork this gist and clone it locally.
  2. Send [email protected] and [email protected] a link to your forked gist, along with an estimate of how long the solution should take in man-hours and an estimate of when you will be finished.
  3. Complete the exercise.
@tsnow
tsnow / say_what.sh
Created May 8, 2013 15:39
dark magic
exec 3<> /dev/udp/127.0.0.1/8125 ; echo "gtfo" >&3 ; exec 3<& ; exec 3>&
class Array
def self.find_rec(ary,start,fin,num)
return if fin < start
center = ((fin + start) / 2)
# http://blog.8thlight.com/uncle-bob/2013/05/27/TransformationPriorityAndSorting.html
# The Transformations
#
# So what are these transformations? Perhaps we can make a list of them:
#
# ({}–>nil) no code at all->code that employs nil
# (nil->constant)
# (constant->constant+) a simple constant to a more complex constant
# (constant->scalar) replacing a constant with a variable or an argument
(10000000..99999999). #change to e.g. 1000..9999 for all 4 digit, 100000..999999 for all 6 digit nums
select do |i|
start=i.to_s.split('');
bk= (start.length / 2) - 1;
first = start[0..bk].join('').to_i;
last = start[-(bk+1)..-1].join('').to_i;
next if last > first;
prod = (first * last).to_s.split('');
prod.sort == start.sort;
end
def f(n)
@q ||= []
[email protected](n)
puts [@q,v,n].inspect
return -n if v
@q.push(n)
n
end
=begin
library("optparse")
option_list <- list(
make_option(c("-p", "--no_png"), action="store",default='TRUE')
)
args <- parse_args(OptionParser(option_list = option_list))
no_png <- args$no_png == "TRUE"
f <- file("stdin")
@tsnow
tsnow / architecture_test.sh
Last active December 23, 2015 16:39
Fixing Pim Firmware issues at the Varnish / Relayd level
# Test https://rips.ridecharge.com/firmware_resources/global/miamiyellow/rc_pulsar_a/Pos at all endpoints in our architecture
# ssh coruscant.dca1.rws
export webpath="/firmware_resources/global/miamiyellow/rc_pulsar_a/Pos";
for j in `for i in 192.168.1.203 192.168.1.204 192.168.1.206 192.168.1.207 192.168.1.208 192.168.1.209; do echo "unicorn:http://$i:51010"; done | xargs` relayd_load_balancer:http://127.0.0.1:11010 lhttp_relayd_rips.prod.rws:http://192.168.1.227:50080 lhttps_relayd_rips.prod.rws:https://192.168.1.227:50443 varnish:http://0.0.0.0:6081 https_relayd_rips.prod.rws:https://192.168.1.227:443 public:https://rips.ridecharge.com; do
export name=`echo "$j" | sed 's/https*:.*//'`;
export endpoint=`echo "$j" | grep -o -e 'https*:.*'`;
echo $name $endpoint;
curl -w '%{http_code} %{size_download} \n' --insecure -H 'X-Forwarded-Proto: https' -H 'X-Forwarded-SSL: on' -H 'Host: rips.ridecharge.com' -H 'X-Forwarded-By: rips.ridecharge.com' -o /dev/null "$endpoint""$webpath" 2>/dev/null;
done
echo "Disk Spac
@tsnow
tsnow / README.md
Created September 30, 2013 15:21
Bundle Conservative Updating

After reading up on the bundler project about "conservative updating" this, bundle_nice.sh above, appears to be the suggested workflow for updating Just the Gems You Have To:

  • gem list -r --all $X to get the latest version of whatever gem you want.
  • Edit Gemfile to add a new '=' version constraint for that gem.
  • Edit Gemfile.lock to relax the locked constraint for that gem, up to the new version. Dependencies (gem specification $X -v $version) will be updated by bundle install and bundle check in the Gemfile.lock automatically.
  • Run bundle install to conservatively update the dependency graph, and Gemfile.lock.
  • Remove the constraint from the Gemfile, and run bundle check to update the Gemfile.lock with the removed constraint without installing new gems.
  • whew.

Below is a log of those actions, along with git diff interspersed for clarity.

@tsnow
tsnow / ignore_local_remote_branches.sh
Created October 6, 2013 19:34
working with many many remotes, e.g. emacs starter kit, dotfiles, gitx forks, etc
# delete (locally) remote branches older than 2013 ("not" 2013)
git branch -r | while read i; do git log -n 1 $i --pretty=format:"%ci" | grep -e '^2013' && echo $i || git branch -r -d $i; done
# delete (locally) remote branches which are fully merged into another remote branch
git branch -r | grep -v origin/HEAD | while read branch; do git branch -r --merged $branch | grep -v $branch; done | sort | uniq | while read rm_branch; do git branch -r -d $rm_branch; done
# Remove (locally) all branches on all remotes which are merged into their own $origin/master. Set that remote to only sync those branches.
git remote | while read i; do git ls-remote -h $i | sed "s,.*refs/heads/,$i/,"; done > all_heads;