Skip to content

Instantly share code, notes, and snippets.

@jakejscott
jakejscott / Default (Windows).sublime-keymap
Last active January 28, 2017 18:14
Handmade hero Sublime Text 3 settings
[
{ "keys": ["ctrl+up"], "command": "move", "args": {"by": "stops", "empty_line": true, "forward": false} },
{ "keys": ["ctrl+down"], "command": "move", "args": {"by": "stops", "empty_line": true, "forward": true} }
]
@jakejscott
jakejscott / heap_sort.rs
Created November 7, 2014 03:23
Rust Heap sort ported from Rosetta code Dart example
fn heap_sort<T: Ord>(a: &mut [T]) {
let count:uint = a.len();
// first place 'a' in max-heap order
heapify(a, count);
let mut end = count - 1;
while end > 0 {
// swap the root (maximum value) of the heap with the
// last element of the heap
@jakejscott
jakejscott / bubble_sort.rs
Last active August 29, 2015 14:08
Rust Bubble sort
fn main() {
let mut list = [1u, 5, 2, 7, 3, 9, 4, 6, 8];
bubble_sort(list);
println!("After sort: {}", list.as_slice());
let mut list = ['a', 'z', 'd', 'e', 'x', 'a'];
bubble_sort(list);
println!("After sort: {}", list.as_slice());
}
@jakejscott
jakejscott / quick_sort.rs
Last active August 29, 2015 14:08
Rust quick_sort ported from Rosetta code Dart example
use std::fmt::Show;
fn main() {
println!("After sort: {}", quick_sort(vec!(1u, 5, 2, 7, 3, 9, 4, 6, 8)));
println!("After sort: {}", quick_sort(vec!(1u, 2, 3, 4, 5, 6, 7, 8, 9)));
println!("After sort: {}", quick_sort(vec!(9u, 8, 7, 6, 5, 4, 3, 2, 1)));
}
fn quick_sort<T: Clone + Show + PartialOrd>(a: Vec<T>) -> Vec<T> {
if a.len() <= 1 {
@jakejscott
jakejscott / merge_sort.rs
Last active August 29, 2015 14:08
Merge sort ported from the C# example
fn main() {
let list: Vec<u64> = vec![1, 2, 3, 6, 8, 8, 4, 5, 99, 234, 4, 1, 2, 45];
let sorted = sort(list);
println!("sorted: {}", sorted);
// sorted: [1, 1, 2, 2, 3, 4, 4, 5, 6, 8, 8, 45, 99, 234]
}
fn sort<T: Clone + PartialOrd>(list: Vec<T>) -> Vec<T> {
if list.len() <= 1 {
@jakejscott
jakejscott / merge_sort.rs
Last active August 29, 2015 14:08
merge_sort.rs ported from C
fn main() {
let mut list = vec![9_u64, 12, 3, 1, 6, 8, 2, 5, 14, 13, 11, 7, 10, 4, 0];
println!("Test - Before sort: {}", list);
merge_sort(0, list.len() as u64, &mut list);
println!("Test - After sort: {}", list);
// Test - Before sort: [9, 12, 3, 1, 6, 8, 2, 5, 14, 13, 11, 7, 10, 4, 0]
// Test - After sort: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
}
<link rel="import" href="../core-scaffold/core-scaffold.html">
<link rel="import" href="../core-header-panel/core-header-panel.html">
<link rel="import" href="../core-menu/core-menu.html">
<link rel="import" href="../core-item/core-item.html">
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<link rel="import" href="../core-menu/core-submenu.html">
<polymer-element name="my-element">
@jakejscott
jakejscott / server.go
Created May 20, 2014 00:53
negroni + httprouter
package main
import (
"fmt"
"github.com/codegangsta/negroni"
"github.com/julienschmidt/httprouter"
"net/http"
)
func main() {
@jakejscott
jakejscott / server.go
Created February 12, 2014 07:11
oauth2 martini google
package main
import (
"github.com/codegangsta/martini"
"github.com/martini-contrib/oauth2"
"github.com/martini-contrib/sessions"
)
func main() {
m := martini.Classic()
@jakejscott
jakejscott / elastic-search-completion-suggestor
Created December 5, 2013 02:20
Elastic search completion suggestor (run this in sense)
PUT music
PUT music/song/_mapping
{
"song": {
"properties": {
"name": {
"type": "string"
},
"suggest": {