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
----- | |
js:1 (function() { | |
js:2 var Access, Arr, Assign, Base, Block, Call, Class, Closure, Code, Comment, Existence, Extends, For, IDENTIFIER, IDENTIFIER_STR, IS_STRING, If, In, Index, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, METHOD_DEF, NEGATE, NO, Obj, Op, Param, Parens, RESERVED, Range, Return, SIMPLENUM, Scope, Slice, Splat, Switch, TAB, THIS, Throw, Try, UTILITIES, Value, While, YES, compact, del, ends, extend, flatten, last, merge, multident, starts, unfoldSoak, utility, _ref, | |
js:3 __hasProp = Object.prototype.hasOwnProperty, | |
js:4 __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }, | |
js:5 __indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item |
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
root = this | |
$ = jQuery | |
root.logger = do ($) -> | |
logContainer = null | |
write = (msg) -> | |
logContainer.append("<p>#{msg}</p>") | |
pub = | |
init: (el) -> logContainer = el | |
log: (msg) -> write msg |
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
Follow instructions here: | |
http://www.php.net/manual/en/install.macosx.bundled.php | |
Create /Users/steve/Sites/steve.php: | |
<?php phpinfo(); ?> | |
Enable PHP and start Apache: |
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
class StaticMath | |
@pi = 3.14 | |
@sum = (a, b) -> a+b | |
console.log StaticMath.pi # 3.14 | |
console.log StaticMath.sum(3,4) # 7 | |
# If your class just has statics, this style may | |
# make more sense | |
MathNamespace = |
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
call_three_funcs = (f1, f2, f3) -> | |
f1() | |
f2() | |
f3() | |
# This style is highly unrecommended, but it shows | |
# that coffeescript can support delimiters around functions. | |
call_three_funcs (-> | |
console.log "one" | |
), |
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 code demonstrates how CS scoping works within a file. Scroll down to the end to | |
# see how cross-file scoping works. | |
# Here are the rules. | |
# | |
# Scoping is all lexical. Read the file from top to bottom to determine variable scopes. | |
# | |
# 1) When you encounter any variable in the top-level nesting, its scope is top level. | |
# 2) Inside a function, if you encounter a variable name that still exists in an outer scope, then that | |
# variable name refers to the variable in the outer scope. (This is "closure".) |
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 is a sketch of how to add line number support to CoffeeScript. | |
# It only goes as far as getting line numbers into the AST output from | |
# nodes. Even that would be a huge step forward, and it would set the | |
# groundwork for other features, such as line-number mappings. | |
# | |
# LEXER HOOKS (coffee-script.coffee) | |
# |
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
roll_odometer = (factors, odometer) -> | |
# digits are an array w/least significant digit in | |
# position 0; for example, [3, [0]] will roll as | |
# follows: | |
# [0] -> [1] -> [2] -> [0, 1] | |
[base, digits] = odometer | |
i = 0 | |
while i < digits.length | |
digits[i] += 1 | |
carry = digits[i] == base |
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
import re | |
def counted_quine(): | |
"This function has been quined 0 times." | |
ds = counted_quine.__doc__ | |
cnt = int(re.search('(\d+)', ds).group(1)) + 1 | |
code = ''' | |
def counted_quine(): | |
"This function has been quined %d times." | |
ds = counted_quine.__doc__ |
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
def ok_horizontal(m): | |
# for each horizontal row in the array, ensure | |
# that you dont have duplicate values | |
for lst in m: | |
# TODO, just use set | |
vals = {} # values encountered so far | |
for elem in lst: | |
if elem is None: | |
continue |