Skip to content

Instantly share code, notes, and snippets.

@avit
avit / .gitconfig
Created September 19, 2018 20:42
Commands to find when a commit was merged
[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 April 28, 2018 23:47
Testing javascript regular expressions using a ruby test suite
require 'therubyracer'
js = V8::Context.new
matches = (<<-___).split("\n---\n")
123
---
abc
___
pattern = DATA.reduce("") { |str, line|
# 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 January 13, 2018 22:04 — forked from haasn/about:config.md
Firefox bullshit removal via about:config

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.

Verifying my Blockstack ID is secured with the address 1MSQ883WpqnGrpFyg62qPGPCiTtK8Bv1c6 https://explorer.blockstack.org/address/1MSQ883WpqnGrpFyg62qPGPCiTtK8Bv1c6
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 15:53
Normalizer to add prefix on root-relative paths
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 April 7, 2016 03:32
Getting ruby Date to respect negative offsets when calculating
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 January 28, 2016 21:24
I hate this about ruby
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]