Skip to content

Instantly share code, notes, and snippets.

pete higgins phiggins

Block or report user

Report or block phiggins

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@phiggins
phiggins / gist:8681048
Created Jan 29, 2014
Nand2Tetris from the commandline
View gist:8681048
pete@balloon:~/projects/nand2tetris/phiggins/01$ pwd
/home/pete/projects/nand2tetris/phiggins/01
pete@balloon:~/projects/nand2tetris/phiggins/01$ ../../tools/HardwareSimulator.sh ~/projects/nand2tetris/phiggins/01/Mux4Way16.tst
End of script - Comparison ended successfully
pete@balloon:~/projects/nand2tetris/phiggins/01$
@phiggins
phiggins / excon benchmark
Created Dec 1, 2010
excon benchmark vs google
View excon benchmark
$ ruby benchmarks/excon_vs_google.rb
[em-http-request, HTTParty, Net::HTTP, Net::HTTP (persistent), open-uri, RestClient, StreamlyFFI (persistent), Typhoeus, Excon, Excon (persistent)]
+--------------------------+-----------+
| tach | total |
+--------------------------+-----------+
| Excon | 7.614298 |
+--------------------------+-----------+
| Typhoeus | 7.723362 |
View bin_packing.rb
require "minitest/autorun"
require "benchmark/ips"
class CachingPack
def self.call(inventory, order)
return if inventory.nil? || inventory.empty?
return if inventory.inject(:+) < order
loop do
r = cached_pack(inventory, order)
@phiggins
phiggins / gist:7850ccf50d2924f88ad0
Last active Dec 15, 2016
bash scripts for finding dead rails code
View gist:7850ccf50d2924f88ad0
for i in app/models/post.rb ; do sed -e "s/\s\+def \(self\.\)\?\([^( ]*\).*\|\s\+scope :\([^,]*\).*/\2\3/" -e 'tx' -e 'd' -e ':x' $i | while read j ; do echo $(grep -R $j app/ lib/ config/ | wc -l) $j ; done ; done | sort -rn
for i in $(find app/views/ -type f) ; do echo $(grep -R $(echo $i | sed "s/.*\/_\?\([^.]*\).*/\1/") app/ | wc -l) $i ; done | sort -rn
View gist:5a24567e7f24c5c238969dfde2e8aa5e
for i in $(find app/views/ -type f) ; do echo $(grep -R $(echo $i | sed "s/.*\/_\?\([^.]*\).*/\1/") app/ | wc -l) $i ; done | sort -rn | grep "^0" | sed 's/^0 //' | xargs git rm
View httparty_example.rb
require 'httparty'
class Webservice
CANDIDATE = <<XML
<Candidate xmlns="com.mysite/2010/10/10" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<FirstName>%s</FirstName>
<LastName>%s</LastName>
<Email>%s</Email>
<Gender>%s</Gender>
</Candidate>
View scrabble_cheater.md

Scrabble Cheater

  • I'd like you to help me cheat at Scrabble. I'd like you to write some code to give me all possible words that can be created given a set of tiles. The maximum number of tiles you can have in Scrabble is seven, so you'll need to find all of the words that can be made out of those tiles.

On most unix systems (including Mac OS X), you can find a word dictionary in "/usr/share/dict/words" - let's assume that all of these words (including "zymogenic"!) are up valid for scrabble. Feel free to use your own custom dictionary, but this will do for this purpose.

Here's sample code that reads in all of the words into an array, removes newlines, and downcases them.

words = File.readlines("/usr/share/dict/words").map(&:chomp).map(&:downcase)
View css_diff.rb
branches = %w[ master switch-to-sassc ]
tmp = Pathname.new(Dir.tmpdir)
branches.each do |branch|
asset_dir = tmp + "assets_#{branch}"
if asset_dir.exist?
puts "#{asset_dir} exists, skipping"
next
end
View gist:d6e91605ba744090c2a54466ea3ad29a
# Find all strings in a CSS file or files that start with a '.' and
# stop on some common CSS delimiters.
# This is only looking at _map.scss, but you could look at any other file or even
# app/assets/stylesheets if you wanted to see everything.
grep -hro "\.[^ .,():]\+" app/assets/stylesheets/partials/mobile/_map.scss |
# The sort | uniq part makes it so we don't look for duplicates.
sort |
uniq |
# Loop over the things we just found.
while read i ; do
View gist:59edc5b147f6dd1aad4c58ad47741f0a
# Find all thing strings in a CSS file or files that start with a '.' and
# stop on some common CSS delimiters.
# This is only looking at _map.scss, but you could look at any other file or even
# app/assets/stylesheets if you wanted to see everything.
grep -hro "\.[^ .,():]\+" app/assets/stylesheets/partials/mobile/_map.scss |
# The sort | uniq part makes it so we don't look for duplicates.
sort |
uniq |
# Loop over the things we just found.
while read i ; do
You can’t perform that action at this time.