Skip to content

Instantly share code, notes, and snippets.

View dmgarland's full-sized avatar

Dan Garland dmgarland

View GitHub Profile
@dmgarland
dmgarland / gist
Created March 10, 2014 10:57
Marshal the whole key?
url = "http://prod.hi360.com"
params = {:channel_id=>"12345", :lang=>"en"}
key = Marshal.dump(url + "?" + params.to_a.map {|a| a.join("=")}.join('&'))
url = Marshal.load(key)
@dmgarland
dmgarland / gist:7656211
Last active December 29, 2015 10:19
My latest TaskSpec.js
describe("Tasks", function() {
var task;
var last_task_id;
beforeEach(function() {
task = new app.models.Task("Buy the milk");
});
describe("makeId", function() {
@dmgarland
dmgarland / gist:7007800
Created October 16, 2013 13:34
Mongo CRUD
require 'mongo'
# Get a connection to Mongo
db = Mongo::Connection.new
# Insert records (Create)
db["movies_db"]["movies"].insert({ hello: "there"})
# Find records (Read)
db["movies_db"]["movies"].find_one
@dmgarland
dmgarland / gist:6902298
Created October 9, 2013 14:35
Equals method in Javascript
String.prototype.equals = function(s) {
if(typeof(s) == "object") {
return this.valueOf() === s.valueOf();
}
else if(typeof(s) == "string") {
return this.valueOf() === s;
}
else {
return undefined;
}
@dmgarland
dmgarland / gist:6812073
Created October 3, 2013 15:48
Here's that stuff about Factory methods in Ruby
class Mammal
def self.factory(type)
if choice == "Dog"
mammal = Dog.new
elsif choice == "Cat"
mammal = Cat.new
elsif choice == "Whale"
mammal = Whale.new
else
@dmgarland
dmgarland / gist:6762238
Created September 30, 2013 11:02
My sublime settings
{
"auto_complete": false,
"color_scheme": "Packages/Color Scheme - Default/Dawn.tmTheme",
"font_size": 12,
"hot_exit": false,
"ignored_packages":
[
"Floobits",
"Vintage"
],
@dmgarland
dmgarland / gist:5714332
Created June 5, 2013 14:38
An insertion sort solution
class Array
def insertion_sort(list = self)
sorted = [self.delete_at(0)]
self.each_with_index do |i, p|
if i < sorted.last
sorted.each_with_index do |j, k|
if sorted[k] >= i
already_sorted = sorted.slice(0, k - 1)
to_shift = sorted.slice(k + 1, sorted.size)
sorted = already_sorted + [i] + to_shift
@dmgarland
dmgarland / nav.css.scss
Created May 30, 2013 14:27
Navigation bar with media queries
@mixin cool_gradient($from, $to) {
background: $from; /* Old browsers */
background: -moz-linear-gradient(top, $from 0%, $to 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,$from), color-stop(100%,$to)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, $from 0%,$to 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, $from 0%,$to 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, $from 0%,$to 100%); /* IE10+ */
background: linear-gradient(to bottom, $from 0%,$to 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='$from', endColorstr='$to',GradientType=0 ); /* IE6-9 */
require 'spec_helper'
describe Project do
describe 'nested attributes' do
before do
json = {
"title" => "My Amazing Project",
"skills_attributes" => [
app.models.Project = Backbone.Model.extend({
url: function() {
var url = '/users/' + this.user.id + '/projects';
if(!this.isNew()) {
url += '/' + this.id;
}
return url;
},