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
/** Cute little function to take a random sample of a sequence. */ | |
def randomSample(s:Seq[_]) = s filter { _ => util.Random.nextBoolean } |
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
(defn | |
#^{:doc "Clojure code to compute a Collatz sequence."} | |
collatz [n] | |
(if (= n 1) | |
'(1) | |
(cons n | |
(collatz (if (= (mod n 2) 0) | |
(/ n 2) | |
(+ (* n 3) 1)))))) |
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
stpcpy is a #define on Mac OS X. Trying to define it as an extern is invalid. | |
diff -ur mcpp-2.7.2-orig/src/internal.H mcpp-2.7.2/src/internal.H | |
--- mcpp-2.7.2-orig/src/internal.H 2008-08-27 08:01:16.000000000 -0500 | |
+++ mcpp-2.7.2/src/internal.H 2010-11-08 15:53:38.000000000 -0600 | |
@@ -557,6 +557,6 @@ | |
#endif | |
#endif | |
-#if HOST_HAVE_STPCPY |
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 goes in ~/.ssh/config. | |
# ssh is picky about file permissions, so be sure to | |
# chmod 700 ~/.ssh | |
# chmod 600 ~/.ssh/config | |
# | |
# Forward X11 and ssh-agent to trusted hosts. Be sure to only do this for | |
# *trusted* machines, otherwise you may fall victim to identity theft. | |
# See ssh man page for details. | |
# |
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
// FizzBuzz in Scala | |
// http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html | |
1 to 100 map { | |
case x if x % 15 == 0 => "FizzBuzz" | |
case x if x % 3 == 0 => "Fizz" | |
case x if x % 5 == 0 => "Buzz" | |
case x => x | |
} foreach (println _) |
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
#include <stdio.h> | |
int main() { | |
printf("Goodbye, dmr.\n"); | |
return 0; | |
} |
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
trait Searchable { | |
def search(query: SearchQuery): Seq[SearchResults] | |
} | |
trait PaginationWithNominalType { | |
this: Searchable => | |
def page(query: SearchQuery, pageSize: Int, pageNum: Int) = { | |
search(query).grouped(pageSize).toList(pageNum) | |
} | |
} |
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
//create a map | |
val cars = Map("james" -> "BMW", "ike" -> "Infiniti", "stephen" -> "Buick") | |
//create a map from an Array | |
//Scala does not provide a convenience method to do this... :( | |
val carArray = Array("james", "BMW", "ike", "Infiniti", "stephen", "Buick") | |
val cars = carArray.grouped(2).toList.map(c => (c.head,c.last)).toMap | |
//mapping over a map | |
//transform all string keys to symbols (interned strings) |
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
#!/bin/bash | |
# | |
# Runs a program, stripping ANSI color codes from stdout and stderr | |
# | |
# detect which sed to use | |
if test -z ${SED}; then | |
if cat /dev/null | sed -r '' 2> /dev/null ; then | |
SED=sed |
OlderNewer