Skip to content

Instantly share code, notes, and snippets.

View JohnMurray's full-sized avatar

John Murray JohnMurray

View GitHub Profile
@JohnMurray
JohnMurray / URL-1.txt
Created August 19, 2012 18:54
Versioning WCF Web APIs Blog Post (http://goo.gl/PkCVc)
http://api.mysite.com/UserInfo/<MethodName>
http://api.mysite.com/CarInfo/<MethodName>
@JohnMurray
JohnMurray / det.rb
Created August 19, 2012 20:03
Geofencing (part 2) Blog Post
# Get the determinant of a line and a point. This is conceptually
# represented by the following:
#
# point = (a,b)
# line = [(x1, y1), (x2, y2)], such that y2 > y1
#
# matrix:
# | (x2 - x1) (a-x1) |
# | (y2 - y1) (b-y1) |
#
@JohnMurray
JohnMurray / compiling-rust.sh
Created September 29, 2012 20:06
gist for blog entry on johnmurray.io
# get all of the necessary tools to build
sudo yum install gcc-c++ llvm llvm-devel perl wget
# following rust-lang.org's instructions
wget http://dl.rust-lang.org/dist/rust-0.3.tar.gz
tar -xzf rust-0.3.tar.gz
cd rust-0.3
./configure
make -j 4 && make install
@JohnMurray
JohnMurray / test.rs
Last active December 12, 2015 10:39
simple rust program
struct MyStruct {
mut count : int
}
impl MyStruct {
fn inc(&mut self) -> () { (*self).count += 1; }
}
fn main() -> () {
let STAT : MyStruct = MyStruct { count: 1 };
@JohnMurray
JohnMurray / after.php
Last active December 14, 2015 19:49
gists for blog post on Pinatra (PHP Sinatra clone) as a tool for learning
Pinatra::after('*', function () {
Logger::log_request('served yet another request');
});
struct Bob {
priv name : ~str,
priv age : int
}
impl Bob {
fn new(name: ~str, age: int) -> Bob {
Bob { name: name, age: age }
}
@JohnMurray
JohnMurray / string-reverse.js
Created April 12, 2013 23:49
Explanation of JS string reversal
var str = "hello world";
// Split on the empty character (between every
// letter).
var str_split = str.split(''); // => ['h', 'e', 'l', 'l', ' ', 'w', 'o', 'r', 'l', 'd']
// reverse the resulting array
var str_reverse = str_split.reverse(); // => ['d', 'l', 'r', 'o', 'w', ' ', 'l', 'l', 'e', 'h']
// join each string in the array, delimited by
@JohnMurray
JohnMurray / array.rs
Last active December 16, 2015 18:09
Question for Rust IRC
/*
* Question: should this be the correct way to initialize a new vector
* with a set capacity? Seems al little verbose.
*/
fn main() -> () {
let mut a : ~[int] = ~[];
vec::reserve(&mut a, 20);
}
@JohnMurray
JohnMurray / array_alloc.rs
Created April 28, 2013 06:22
Question for Rust IRC
fn main() -> () {
let a : ~[int] = vec::with_capacity(20);
a[0] = 1; // rust: task failed at 'index out of bounds: the len is 0 but the index is 0'
}
// Initialize API key, session, and token...
// Think of a session as a room, and a token as the key to get in to the room
// Sessions and tokens are generated on your server and passed down to the client
var apiKey = "1127";
var sessionId = "1_MX4xMTI3fn5TYXQgTWF5IDA0IDA3OjIwOjAzIFBEVCAyMDEzfjAuNDQwODI4MTR-";
var token = "T1==cGFydG5lcl9pZD0xMTI3JnNpZz1jZjRhYzc3OWI5MGNkMzBkMGUyOGZmN2UxMTRjZDlmNDAxY2FiN2VlOnNlc3Npb25faWQ9MV9NWDR4TVRJM2ZuNVRZWFFnVFdGNUlEQTBJREEzT2pJd09qQXpJRkJFVkNBeU1ERXpmakF1TkRRd09ESTRNVFItJmNyZWF0ZV90aW1lPTEzNjc2NzcyMDMmbm9uY2U9MTk1MDcyJnJvbGU9cHVibGlzaGVy";
// Enable console logs for debugging
TB.setLogLevel(TB.DEBUG);