Skip to content

Instantly share code, notes, and snippets.

@avit
avit / .gitconfig
Created Sep 19, 2018
Commands to find when a commit was merged
View .gitconfig
[alias]
find-merge = "!sh -c 'commit=$0 && branch=${1:-HEAD} && (git rev-list $commit..$branch --ancestry-path | cat -n; git rev-list $commit..$branch --first-parent | cat -n) | sort -k2 -s | uniq -f1 -d | sort -n | tail -1 | cut -f2'"
show-merge = "!sh -c 'merge=$(git find-merge $0 $1) && [ -n \"$merge\" ] && git show $merge'"
@avit
avit / test_js_regex.rb
Created Apr 28, 2018
Testing javascript regular expressions using a ruby test suite
View test_js_regex.rb
require 'therubyracer'
js = V8::Context.new
matches = (<<-___).split("\n---\n")
123
---
abc
___
pattern = DATA.reduce("") { |str, line|
View award_winning_xor.rb
# 0. "trust me it works"
def cancelled_at=(time)
super.tap do
if cancelled_at_change && ((!cancelled_at_change.first) ^ (!cancelled_at_change.last))
time ? self.status_event = "cancel" : self.status_event = "reserve"
end
end
end
@avit
avit / about:config.md
Created Jan 13, 2018 — forked from haasn/about:config.md
Firefox bullshit removal via about:config
View about:config.md

Firefox bullshit removal

Due to the incessant swarm of complete and utter nonsense that has been forcing its way into Firefox over time, I've decided to start collecting my personal list of “must-have” about:config tweaks required to turn Firefox into a functional brower.

NOTE: Unfortunately this is somewhat out of date. The comments link to some resources that may be more up-to-date. Patches welcome.

WebSockets

These can be used for nefarious purposes and to bypass access restrictions.

View gist:9f3e76eee1a476201f0f52837cc05905
Verifying my Blockstack ID is secured with the address 1MSQ883WpqnGrpFyg62qPGPCiTtK8Bv1c6 https://explorer.blockstack.org/address/1MSQ883WpqnGrpFyg62qPGPCiTtK8Bv1c6
View string_pool.rb
strings = Hash.new { |h, k| h[k] = k.freeze }
#=> {}
a = strings["asdf"]
#=> "asdf"
a.object_id
#=> 70266940175600
b = strings["asdf"]
@avit
avit / normalizr.rb
Last active May 9, 2016
Normalizer to add prefix on root-relative paths
View normalizr.rb
Normalizr.configure do |config|
# Match root-relative paths that begin with a leading slash
#
# (/path/to/image.jpg) in CSS url(/...)
# "/path/to/image.jpg" in HTML src="/..."
# '/path/to/image.jpg' in HTML src='/...'
#
# The contents of the parentheses or quotes are captured as matches that can
# be prefixed with a hostname for absolute URLs.
#
@avit
avit / anchored_date.rb
Created Apr 7, 2016
Getting ruby Date to respect negative offsets when calculating
View anchored_date.rb
require 'delegate'
require 'date'
class AnchoredDate < Delegator
def initialize year, month=1, day=1
case year
when Fixnum
@year = year
@month = month
@day = day
@avit
avit / proc_vs_lambda.rb
Created Jan 28, 2016
I hate this about ruby
View proc_vs_lambda.rb
lm = lambda { |things, *options| puts things.inspect, options.inspect }
pr = proc { |things, *options| puts things.inspect, options.inspect }
lm.call([1,2], 'a') #=> [1, 2], ["a"]
pr.call([1,2], 'a') #=> [1, 2], ["a"]
lm.call([1,2]) #=> [1, 2], []
pr.call([1,2]) #=> 1, [2]
View photo_carousel.js