Skip to content

Instantly share code, notes, and snippets.

@machty
machty / index.html.slim
Created April 7, 2012 14:24
An attempt at Slim/Haml helpers for handlebars
= handlebars_template_named "edit-field" do
= hb %{ if isEditing } do
= hb %{ view BD.TextField valueBinding="value" }
= hb_else
= hb %{ if value } do
= hbb %{ value }
= hb_else
span.no-name empty
/ Outputs
@machty
machty / gist:2931511
Created June 14, 2012 17:05
async queue download
ownloadQueue = async.queue (photo, callback) ->
# Here we define the task handled by this concurrency-limiting queue.
downloadfile = photo.url
host = url.parse(downloadfile).hostname
filename = url.parse(downloadfile).pathname.split("/").pop()
filename = "./public/downloads/#{filename}"
photo.localFilename = filename
console.log "set photo.localFilename to #{photo.localFilename}"
theurl = http.createClient(80, host)
requestUrl = downloadfile
DOWNLOAD_CONCURRENCY = 10
# Data Structures
longPollRequests = []
jobs = {}
downloadQueue = async.queue (photo, callback) ->
# Here we define the task handled by this concurrency-limiting queue.
downloadfile = photo.url
host = url.parse(downloadfile).hostname
filename = url.parse(downloadfile).pathname.split("/").pop()
@machty
machty / Assetfile
Last active December 10, 2015 08:48
Rake Pipeline filter for syncing already-published static content on production with the generated local file via Nokogiri and css selectors
require "rake-pipeline-web-filters"
require "./remote-replace-filter"
# specify output, other configuration
input "app" do
match "slim/whatever.slim" do
tilt { |input| input.sub(/\.slim$/, '.html') }
copy "index.html"
@machty
machty / emblem
Last active December 10, 2015 19:29
Emblem/Emblate: indentation-based templating language targeting Ember Handlebars
Emblem examples:
1) Text / property lookup / helpers
#bar.baz Raw text
#bar.baz
| Raw text
on multiple lines
with {{normal}} Handlebars syntax support
as well as raw <span>HTML</span> support.
@machty
machty / newoperator.coffee
Created January 9, 2013 22:48
Proposal: add block level lambda ~> operator to CoffeeScript to hackishly achieve block level lambda functionality in pre ES6 Javascript. An example of block level lambdas is returning a value from within a .each loop in Ruby. See below.
findTheThingWeWant = (things) ->
things.each (thing) ~>
return item if thing.isWhatWeWant
// Version: v1.0.0-pre.2-318-g075ed98
// Last commit: 075ed98 (2013-01-07 10:58:00 -0800)
(function() {
/*global __fail__*/
/**
Ember Debug
State = (hash) -> Em.State.extend hash
TransitionTo = Em.State.transitionTo
C = null
Receivers.WithdrawController = Em.ObjectController.extend
receiverController: null
router: null
init: ->
@_super()
start = content
content = statement*
statement
= html
/ mustache
html
= htmlMaybeBlock
this.StringScanner = (function() {
var StringScanner;
StringScanner = (function() {
function StringScanner(str) {
this.str = str != null ? str : '';
this.str = '' + this.str;
this.pos = 0;
this.lastMatch = {
reset: function() {