Skip to content

Instantly share code, notes, and snippets.

View dghubble's full-sized avatar

Dalton Hubble dghubble

View GitHub Profile
@dghubble
dghubble / create.js
Created October 6, 2012 03:47 — forked from davidaurelio/create.js
Constructor-less inheritance for ECMAScript 5
var BaseObject = {
create: function create() {
var instance = Object.create(this);
instance._construct.apply(instance, arguments);
return instance;
},
extend: function extend(properties, propertyDescriptors) {
propertyDescriptors = propertyDescriptors || {};
@dghubble
dghubble / geodist.py
Created October 15, 2012 06:23
Collection of useful distance calculation functions for the earth
# A collection of useful distance calculation functions for the earth
from __future__ import division
from math import sin, cos, acos, asin, radians, degrees, sqrt
EARTH_RADIUS = 6371009 # meters
class Geolocation(object):
def __init__(self, latitude, longitude):
self.latitude = latitude # Restrict to be within -90 and 90
@dghubble
dghubble / go.sh
Last active September 29, 2016 19:01
Script to install Go 1.0.3 and setup development environment.
cd ~
wget http://go.googlecode.com/files/go1.0.3.linux-amd64.tar.gz
tar -zxvf go1.0.3.linux-amd64.tar.gz
rm go1.0.3.linux-amd64.tar.gz
# binary distributions assume they will be installed at /usr/local/go
# Otherwise, you must set the GOROOT environment variable
sudo mv ~/go /usr/local
echo "export PATH=$PATH:/usr/local/go/bin" >> ~/.bashrc
mkdir -p ~/Workspace/go-workspace
mkdir -p $HOME/Workspace/go-workspace/src
# OS X Homebrew (Package Manager) Setup
# Assumes:
# + GCC installed via XCode comamnd line tools (https://connect.apple.com)
# Install latest Homebrew release (0.9.4 as of July 6, 2013)
###############################################################################
# Homebrew placed under '/usr/local' so package installs don't require sudo.
# Individual brew packages (kegs) isolated in their own directory under
# '/usr/local/Cellar'
@dghubble
dghubble / country_adjectivals.js
Last active December 24, 2015 12:59
Country to Adjectival Mapping
var country_to_adjectival = {
"Afghanistan": "Afghan",
"Albania": "Albanian",
"Algeria": "Algerian",
"Angola": "Angolan",
"Antigua": "Antiguan",
"Barbuda": "Antiguan",
"Argentina": "Argentine",
"Armenia": "Armenian",
"Australia": "Australian",
@dghubble
dghubble / echoer.thrift
Created November 21, 2013 18:27
Thrift Interface Definition for Echoer Service
struct EchoArgs {
1: required string Message
}
struct EchoReply {
1: required string Echo
}
struct MultiplyArgs {
@dghubble
dghubble / echoer.go
Last active December 29, 2015 00:38
Echoer generated Go code (go-thrift with -go.rpcstyle=true option)
// This file is automatically generated. Do not modify.
package echoer_thrift
type EchoArgs struct {
Message string `thrift:"1,required" json:"Message"`
}
type EchoReply struct {
Echo string `thrift:"1,required" json:"Echo"`
@dghubble
dghubble / stringToLong.scala
Last active June 15, 2018 13:49
Scala String to Long check via regex vs cast
def time[A](a: => A) = {
val now = System.nanoTime
val result = a
val micros = (System.nanoTime - now) / 1000
println("%d microseconds".format(micros))
result
}
def validIdByRegex(id: String): Boolean = {
val idPattern = """[0-9]+""".r
#!/bin/sh
OSX_VERS=$(sw_vers -productVersion | awk -F "." '{print $2}')
# Get Xcode CLI tools
# https://devimages.apple.com.edgekey.net/downloads/xcode/simulators/index-3905972D-B609-49CE-8D06-51ADC78E07BC.dvtdownloadableindex
TOOLS=clitools.dmg
if [ ! -f "$TOOLS" ]; then
if [ "$OSX_VERS" -eq 7 ]; then
DMGURL=http://devimages.apple.com/downloads/xcode/command_line_tools_for_xcode_os_x_lion_april_2013.dmg
elif [ "$OSX_VERS" -eq 8 ]; then
@dghubble
dghubble / .gitignore
Created April 19, 2014 07:03
Android Gitignore
# Gradle Files
.gradle
.m2
.gradletasknamecache
# Build output directories and files
target/
build/
Version.java
logcat.txt