Skip to content

Instantly share code, notes, and snippets.

writing computer programs

Mr Rogers bunnymatic

writing computer programs
View GitHub Profile
View gist:08511901cebee502c81faf4604a78dd2
Create bookmark and drop this in the URL field
javascript:!function(){let e,t=["kevinhyunilkim","rhkwong","yingyingchoi","t3ly","roger-mo-gusto","julieqdchen-gusto","Lizard381","jaguar1014"];function n(){if(t.length>0){const e=t.shift();document.getElementById("review-filter-field").value=e,document.getElementById("review-filter-field").dispatchEvent(new Event("focus"));let i=0;const s=function(){let t=document.querySelectorAll(".filterable-active .select-menu-item"),c=null;t.forEach(function(t){-1!==t.textContent.toLowerCase().indexOf(e.toLowerCase())&&(c=t)}),c?(,setTimeout(n,200)):i%3E8?setTimeout(n,200):(i++,setTimeout(s,500))};s()}else%20document.querySelectorAll(%22.sidebar-assignee.js-discussion-sidebar-item%20summary%22)[0].click(),e.parentNode.removeChild(e)}function%20i(){const%20e=function(){const%20t=document.querySelectorAll(;null==document.querySelector(
bunnymatic / .htaccess
Created Feb 5, 2012
javascript regex tester
View .htaccess
Options -Indexes

Fixes issue(s) # .

Changes proposed in this pull request:

/cc relevant people

bunnymatic / custom_array_matchers.rb
Last active Jul 3, 2020
RSpec Matchers for increasing/decreasing array tests. Useful when sort may not be the easiest way to do things.
View custom_array_matchers.rb
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}
failure_message_for_should do |actual|
"expected array #{actual.inspect} to be monotonically increasing"
View delegators.rb
#!/usr/bin/env ruby
# require 'pry'
# require 'byebug'
module DelegateMe
def delegate_methods(methods, to:)
[methods].flatten.each do |method_name|
define_method method_name do |*arg, &block|
base = send(to)
bunnymatic / gist:1648765
Last active Feb 22, 2020
compute histogram in ruby
View gist:1648765
def tally inp; hash =; inp.each {|k,v| hash[k] +=v}; hash; end
def histogram inp; hash =; inp.each {|v| hash[v]+=1}; hash; end
def histogram2 inp; Hash[*inp.group_by{ |v| v }.flat_map{ |k, v| [k, v.size] }] end
def test_tally
tally([['a',1],['b',1],['a',1],['c',1],['a',3], ['c',1]]) == {'a'=>5, 'b'=>1, 'c'=>2}
def test_histogram
histogram(['a','b','a','c','a', 'c']) == {'a'=>3, 'b'=>1, 'c'=>2}
bunnymatic / lint-fix-on-save.el
Created Dec 17, 2018
Emacs routines to auto lint fix (prettier and rubocop) on save
View lint-fix-on-save.el
(defun is-ruby-file (f)
(if (string-match "\\.rb$" f)
(defun is-javascript-file (f)
(if (or
(string-match "\\.jsx?$" f)
(string-match "\\.json$" f))
bunnymatic / nested_content_snippet.rb
Created Dec 6, 2012
nested content in rails view helpers
View nested_content_snippet.rb
# 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 /
Last active Jul 11, 2018
Axios vs Fetch
bunnymatic / prototype_extension_data.js
Created Feb 10, 2012
give prototype the .data() method like jQuery
View prototype_extension_data.js
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 ) {