Skip to content

Instantly share code, notes, and snippets.

View phiggins's full-sized avatar

pete higgins phiggins

View GitHub Profile
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)
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 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
View debride_file_extension_fix.diff
diff --git a/lib/debride.rb b/lib/debride.rb
index 54e2f4f..7730457 100755
--- a/lib/debride.rb
+++ b/lib/debride.rb
@@ -35,31 +35,36 @@ class Debride < MethodBasedSexpProcessor
end
def self.load_plugins proj = PROJECT
- unless defined? @@plugins then
- @@plugins = []
@phiggins
phiggins / gist:7850ccf50d2924f88ad0
Last active December 15, 2016 21:44
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:a73fcb0173a598928876
$ irb
> require 'set'
=> true
> Set.instance_method(:divide)
=> #<UnboundMethod: Set#divide>
> Set.instance_method(:divide).source_location
=> ["/home/pete/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/set.rb", 466]