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 / .bash_profile
Last active September 15, 2020 18:08
Dev box config files
alias ll='ls -lhG'
alias cp='cp -irv'
alias mv='mv -iv'
alias rm='rm -ir'
alias jspec="RAILS_ENV=test bundle exec rake spec:javascript"
alias http="ruby -run -ehttpd . -p8000"
alias dockerclean="docker ps -a | grep Exit | cut -d ' ' -f 1 | xargs docker rm"
alias gitclean="git branch --merged | ack '^(?![\* ] master).+$' | xargs git branch -d"
alias nodev="node -r ./scripts/dev.js"
alias tunnel="forever ssh -vND 1080 -p 443 root@proxy.jmnsf.com"
@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 / 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.
#
@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 / ssh-tunnel-setup.md
Created April 21, 2017 04:55
SSH Tunnel Setup

SSH Tunnel Setup

Use this for protected networks where port 22 isn't available, or for general security reasons where your traffic will be routed through an external server via SSH tunnel.

Server Setup

An EC2 micro instance or a tiny DigitalOcean droplet will work for this. For the initial configuration, access to port 22 is required, as you'll have to SSH onto your host.

In the host, edit /etc/ssh/sshd_config and add the line Port 443. Reboot. From now on you can SSH into the server through port 443 (ssh -p 443 user@server).

Tunnel Setup