Skip to content

Instantly share code, notes, and snippets.

View tmlbl's full-sized avatar

Tim tmlbl

View GitHub Profile
@tmlbl
tmlbl / hash.js
Created May 9, 2014 05:38
Simple hash function in JavaScript
String.prototype.hashCode = function(){
var hash = 0;
if (this.length == 0) return hash;
for (i = 0; i < this.length; i++) {
char = this.charCodeAt(i);
hash = ((hash<<5)-hash)+char;
hash = hash & hash; // Convert to 32bit integer
}
return hash;
}
@tmlbl
tmlbl / fig.go
Created September 13, 2014 23:46
Basic implementation of fig syntax
// Implements fig syntax.
package main
import (
"gopkg.in/yaml.v1"
"io/ioutil"
"log"
)
var metaConfig MetaConfig
@tmlbl
tmlbl / runner.js
Last active January 23, 2020 19:52
Asynchronous test runner
module.exports = Runner;
function Runner() {
this.stack = [];
this.passed = 0;
this.failed = 0;
}
Runner.prototype.it = function (msg, test) {
this.stack.push(new Test(msg, test));
@tmlbl
tmlbl / util.sh
Created November 8, 2014 20:27
Task runner utilities fr JS project
#!/bin/bash
# Run in mock production mode with docker
dockerEnv() {
mkdir -p images;
printf "Starting the mongodb container...\n";
docker run -d --name="spacedb" beshippable/dbbase;
printf "Starting the application container...\n";
docker run -v $(pwd):/app -p 8080:8080 -v $(pwd)/images:/img \
--name="spacecam" -e NODE_ENV=prod --link spacedb:db \
@tmlbl
tmlbl / montha.go
Created December 8, 2014 08:19
How to get time in past in Golang https://play.golang.org/p/ROTLEXldq4
package main
import (
"fmt"
"time"
)
func main() {
now := time.Now()
oneMonthAgo := time.Unix(now.Unix() - (60 * 60 * 24 * 30), 0)
@tmlbl
tmlbl / output.txt
Last active August 29, 2015 14:14
Parsing Neighborhood Information from Zillow
[ { title: 'Makin\' It Singles',
name: 'Upper-scale urban singles.',
description: 'Pre-middle-age to middle-age singles with upper-scale incomes. May or may not own their own home. Most have college educations and are employed in mid-management professions.' },
{ title: 'Aspiring Urbanites',
name: 'Urban singles with moderate income.',
description: 'Low- to middle-income singles over a wide age range. Some have a college education. They work in a variety of occupations, including some management-level positions.' },
{ title: 'Bright Lights, Big City',
name: 'Very mobile singles living in the city.',
description: 'Singles ranging in age from early 20s to mid-40s who have moved to an urban setting. Most rent their apartment or condo. Some have a college education and work in services and the professional sector.' } ]
@tmlbl
tmlbl / xmlToJs.js
Last active August 29, 2015 14:14
xmltojs
// My attempt to make David Walsh's xmlToJson function work
// with libxmltojs. This reproduces the document tree but not
// the text inside in each node. There is a lot of data in these
// documents we are not using... I think we should stick to the
// xpath queries.
// Changes XML to JSON
function xmlToJson (xml) {
// Create the return object
var obj = {};
@tmlbl
tmlbl / Qstring.jl
Last active August 29, 2015 14:16
Basic query string encoder in Julia
using HttpCommon
using Dates
# Creating a query string that will encode unix datetimes
# given Julia DateTimes. Methods to handle more types could
# easily be added.
function qstring(kv::Tuple...)
encodeval(v::String) = encodeURI(v)
encodeval(dt::DateTime) = string(int64(datetime2unix(dt)))
encodepair(p::Tuple) = string(encodeval(p[1]), "=", encodeval(p[2]), "&")
@tmlbl
tmlbl / testexec.sh
Created February 26, 2015 17:42
Bash script to check for required executables
#!/bin/bash
test_exec() {
echo -e "Checking for command: \e[34m$1\e[0m"
EX=$(which $1)
if [[ ! "$EX" ]]; then
echo -e "\e[31mUh oh! It looks like you need to install $1:"
echo -e "$2\e[0m"
exit 1
else
@tmlbl
tmlbl / yesno.sh
Last active August 29, 2015 14:16
A "Standard Library"-Style Function for Bash
#!/bin/bash
# Asks the user a yes or no question, returning the boolean result
# $1: Message message to print
# $2: Default answer (defaults to "no" (1))
std_askyesno() {
local CONF="y/N"
if [[ $2 == 0 ]]; then local CONF="Y/n"; fi
local reply="n"
read -p "$1 $CONF " -n 1 -r reply