Skip to content

Instantly share code, notes, and snippets.

Model.findByName = (name, value, cb) ->
model = new @
@find "SELECT * FROM #{model.tableName()} WHERE `#{name}`=`#{value}` LIMIT 1", cb
@meltingice
meltingice / gist:4602034
Created January 23, 2013 04:44
iRacing SDK NodeJS bindings session output
{ WeekendInfo:
{ TrackName: 'okayama short',
TrackID: 167,
TrackLength: '1.93 km',
TrackDisplayName: 'Okayama International Circuit',
TrackDisplayShortName: 'Okayama Short',
TrackCity: 'Okayama',
TrackCountry: 'Japan',
TrackAltitude: '265.84 m',
TrackLatitude: '34.914295 m',
@meltingice
meltingice / gist:4356210
Last active December 10, 2015 01:09
This is a nice way to force instantiation in a Coffeescript "class". It basically allows it to look like a function. Adapted from John Resig's blog post http://ejohn.org/blog/simple-class-instantiation/
class Foo
constructor: ->
return new Foo() unless @ instanceof Foo
# Guaranteed to be an object here
@announce()
announce: -> console.log "here!"
# These are equivalent now
@meltingice
meltingice / gist:3955550
Created October 25, 2012 21:29
RestClient + the 37Signals API
def do_post(account_id, endpoint, params={})
r = RestClient::Resource.new(
api_url(account_id) + endpoint + ".json",
:headers => headers
)
# RestClient doesn't convert the POST parameters to
# JSON, so we have to do it manually. This was the
# big gotcha, and why we were getting 415 Unsupported
# Media Type as the error response.
psd = psd.fromFile "/path/to/file.psd"
psd.parse()
data = psd.toJSON()
# PS <= 5.0
console.log data.layerMask.layers[0].adjustments.legacyEffects
# PS >= 6.0
console.log data.layerMask.layers[0].adjustments.effects
@meltingice
meltingice / gist:2171421
Created March 23, 2012 14:53
CamanJS Example
// First, initialize Caman (only do this once)
caman = Caman("#image-id");
// This will be called when a slider is adjusted
var applyFilters = function () {
// Revert the canvas to its original state. This is asynchronous.
caman.revert(function () {
// Once canvas is ready, go through each slider and call filter
var slider;
for (var key in sliders) {
<style type="text/css">
#parent { position: relative; }
#fixed {
position: absolute;
top: 10px;
left: 10px;
}
#content { overflow: auto; }
</style>
@meltingice
meltingice / gist:2037813
Created March 14, 2012 16:50
Example port of Ruby's BinData to Coffeescript
class Rectangle extends BinData.Record
endian: "little"
parse: ->
uint16 "len"
string "name", readLength: len
uint32 "width"
uint32 "height"
r = new Rectangle(file)
console.log "Rectangle #{r.name} is #{r.width} x #{r.height}"
parseRLE: ->
Log.debug "Attempting to parse RLE encoded image..."
# RLE stores the scan line byte counts in the first chunk of data
byteCounts = []
for i in [[email protected]]
for j in [0...@height]
byteCounts.push @file.readShortInt()
Log.debug "Read byte counts. Current pos = #{@file.tell()}, Pixels = #{@length}"
parseRLE: ->
Log.debug "Attempting to parse RLE encoded image..."
# RLE stores the scan line byte counts in the first chunk of data
byteCounts = []
for i in [[email protected]]
for j in [0...@height]
byteCounts.push @file.readShortInt()
Log.debug "Read byte counts. Current pos = #{@file.tell()}, Pixels = #{@length}, End = #{@endPos}"