Skip to content

Instantly share code, notes, and snippets.

View colindean's full-sized avatar
🏆
Helping others find happiness and serenity

Colin Dean colindean

🏆
Helping others find happiness and serenity
View GitHub Profile
@colindean
colindean / get_scala.sh
Last active August 29, 2015 14:06
Installs Scala from the official download site
#!/bin/bash
# quickly run this by executing this:
#
# curl -sSL https://gist.githubusercontent.com/colindean/335f5f55073462b114f3/raw/get_scala.sh | sudo bash -s
if [ -z "$1" ]; then
VERSION="2.11.6"
else
VERSION="$1"
@colindean
colindean / bench_hash.rb
Last active August 29, 2015 14:06
Benchmarking ways to join the key and value of a hash
require 'benchmark'
def h
{"header" => "value", "header2" => "value2"}
end
n = 50_000
Benchmark.bm(20) do |x|
x.report("split interpolation") { n.times {h.collect{|k,v| "#{k}:#{v}"} }}
x.report("split array.join") { n.times {h.collect{|k,v| [k,v].join(':')} }}
x.report("split string cat +") { n.times {h.collect{|k,v| k+':'+v} }}
@colindean
colindean / phoenix.js
Created November 6, 2014 19:29
My Phoenix config. Use Mjolnir instead.
var mash = ["cmd", "alt", "ctrl"];
var mashShift = ["cmd", "alt", "shift"];
var MARGIN_X = 5;
var MARGIN_Y = 5;
var GRID_WIDTH = 4;
Window.prototype.getGrid = function() {
var winFrame = this.frame();
var screenRect = this.screen().frameWithoutDockOrMenu();
@colindean
colindean / arrayhashset_benchmark.rb
Created November 24, 2014 00:35
A simple benchmark of array v hash v set in Ruby
require 'benchmark'
require 'set'
ranges = [ "a".."z", "A".."Z", 0..9 ]
n = ARGV[0].to_i || 100
Benchmark.bm do |x|
#array
x.report "array" do
n.times do
@colindean
colindean / arrayhashset_benchmark.rb
Created November 24, 2014 00:35
A simple benchmark of array v hash v set in Ruby
require 'benchmark'
require 'set'
ranges = [ "a".."z", "A".."Z", 0..9 ]
n = ARGV[0].to_i || 100
Benchmark.bm do |x|
#array
x.report "array" do
n.times do
@colindean
colindean / light.rb
Last active August 29, 2015 14:12 — forked from Bunkerbewohner/light
A simple Ruby shell script to control LIFX (http://lifx.co) light bulbs, adds color support
#!/usr/bin/env ruby
require 'lifx'
available_colors = LIFX::Colors.instance_methods
if ARGV.length > 0
# see if a specific lamp is addressed
label = /^on|off|0x[0-9a-f]{6}$/.match(ARGV[0]) || available_colors.member?(ARGV[0]) ? nil : ARGV[0]
@colindean
colindean / ssh-tester.py
Last active August 29, 2015 14:14
A simple tester of the Secure Secure Shell article recommendations
#!/usr/bin/env python3 -O
import argparse
import subprocess
import sys
def usage():
print("%s target_host target_port" % sys.argv[0])
if len(sys.argv) < 3:
sealed trait Angle { val degrees: Int }
private final case object Perpendicular extends Angle { val degrees = 90 }
private final case object Straight extends Angle { val degrees = 180 }
private final case class Acute(degrees: Int) extends Angle
private final case class Obtuse(degrees: Int) extends Angle
private final case class Reflex(degrees: Int) extends Angle
object Angle {
def apply(degrees: Int): Either[String,Angle] = degrees match {
case _ if degrees == 90 ⇒
Right(Perpendicular)
@colindean
colindean / steam-win32.rb
Created May 1, 2015 22:07
A half-attempt at a Ruby library for getting Steam information from the Windows registry.
# warning: this was never tested.
# license: cc0
require 'win32/registry'
module SteamR; module Registry
STEAM_HKEY_ROOT = 'SOFTWARE\Valve\Steam'
HKEYS = {
@colindean
colindean / NodeId.scala
Last active August 29, 2015 14:21
AnyVal with subclasses
class NodeId(val id: Int)
case class DocumentId(override val id: Int) extends NodeId(id)
case class ContainerId(override val id: Int) extends NodeId(id)
case class UserId(override val id: Int) extends NodeId(id)
// how can I get DocumentId, ContainerId, and UserId to be a NodeId and still extend AnyVal?
// this seems to work: