Skip to content

Instantly share code, notes, and snippets.

Avatar
👍
webby goodness

Tad Thorley phaedryx

👍
webby goodness
View GitHub Profile
@phaedryx
phaedryx / decimalize.rb
Created Jul 17, 2014
convert a mixed number string to a decimal in Ruby
View decimalize.rb
def decimalize(string)
return 0.0 if string.nil? || string.empty?
string.gsub!(/[^\d\s\/]/, "")
fraction, numeral = string.split.reverse
fraction ||= '0/1'
numeral.to_i + Rational(fraction).to_f
end
# decimalize('1 1/2') => 1.5
# decimalize('2 3/4 inches') => 2.75
View destructured_assignment.coffee
weatherReport = (location) ->
# Make an Ajax request to fetch the weather...
[location, 72, "Mostly Sunny"]
[city, temp, forecast] = weatherReport "Berkeley, CA"
futurists =
sculptor: "Umberto Boccioni"
painter: "Vladimir Burliuk"
poet:
@phaedryx
phaedryx / 1-application.js.coffee
Created Nov 19, 2011
Example code for my DragMarkers project (part 1)
View 1-application.js.coffee
#= require spine/spine
#= require spine/ajax
#= require_tree ./lib
#= require_self
#= require_tree ./models
#= require_tree ./controllers
#= require_tree ./views
#= require_tree .
@phaedryx
phaedryx / 2-markers_controller.js.coffee
Created Nov 20, 2011
Example code for my DragMarkers project (part 2)
View 2-markers_controller.js.coffee
$ = jQuery.sub()
Marker = App.Marker
class App.MarkersController extends Spine.Controller
elements:
"#map" : "mapEl"
".marker" : "markerIcons"
constructor: ->
super
@phaedryx
phaedryx / final-marker.js.coffee
Created Nov 20, 2011
Example code for my DragMarkers project (part 3)
View final-marker.js.coffee
class App.Marker extends Spine.Model
@configure 'Marker', 'latitude', 'longitude', 'icon'
@extend Spine.Model.Ajax
constructor: ->
super
@gmarker = new google.maps.Marker(
position: new google.maps.LatLng(@latitude, @longitude)
icon: @icon
draggable: true
View gist:1747038
var Student;
var students;
var student1;
var student2;
var i, len, student;
Student = (function() {
function Student(fname, lname) {
this.firstName = fname;
this.lastName = lname;
View gist:1803342
module Foo
class BarGenerator < Rails::Generators::Base
class_option :baz, :aliases => '-b', :type => :string, :default => 'quux', :desc => 'foobar is unfoo'
def bar
puts options[:baz]
end
end
end
View gist:2316002
(function() {
"use strict";
(42, eval)('var z = 5');
}());
View gist:2962074
def leppard
self.pour(@sugar)
end
View modules_with_methods.rb
module Debug
def whoAmI?
"#{self.type.name} (\##{self.id}): #{self.to_s}"
end
end
class Phonograph
include Debug
def initialize(title)
@title = title
You can’t perform that action at this time.