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 / prototype_extension_data.js
Created February 10, 2012 23:04
give prototype the .data() method like jQuery
var PrototypeExtensions = {
data: function(elem, key, val) {
var DATA_REGEX = /data-(\w+)/;
var ii = 0;
var nattr = elem.attributes.length;
if (key && val) {
elem.setAttribute('data-' + key, val);
}
else {
for (; ii < nattr; ++ii ) {
@bunnymatic
bunnymatic / io_inspector.ex
Created December 11, 2017 02:12
Elixir Inspector
defmodule Inspector do
def inspector(v,s), do: (IO.puts("[#{s}] #{inspect(v)}"); v)
def inspector(v), do: (IO.puts("[check] #{inspect(v)}"); v)
end
@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 / myproject_s3.rb
Created February 28, 2014 16:28
Build signed read url for s3/aws access outside of the aws-sdk#url_for which doesn't like filenames with w/spaces
module MyProject
class S3
def config
Rails.application.config.s3_config
end
def url_for_read(path, opts)
expire_date = (Time.zone.now + opts[:expires]).to_i
request_string = "GET\n\n\n#{expire_date}\n/#{config[:bucket]}/#{path}"
hmac = OpenSSL::HMAC.digest(digest, config[:secret_access_key], request_string)
module Capybara
class Session
def has_flash?(kind, msg)
within ".alert-#{kind}" do
has_content?(msg)
end
end
end
end
@bunnymatic
bunnymatic / jasmine_json_fixtures.js
Created August 31, 2012 23:40
Jasmine Load JSON fixtures
/**
add ability to load json fixtures into jasmine
**/
var readJsonFixtures = function() {
return jasmine.getJsonFixtures().proxyCallTo_('read', arguments);
};
var preloadJsonFixtures = function() {
jasmine.getJsonFixtures().proxyCallTo_('preload', arguments);
@bunnymatic
bunnymatic / features-support-elasticsearch.rb
Created January 13, 2016 08:41
Elasticsearch test helpers
require_relative "../../spec/support/test_es_server"
require_relative "./webmock"
TestEsServer.start
at_exit do
TestEsServer.stop
end
@bunnymatic
bunnymatic / hot_stuff-1.rb
Last active January 2, 2016 03:49
active_model_conversion blog post assets
# the hot stuff wrapper/presenter
class HotStuff
def items
@items ||= Stuff.hot.limit(5)
end
end
@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