Skip to content

Instantly share code, notes, and snippets.

View montanaflynn's full-sized avatar

Montana Flynn montanaflynn

View GitHub Profile
curl --include --request POST 'https://shippo.p.mashape.com/addresses/' \
--header "X-Mashape-Authorization: <mashape-key>" \
--user "<username>:<password>" \
@montanaflynn
montanaflynn / predict.js
Created August 22, 2014 15:23
Predict the future with javascript
var predictions = predict(913,new Date())
console.log(predictions)
function predict(count,date) {
var timestamp = date.getTime()
var y = date.getFullYear(), m = date.getMonth(), d = date.getDate()
var beginningOfDay = new Date(y, m, d).getTime()
var endOfDay = new Date(y, m, d+1).getTime()
var pacePerDay = count / (timestamp - beginningOfDay)
@montanaflynn
montanaflynn / minimal.fish
Last active August 29, 2015 14:07
Remove noise from the terminal
#!/usr/bin/env fish
# Ubuntu Message of The Day
if test -f /etc/update-motd.d/*
chmod -x /etc/update-motd.d/*
end
# Fish Shell Greeting
set line1 "# Don't Show Fish Greeting"
set line2 "set --erase fish_greeting"
@montanaflynn
montanaflynn / datacommands
Last active August 29, 2015 14:07
Most popular U.S. first names by year (source: http://www.ssa.gov/oact/babynames/top5names.html)
Here is a few examples how you can play with the data
# get the data, saving as names.tsv in current working directory
curl -o names.tsv https://gist.githubusercontent.com/montanaflynn/d5c882ad680f94b972f6/raw/1d3ecfb6dae48e119961fe299062a21c0c3ae1ab/names.tsv
# convert tsv to csv
cat names.tsv | tr "\\t" "," > names.csv
# print the most post popular girls name throughout all the years
cat names.tsv | tail -n +2 | awk '{print $2}' | sort | uniq -c | sort -nr
@montanaflynn
montanaflynn / mongo-csv-export.sh
Last active August 29, 2015 14:07
MongoDB CSV export
# mongo export all users who have an email and are not hellbanned
# take special notice that --query is in quotes and is valid JSON
# also that --fields is also wrapped with quotes and is comma seperated
mongoexport --db appname --collection users \
--query '{ "$and" : [ { "email" : { "$ne" : "" } }, { "role" : { "$ne" : 666 } } ] }' \
--csv --fields 'username, email' --out ./user-emails.csv
@montanaflynn
montanaflynn / client.js
Last active August 29, 2015 14:07
Latency Headers PoC
var unirest = require('unirest')
// This is the starting timestamp of when the request was sent
var requestSent = new Date().getTime()
unirest
.get('http://localhost:1337/')
.end(function(res){
if (res.status === 200) {
@montanaflynn
montanaflynn / os.js
Created October 21, 2014 11:18
Node.js host operating system info
var os = require('os')
var response = {}
for (property in os) {
if (typeof os[property] === 'function') {
response[property] = os[property]()
} else {
response[property] = os[property]
}
@montanaflynn
montanaflynn / fancydate.js
Last active August 29, 2015 14:08
Humanize dates in vanilla JavaScript
console.log(fancyDate(556095600000))
// August 16th, 1987
function fancyDate(input) {
var input = new Date(input)
var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
var monthName = monthNames[input.getMonth()]
var day = input.getDate()
@montanaflynn
montanaflynn / Palindromes
Last active August 29, 2015 14:08
Find palindromes in the OSX / Linux dictionary
## MOVED REPOS: https://github.com/montanaflynn/palindromes ##
Learning exercise by writing the same program in multiple languages. The
time results below are the best out of ten runs, optimizations welcome!
Rust 0.12.0: 0.03s user 0.00s system 95% cpu 0.036 total
Clang 600.0.51: 0.04s user 0.00s system 96% cpu 0.039 total
GO 1.3.1: 0.11s user 0.01s system 101% cpu 0.112 total
Ruby 2.0.0: 0.15s user 0.01s system 99% cpu 0.154 total
Haskell 7.8.3: 0.20s user 0.01s system 99% cpu 0.211 total
@montanaflynn
montanaflynn / http-methods.md
Last active August 29, 2015 14:08
HTTP methods