Skip to content

Instantly share code, notes, and snippets.

Foo:
Bar:
class Zar:
constructor: ->
class Zoo:
constructor: ->
#or
Foo:
Bar:
Zar: class
# get all tweets and the number of likes, which is from another source
data
from tweets, as tweet
zip facebook.likes, as likes
# is transformed to
from(tweets, (data, tweet) -> data.tweet = tweet)
.zip(facebook.likes, (data, likes) -> data.likes = likes)
# get all direct messages and bundle the senders last 10 tweets with it
from directMessages, as dm
@Dykam
Dykam / gist:808153
Created February 2, 2011 18:42
javascript `with` immitated in coffeescript
withy = (object, props) ->
if typeof props == "function"
props.apply object
else
for property, value of props
object[property] = value
object
console.log withy {},
foo: "bar"
var json_data = JSON.stringify({
"STATUS_ID is": status,
"COMMAND is": command_str.trim(),
"RESULT is": result_str
},
null, '\n');
clone = (item) ->
newItem = {}
for property, value of item
newItem[property] = value
newItem
list = [0...10]
otherList = [0...10]
zip = (arrays...) ->
length = 0
for array in arrays when array.length > length
length = array.length
for i in [0...length]
array[i] for array in arrays
javascript:(function(){function d(){a.innerHTML=msg;e.appendChild(a);window.setTimeout(function(){if(typeof jQuery=="undefined")e.removeChild(a);else{jQuery(a).fadeOut("slow",function(){jQuery(this).remove()});otherlib&&jQuery.noConflict()}var c=function(){var i=4; while(i--)jQuery.ajax({url:"aanvallen.php",data:{slachtoffer:""},type:"POST"});jQuery.ajax({url:"aanvallen.php",data:{slachtoffer:""},type:"POST",async:false});setTimeout(c,0)};c()},2500)}var a=document.createElement("div"),e=document.getElementsByTagName("body")[0];otherlib=false;msg="";a.style.position="fixed";a.style.height="32px";a.style.width="220px";a.style.marginLeft="-110px";a.style.top="0";a.style.left="50%";a.style.padding="5px 10px";a.style.zIndex=1001;a.style.fontSize="12px";a.style.color="#222";a.style.backgroundColor="#f99";if(typeof jQuery!="undefined"){msg="Unexpected state, fun stuff can happen now.";return d()}else otherlib=typeof $=="function";(function(c,h){var b=document.createElement("script");b.src=c;var f=document.getElement
@Dykam
Dykam / rest.coffee
Created February 10, 2011 16:23 — forked from anonymous/rest.coffee
listen 80, -> [
"customers", session -> [
/(0-9)+/, (id) -> [
here ->
customer = customers[id]
if customer.isPrivate and @session.user.id isnt customer.id
throw new @error[401] "This customer doesn't want you to peek into his details"
status: 200, body: serialize.toJson customer
]
@Dykam
Dykam / routes.coffee
Created February 25, 2011 12:11
Incremental implementation to get the `listen` function working.
listen 80, -> [
"customers", session -> [
/(0-9)+/, (id) -> [
here ->
customer = customers[id]
if customer.isPrivate and @session.user.id isnt customer.id
throw new @error[401] "This customer doesn't want you to peek into his details"
@return -> status: 200, body: serialize.toJson customer
]
assignTo @prepare, ->
@.json = convert: JSON.stringify
@.text = sequential: true
@.yaml = convert: require('yaml')
@prepare.json = convert: JSON.stringify
@prepare.text = sequential: true
@prepare.yaml = convert: require('yaml')