Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am jmnsf on github.
  • I am jmnsf (https://keybase.io/jmnsf) on keybase.
  • I have a public key whose fingerprint is CE79 517D FC44 351A 723F 7E49 8848 D447 4094 8B88

To claim this, I am signing this object:

@jmnsf
jmnsf / gist:d1478bbe085f06ae6ed2
Created April 30, 2015 15:49
Liquid Aliasing Endpoint

Endpoint: POST /collect/aliases

Request Headers:

Key Value
"Authorization" "Token " + token
"Accept" "application/vnd.lqd.v1+json"
"Content-Type" "application/json"
@jmnsf
jmnsf / mongo_daily_retention.rb
Created September 28, 2015 15:04
Second and Third day retention calculator from seen_at and first_seen_at in MongoDB Aggregation FW
User.disk_aggregate([
{ '$match' => { '$and' => [
{ 'attrs.first_seen_at' => { '$gte' => DateTime.parse('2015-06-01') } },
{ 'attrs.first_seen_at' => { '$lte' => DateTime.parse('2015-06-30 23:59') } }] } },
{ '$project' => {
days_seen_at: { '$map'=> {
input: '$attrs.seen_at',
as: 'date',
in: { '$dayOfYear' => '$$date' } } },
fsa: { '$dayOfYear' => '$attrs.first_seen_at' },
ptSalary :: (Ord a, Fractional a) => a -> a
ptSalary yearly =
let levels = [((0, 7000), 0.145), ((7001, 20000), 0.285), ((20001, 40000), 0.37), ((40001, 80000), 0.45), ((80001, 250000), 0.505)]
leftVal el = fst . fst $ el
rightVal el = snd . fst $ el
pct el = snd el
reducer sal el = sal - (min (rightVal el - leftVal el) (yearly - leftVal el)) * pct el
validLevels levels = takeWhile ((< yearly) . leftVal) levels
in foldl reducer yearly (validLevels levels)
@jmnsf
jmnsf / AfterEachEs6.sublime-snippet
Last active February 10, 2016 15:46
Sublime Text 2 Snippets
<snippet>
<content><![CDATA[
afterEach((${1:args}) => ${2:{}});
]]></content>
<tabTrigger>aea</tabTrigger>
<scope>source.js</scope>
<description>ES 6 afterEach </description>
</snippet>
@jmnsf
jmnsf / 2016_table.txt
Last active April 1, 2016 13:44
Calculate Portuguese TAX in Google Sheets
Echelon Tax Overtax
€7,000.00 0.145 0
€20,000.00 0.285 0.01
€40,000.00 0.37 0.0175
€80,000.00 0.45 0.03
€99,999,999,999.00 0.48 0.035
@jmnsf
jmnsf / marvin-annotations.rb
Last active March 19, 2017 03:43
Extract annotations from Marvin 2.0
require 'nokogiri'
if ARGV.length != 1
puts "Usage:\n$ ruby marvin-annotations.rb <path-to-library.mrvi>"
exit
end
def extract_highlights(book)
min_ts = 3000000000 # very large
max_ts = 0
@jmnsf
jmnsf / forever.sh
Created April 22, 2017 12:30
Keep any command running forever
#!/bin/sh
# Reruns any command when it exits.
while :
do
eval $@
echo "Died... Re-running in 1 second."
sleep 1
done
@jmnsf
jmnsf / retry.sh
Created August 15, 2018 12:09
Rerun any command that exists with non-zero status.
#!/bin/sh
# Reruns any command when it exits with non-zero status.
while :
do
if eval $@ ; then
break
fi
echo "Died... Re-trying in 1 second."
@jmnsf
jmnsf / clean-git.rb
Last active March 2, 2020 12:31
Clean Git Branches
# @author jmnsf
#
# This script attempts to clean the local repository of stale branches. This
# goes in a few steps:
#
# 0. Fetch with `-p` is run to remove references to deleted remote branches.
# 1. Merged branches are removed (except for `master`).
# 2. Branches with no conflicts or changes vs `master` are removed.
# 3. Branches that have the same head as a merged PR in GitHub will be merged.
#