Skip to content

Instantly share code, notes, and snippets.

desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.'
task :routes => :environment do
all_routes = ENV['CONTROLLER'] ? ActionController::Routing::Routes.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] } : ActionController::Routing::Routes.routes
routes = all_routes.collect do |route|
name = ActionController::Routing::Routes.named_routes.routes.index(route).to_s
verb = route.conditions[:method].to_s.upcase
segs = route.segments.inject("") { |str,s| str << s.to_s }
segs.chop! if segs.length > 1
reqs = route.requirements.empty? ? "" : route.requirements.inspect
{:name => name, :verb => verb, :segs => segs, :reqs => reqs}
@hardbap
hardbap / gist:29881
Created November 28, 2008 02:09 — forked from dhh/gist:29752
config.action_controller.asset_host = Proc.new do |source, request|
non_ssl_host = "http://asset#{source.hash % 4}.backpackit.com"
ssl_host = "https://asset1.backpackit.com"
if request.ssl?
case
when source =~ /\.js$/
ssl_host
when request.headers["USER_AGENT"] =~ /(Safari)/
non_ssl_host
@hardbap
hardbap / video_hack.js
Created May 3, 2020 14:09
Speed up videos on web that don't display controls
document.querySelectorAll('video').forEach((video)=>video.playbackRate = 1.75);
@hardbap
hardbap / regex_a.rb
Last active June 26, 2018 17:26 — forked from JoshCheek/regex.rb
Ruby 1.9 regex, named capture groups to local variables
/(?<area_code>\d{3}) (?<local_number>\d{3}-\d{4})/ =~ "123 456-7890"
local_variables # => [:area_code, :local_number]
area_code # => "123"
local_number # => "456-7890"

You may be asking yourself "why didn't this idiot just use Sphinx, Xapian or Hyper Estraier?". The decision to use MySQL Full-Text Search was based on the fact that this is a smallish project with minimal full-text searching needs. I felt that the requirements didn't warrant downloading/compiling/installing software, monitoring daemons/processes, rebuilding indices, and all the other crap that comes with the big boys of full-text indexing. Don't get me wrong I love Sphinx and Xapian, having used both on several projects, but I wanted something with a little less ceremony. Plus I'm always up for learning something new.

migration

The first thing you need to do is convert the storage engine from the Rails default **In

@hardbap
hardbap / ninja.rb
Created August 8, 2012 15:24
cool block passing from girl_friday
class Ninja
def initialize(name, &block)
@name = name
@move = block
end
def attack
@move.call
end
end
This assumes that you start with 5 cards, 1 being Holocron another is Force Lightning. You also need to start with 2 resources.
I don't know the statistical probabilites behind this but it *is* in the realm of possibility. :)
This tutorial is going to just run it from one side. Of course your opponent may have die manipulation, etc. Let's just assume everything
goes swimmingly and if you need to discard one of your four cards to make it happens it just works. ;)
1. play Holocron on Palp. (4 cards in hand, 2 resources)
2. roll out Palp, *, 3R, 3R
3. resolve 3R, 3R for 10 including Palps ability
4. resolve * to play Force Lightning, pay 1 to roll it out (4 cards, 1 resource) hit 4R1
@hardbap
hardbap / upgrade_postgres.txt
Last active December 14, 2016 01:28
Upgrading postgresql from 9.4.x to 9.5.x with Hstore
# Orignal instructions here: https://kkob.us/2016/01/09/homebrew-and-postgresql-9-5/
1. Stop postgresql
$ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
2. Install postgresql 9.5
$ brew update && brew upgrade postgresql
3. Make a new 9.5 database
$ initdb /usr/local/var/postgres9.5 -E utf8

Keybase proof

I hereby claim:

  • I am hardbap on github.
  • I am hardbap (https://keybase.io/hardbap) on keybase.
  • I have a public key ASAjRU2fWZt-euiaLPE0s0B0sUPSICrEKbU07DJQiTpiPQo

To claim this, I am signing this object:

export LANGUAGE="en_US.UTF-8"
export LANG="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
sudo su postgres
psql
update pg_database set datistemplate=false where datname='template1';
drop database Template1;