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 / gist:a78deb0e3274af571916
Created July 9, 2014 15:32
who done it - git blame statistics
Hop into a shell and to the root directory of your project and run
git ls-tree --name-only -z -r HEAD -- $1 | xargs -0 -n1 git blame --line-porcelain | grep "^author "|sort|uniq -c|sort -nr
Then wait a bit. You get a nice sorted list of lines of code and author name.
Add it to your bash profile like this
whodunit() {
git ls-tree --name-only -z -r HEAD -- $1 | xargs -0 -n1 git blame --line-porcelain | grep "^author "|sort|uniq -c|sort -nr
}
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?(c.click(),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(%22.select-menu-list%20.select-menu-item%22).length;null==document.querySelector(%22.js-discussion-sidebar-menu%20.select-menu-header%22).offsetParent&&document.que
@bunnymatic
bunnymatic / .htaccess
Created February 5, 2012 08:40
javascript regex tester
Options -Indexes
@bunnymatic
bunnymatic / pull_request_simple.md
Last active March 9, 2021 15:43
Pull Request Template

Fixes issue(s) # .

Changes proposed in this pull request:

/cc relevant people

@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 / delegators.rb
Created February 27, 2020 16:25
ruby delegator
#!/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
bunnymatic / gist:1648765
Last active February 22, 2020 21:03
compute histogram in ruby
def tally inp; hash = Hash.new(0); inp.each {|k,v| hash[k] +=v}; hash; end
def histogram inp; hash = Hash.new(0); 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}
end
def test_histogram
histogram(['a','b','a','c','a', 'c']) == {'a'=>3, 'b'=>1, 'c'=>2}
@bunnymatic
bunnymatic / lint-fix-on-save.el
Created December 17, 2018 08:21
Emacs routines to auto lint fix (prettier and rubocop) on save
(defun is-ruby-file (f)
(if (string-match "\\.rb$" f)
t
nil
))
(defun is-javascript-file (f)
(if (or
(string-match "\\.jsx?$" f)
(string-match "\\.json$" f))
@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 / info.md
Last active July 11, 2018 15:13
Axios vs Fetch