Skip to content

Instantly share code, notes, and snippets.

View JohnMurray's full-sized avatar

John Murray JohnMurray

View GitHub Profile
@JohnMurray
JohnMurray / .travis.yml
Last active August 29, 2015 14:00
Code snippets for scala-project blog post on www.johnmurray.io
language: scala
scala:
- 2.10.3
script:
- sbt compile test:compile
- sbt scalastyle
- sbt test
jdk:
- oraclejdk7
- openjdk7
@JohnMurray
JohnMurray / set.scala
Created October 28, 2014 17:34
Extract from BuiltinCommands object in SBT
def set = Command(SetCommand, setBrief, setDetailed)(setParser) {
case (s, (all, arg)) =>
val extracted = Project extract s
import extracted._
val dslVals = extracted.currentUnit.unit.definitions.dslDefinitions
// TODO - This is possibly inefficient (or stupid). We should try to only attach the
// classloader + imports NEEDED to compile the set command, rather than
// just ALL of them.
val ims = (imports(extracted) ++ dslVals.imports.map(i => (i, -1)))
val cl = dslVals.classloader(currentLoader)
@JohnMurray
JohnMurray / load-keyboard
Created February 20, 2012 12:35
Enable Mac OS X Keyboard (built-in only)
#!/bin/bash
# Load the keyboard back. (Should probably do this
# while the external one is still attached.)
sudo kextload /System/Library/Extensions/AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext/
package trees
object Main extends App {
trait Node
case class InnerTreeNode ( left:Node, right:Node, value:Int ) extends Node
case object StopNode extends Node
def leaf(x: Int): Node = InnerTreeNode(StopNode, StopNode, x)
@JohnMurray
JohnMurray / repetitive_pry_session.rb
Created May 31, 2012 15:35
An example of what a repetitive Pry session _might_ look like
require 'bundler/setup'
bundler.require(:development, :test, :console)
$: << File.expand_path('../src', __FILE__)
require 'app'
require 'models/user_account'
require 'models/car'
# Load config and connect to DB
App.init()
@JohnMurray
JohnMurray / console.rb
Created May 31, 2012 15:41
An example console from my geofence-server-example project
#!/usr/bin/env ruby
# require all the necessary files
$: << ::File.expand_path('../src', __FILE__)
require 'app'
require 'geofence'
# at this point bundler should be setup and the :development group
# should have been included. However, just to be sure, I'm going to
# include bundler again and require the console group.
@JohnMurray
JohnMurray / Dictionary.ToJson.cs
Created June 1, 2012 03:03
Code descriptions for log-entry on API Anti-Patterns (johnmurray.io)
public static class IDictionaryExtension
{
public static JsonDictionary<K, V> ToJsonDictionary<K,V>(this IDictionary<K, V> dict)
{
if (dict == null)
return null;
var jsonDict = new JsonDictionary<K, V>();
foreach (var key in dict.Keys)
{
jsonDict[key] = dict[key];
@JohnMurray
JohnMurray / CheckResponse.cs
Created June 4, 2012 00:03
Code descriptions for log-entry on API Anti-Patterns (johnmurray.io)
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
var statusCode = response.StatusCode;
return statusCode == HttpStatusCode.OK;
@JohnMurray
JohnMurray / how_to.md
Created June 12, 2012 18:24
A getting started guide to making requests to my sample geofence-server

John Murray's Sample Geofence Server

Hey, you ran the project! Good for you! You're probably wondering how the heck to use this thing. Well, keep reading and maybe you'll find out.

Pre-Requisites

  1. Install and run Mongo (on default port w/o a password)
  2. Install Gemset with Bundler
  3. Get the server running. (Hey look! You're ahead of the game!)

That's it... keep reading.

@JohnMurray
JohnMurray / ex.sql
Created July 5, 2012 11:56
Link Multi-Where
select *
from (
select *
from carModels as t1,
carMakes as t2
where t1.somePKId = t2.someFKId
and (
t1.Name like '%c%'
or t2.Name like '%c%'
)