Skip to content

Instantly share code, notes, and snippets.

View montanaflynn's full-sized avatar

Montana Flynn montanaflynn

View GitHub Profile
@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 / colors.html
Last active February 27, 2016 04:41
GitHub language color generator - http://goo.gl/fyj3hk
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="https://cdn.rawgit.com/jeremyfa/yaml.js/develop/dist/yaml.min.js"></script>
<script src="https://cdn.rawgit.com/Fooidge/PleaseJS/master/dist/Please.js"></script>
<meta charset="utf-8">
<style>
a {
font: 16px sans-serif;
@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 / setup.sh
Last active July 26, 2017 00:11
Shell script to setup OSX yosemite
#!/usr/bin/env bash
# Ask for sudo up front
echo "Some steps require sudo so please enter your password"
sudo -v
# Check for and install developer tools
xcode-select -p
if [ $? -ne 0 ]; then
# Install dev tools
@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
@montanaflynn
montanaflynn / easyget.go
Last active September 12, 2020 17:44
GET JSON array in Golang
package easyget
import (
"io"
"io/ioutil"
"net/http"
)
// Define Request struct
type Request struct {
@montanaflynn
montanaflynn / functional.js
Last active August 29, 2015 14:09
Filter, Map and Reduce data in JS
// data format in JSON is just array of objects
var data = [{"a":5,"b":24},{"a":11,"b":72},{"a":20,"b":100},{"a":50,"b":257}]
// filter object key a > 10
filtered = data.filter(function(datum){
// returning true keeps the object in array
if (datum.a > 10) return true
})