This file contains 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
/** | |
* THE FOLLOWING EXERCISE IS FROM (THE SAMPLE OF) "PURELY FUNCTIONAL DATA STRUCTURES" | |
* http://www.amazon.com/Purely-Functional-Structures-Chris-Okasaki/dp/0521663504/ref=sr_1_1?s=books&ie=UTF8&qid=1282766033&sr=1-1 | |
* | |
* Exercise 2.1 | |
* | |
* Write a function suffixes of type a list -> a list list that takes | |
* a list xs and returns a list of all the suffixes of xs in decreasing | |
* order of length. For example: | |
* |
This file contains 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
// In a method that returns a NodeSeq. | |
// compiles | |
val seq = for { | |
moduleId <- S.param("moduleId") | |
moduleInstanceId <- S.param("id") | |
backupId <- S.param("backupId") | |
} yield bind("backup", xhtml, "path" -> backupId) | |
seq openOr (redirectTo("/")) |
This file contains 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
package sidewayscoding.example | |
// normal imports goes here | |
import net.liftweb.http.js.JE._ // implicit string => Str | |
import net.liftweb.http.js.JsCmds._ // implicit JsExp => JsCmd | |
import net.liftweb.http.js.jquery.JqJE.{JqId,JqAttr, Jq} | |
class Test { | |
def test = |
This file contains 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 script will install the following Textmate bundles | |
# | |
# Languages | |
# - c https://github.com/textmate/c.tmbundle | |
# - coffeescript https://github.com/jashkenas/coffee-script-tmbundle | |
# - context free https://github.com/textmate/context-free.tmbundle | |
# - erlang https://github.com/textmate/erlang.tmbundle | |
# - haskell https://github.com/textmate/haskell.tmbundle.git | |
# - html https://github.com/textmate/html.tmbundle |
This file contains 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
/* | |
I want to use pattern matching in coffeescript as a more capable switch. It uses destructuring | |
assignments to figure out which of the cases that matches. So it can match on the entire | |
structure of the object instead of just an integer. | |
(* in F# *) | |
let list = [1;2;3;4] | |
match list with | |
| [] -> printfn "empty list" | |
| x :: xs -> printfn "first element is " + x |
This file contains 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
package com.reversebackup | |
import scala.xml._ | |
import scala.xml.transform._ | |
import scala.xml.XML | |
/* | |
This snippet creates two methods: removeAllNamedTagsTransformer & createRewriteRule. | |
They both create a RuleTransformer which removes all tags with a specific name. | |
However, it seems that it doesn't work if the name of the parameter is 'name'. |
This file contains 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
#!/usr/bin/env ruby | |
# Alignes the source | |
def align(text, regexp, width) | |
text.to_a.map do |line| | |
if offset = offsetOfRegexpInLine(line, regexp) | |
if shouldInsertBefore(line, regexp) | |
before = line[0..offset-1] | |
before + ' ' * (width - (before.length)) + line[offset..line.length-1] | |
else | |
before = line[0..offset] |
This file contains 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
Jun 8 08:21:15 localhost Unknown[305]: Launching the Language Chooser for an OS Install | |
Jun 8 08:21:24 localhost configd[102]: bootp_session_transmit: bpf_write(en1) failed: Network is down (50) | |
Jun 8 08:21:24 localhost configd[102]: DHCP en1: INIT transmit failed | |
Jun 8 08:21:24 localhost LCA[306]: Bookmark failed to issue extension for item (depth=4000): No such file or directory | |
Jun 8 08:21:28 localhost LCA[306]: Using keyboard layout 9 | |
Jun 8 08:21:28 localhost Unknown[307]: Keyboard Layouts: duplicate keyboard layout identifier -16899. | |
Jun 8 08:21:28 localhost Unknown[307]: Keyboard Layouts: keyboard layout identifier -16899 has been replaced with -28673. | |
Jun 8 08:21:28 localhost Unknown[307]: Keyboard Layouts: duplicate keyboard layout identifier -16900. | |
Jun 8 08:21:28 localhost Unknown[307]: Keyboard Layouts: keyboard layout identifier -16900 has been replaced with -28674. | |
Jun 8 08:21:28 localhost LCA[306]: Found primary language hint "en" |
This file contains 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
// Attempt to do tail-recursion in JavaScript without getting a stack-overflow exception. | |
// This is horribly slow because of all of the extra stack frames pr. thunk. | |
// What would you call this? Lazy-tail-recursion? | |
var tailrec = function(f) { | |
for(var x = f() ; typeof x == "function" ; x = x()){} | |
return x; | |
}; | |
var counter = function(){ |