Skip to content

Instantly share code, notes, and snippets.

View bunnymatic's full-sized avatar
💭
writing computer programs

Mr Rogers bunnymatic

💭
writing computer programs
View GitHub Profile
@bunnymatic
bunnymatic / circle.yml
Last active January 2, 2016 01:38 — forked from jonah-williams/circle.yml
add line to remove heroku git remote if it's already in place
test:
override:
- bundle exec rspec spec
deployment:
acceptance:
branch: master
commands:
- ./script/heroku_deploy.sh <ACCEPTANCE_HEROKU_APP>:
timeout: 300
@bunnymatic
bunnymatic / duplicate_finder.rb
Created November 30, 2013 20:00
find duplicate files by md5 with ruby
#!/usr/bin/env ruby
require 'pp'
files = {}
ctr = 0
print "Searching "
Dir.glob(ARGV[0]).each do |f|
s = File.stat(f)
if s.file?
md5 = (`md5 -q #{f}`).chomp
@bunnymatic
bunnymatic / db.rake
Created June 30, 2013 20:27
Using PGBackups, add tasks for pull from a heroku app and restore to local development database.
namespace :<MY APP NAMESPACE> do
namespace :db do
desc "Fetch the latest backup from heroku"
task :fetch => [:environment] do
app = ENV['app']
if app.blank?
puts "You must specify the heroku app name to get its database (use app=<appname>)"
else
url = `heroku pgbackups:url --app #{app}`
db_prefix = app.gsub('-','_')
@bunnymatic
bunnymatic / custom_array_matchers.rb
Last active July 3, 2020 21:24
RSpec Matchers for increasing/decreasing array tests. Useful when sort may not be the easiest way to do things.
RSpec::Matchers.define :be_monotonically_increasing do
match do |actual|
derivative = actual.each_cons(2).map{|x, y| y <=> x}
derivative.all?{|v| v >= 0}
end
failure_message_for_should do |actual|
"expected array #{actual.inspect} to be monotonically increasing"
end
@bunnymatic
bunnymatic / timezone_testing.rb
Last active December 11, 2015 17:38
Timezone Playtime
puts "Server Timezone: %s" % Rails.configuration.time_zone
# try with ruby 1.8.7/1.9.2
# try with different rails apps timezones
springtime = '04/25/2013 1:30PM'
falltime = '11/12/2013 2:40PM'
# maybe print the app timezone here
times = [[ :now , Time.now ],
[:now_zoned , Time.zone.now],
[:spring_parsed , Time.parse(springtime)],
[:spring_parsed_zoned , Time.zone.parse(springtime)],
@bunnymatic
bunnymatic / d3_attrs_extension.js
Created January 14, 2013 18:21
d3 extensions: attrs() method - allow specification of attrs as a hash instead chained attr().attr().attr()....
if(d3 && d3.selection && d3.selection.prototype) {
d3sp = d3.selection.prototype;
/** add extension functions to d3.selection */
/** attrs - set many attrs on a data node given a hash of attributes
usage:
@bunnymatic
bunnymatic / meteor
Last active December 10, 2015 09:49
new meteor shell script which alllows execution of node processes with easy access to the MeteorJS environment if it's run as meteor-exec. To make this work, replace /usr/local/meteor/bin/meteor with this file, and add a link from meteor-exec to this.
#!/bin/bash
BUNDLE_VERSION=0.2.8
# OS Check. Put here because here is where we download the precompiled
# bundles that are arch specific.
UNAME=$(uname)
if [ "$UNAME" != "Linux" -a "$UNAME" != "Darwin" ] ; then
echo "Sorry, this OS is not supported."
exit 1
@bunnymatic
bunnymatic / bash-completion-lunchy.bash
Created December 23, 2012 23:39
Bash completion script for mperham/lunchy gem
__from_lunchy_list() {
COMPREPLY=()
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=($(compgen -W '$(lunchy list)' -- $cur))
}
complete -F __from_lunchy_list -o default lunchy
@bunnymatic
bunnymatic / nested_content_snippet.rb
Created December 6, 2012 08:28
nested content in rails view helpers
# because i can never remember exactly how and when to use concat
# when building content in helpers
def nested_content
content_tag 'div' do
concat(content_tag 'span', 'span block')
concat(tag 'br')
concat(link_to 'root link', root_path)
concat(tag 'br')
concat(link_to('#') do
concat(content_tag 'h2', 'Head \'em off')
@bunnymatic
bunnymatic / 0-readme.md
Created December 4, 2012 19:41 — forked from burke/0-readme.md
ruby-1.9.3-p327 cumulative performance patch for rbenv

ruby-1.9.3-p327 cumulative performance patch for rbenv

This installs a patched ruby 1.9.3-p327 with various performance improvements and a backported COW-friendly GC, all courtesy of funny-falcon.

Requirements

You will also need a C Compiler. If you're on Linux, you probably already have one or know how to install one. On OS X, you should install XCode, and brew install autoconf using homebrew.