This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Async.IF somecondition, -> | |
doSomething() | |
.ELSEIF someothercondition, -> | |
doSomethingElse() | |
.ELSE -> | |
anotherThing() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* An implementation of Ruby's string.succ method. | |
* By Devon Govett | |
* | |
* Returns the successor to str. The successor is calculated by incrementing characters starting | |
* from the rightmost alphanumeric (or the rightmost character if there are no alphanumerics) in the | |
* string. Incrementing a digit always results in another digit, and incrementing a letter results in | |
* another letter of the same case. | |
* | |
* If the increment generates a carry, the character to the left of it is incremented. This |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lorem = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed pulvinar diam eu ' + | |
'dolor bibendum et varius diam laoreet. Morbi eget rutrum enim. Sed enim ipsum, ' + | |
'posuere nec hendrerit non, commodo quis tortor. Fusce id nisl augue. Fusce at ' + | |
'lectus ut libero vehicula imperdiet.' | |
doc.text 'This text is left aligned. ' + lorem, 100, 100, | |
width: 410 | |
align: 'left' | |
doc.moveDown() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doc.addPage | |
size: 'legal' | |
layout: 'landscape' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PDFDocument = require 'pdfkit' | |
doc = new PDFDocument | |
# Embed a font, set the font size, and render some text | |
doc.font('fonts/PalatinoBold.ttf') | |
.fontSize(25) | |
.text('Some text with an embedded font!', 100, 100) | |
# Add another page | |
doc.addPage() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
# JSONDB - a compressed JSON format | |
# By Devon Govett | |
# Originally proposed by Peter Michaux - http://michaux.ca/articles/json-db-a-compressed-json-format | |
# | |
# jsondb.pack converts an array of objects with the same keys (i.e. from a database) | |
# and flattens them into a single array, which is much smaller than the pure json | |
# representation where the keys are repeated for each item in the array. | |
# Combine with JSON.stringify to send compressed JSON data over the network. | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arr = [], | |
obj = {'abcdef' : 1, 'qqq' : 13, '19' : [1, 2, 3, 4]}; | |
for(var i = 0; i < 5000; i++) | |
arr.push(obj); | |
// jsondb(arr) looks something like this: | |
// ["abcdef", "qqq", "19", [1, 13, [1, 2, 3, 4]], [1, 13, [1, 2, 3, 4]]...] | |
> JSON.stringify(arr).length //original |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# fill path to ctx | |
Path.fill(ctx, "M250 150 L150 350 L350 350 Z") | |
# stroke | |
Path.stroke(ctx, "M250 150 L150 350 L350 350 Z") | |
# clip | |
Path.render(ctx, "M250 150 L150 350 L350 350 Z") | |
ctx.clip() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This CoffeeScript: | |
15 + if somevar then "%" | |
used to compile to this JavaScript: | |
15 + (somevar ? "%" : null) | |
which returned 15 if somevar was false. | |
Now it compiles to: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1: how could you rewrite the following to make it shorter? | |
foo ? bar.doSomething(el) : bar.doSomethingElse(el); | |
// 2: what is the faulty logic in the following code? | |
//you are creating a local version of foo instead of overwriting | |
//the global version. Thus, foo will always be equal to world. | |
//The problem is fixed below. | |
var foo = 'hello'; |