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 / gulpfile.js
Last active January 9, 2017 07:05
Jade / Stylus Gulpfile with an express static server and livereload enabled.
var sources, destinations, lr, gulp, gutil, jade, stylus;
gulp = require('gulp');
jade = require('gulp-jade');
gutil = require('gulp-util');
stylus = require('gulp-stylus');
sources = {
jade: "jade/**/*.jade",
stylus: "stylus/**/*.stylus",
@montanaflynn
montanaflynn / md5-benchmarks.js
Last active March 18, 2016 00:40
Testing different packages MD5 hashing performance in node.js
var mhash = require("mhash").hash
var md5 = require("md5")
var crypto = require('crypto')
var packages = ['mhash','md5','crypto']
md5benchmark(packages)
function md5benchmark(packages) {
var max = 100000
@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 / calculator.js
Created August 24, 2014 07:35
Simple calculator in javascript
function Calculator(num){
return {
answer : num ? num : 0,
equals : function() {
return this.answer
},
add : function(num) {
this.answer += num ? num : 1
return this
},
@montanaflynn
montanaflynn / boss.js
Last active August 7, 2016 02:54
Parallel cpu node
// The magic module that makes this all possible
var cluster = require('cluster')
// Boss gets everyone to work
if (cluster.isMaster) {
// The crew made of worker threads
var crew = []
// The state of the job to pass between boss and workers
@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 / fortune.fish
Created October 3, 2014 15:45
Fun with fish and fortunes
# place this in your fish path
# ~/.config/fish/config.fish
function fish_greeting
if not type fortune > /dev/null 2>&1
apt-get install fortune
end
fortune -a
end
@montanaflynn
montanaflynn / check_for_dependencies.sh
Last active January 23, 2023 13:39
Checking for dependencies in a shell script
# Easy way to check for dependencies
checkfor () {
command -v $1 >/dev/null 2>&1 || {
echo >&2 "$1 required";
exit 1;
}
}
checkfor "ffmpeg"
@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