Skip to content

Instantly share code, notes, and snippets.

View seratch's full-sized avatar

Kazuhiro Sera seratch

View GitHub Profile
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use Data::Dumper;
my $rdbms = 'mysql';
my $db = 'database_name';
@seratch
seratch / gist:925573
Created April 18, 2011 15:40
How to install RMongo
#!/bin/sh
# JAVA_HOME=/your/java/home
# R CMD javareconf -e
# R
# install.packages("rJava")
# install.packages("RUnit")
wget https://github.com/downloads/tc/RMongo/RMongo_0.0.20.tar.gz --no-check-certificate
@seratch
seratch / gist:936225
Created April 22, 2011 07:44
How to connect MongoDB via Scala REPL
scala -cp casbah-commons*.jar:casbah-core*.jar:casbah-query*.jar:mongo-java-driver*.jar:slf4j-api-*.jar:scalaj-collection*.jar
scala> val conn = com.mongodb.casbah.MongoConnection("hostname")
conn: com.mongodb.casbah.MongoConnection = com.mongodb.casbah.MongoConnection@ada6d09
@seratch
seratch / gist:938761
Created April 23, 2011 16:32
東京電力/過去30日の電力使用状況(各日18時台)
// see also https://github.com/seratch/yahoo-setsuden-api-client
// invoke Scala REPL
// scala -cp yahoo-setsuden-api-client*:joda-time*
import com.github.seratch.yahooapis.setsuden.scala._
import request._
import response._
import org.joda.time.LocalDate
@seratch
seratch / gist:965398
Created May 10, 2011 21:17
How to install jslint.vim on Mac OS X
# Rhino (Java required)
curl ftp://ftp.mozilla.org/pub/mozilla.org/js/rhino1_7R3.zip > ./rhino.zip
unzip rhino.zip
mkdir -p ~/Library/Java/Extensions
cp -p rhino1_7R3/js.jar ~/Library/Java/Extensions/
rm -rf rhino.zip ./rhino1_7R3
# -- chekcing installed
# java org.mozilla.javascript.tools.shell.Main
@seratch
seratch / gist:968555
Created May 12, 2011 14:02
Scala LINQ-like impl memo
// ----------------------------------------
// * Scala LINQ-like impl memo
// http://scala-programming-language.1934581.n4.nabble.com/scala-LINQ-for-scala-td2003452.html
// https://github.com/vladimirk/scalalinq/blob/master/src/scalalinq/linq.scala
// ----------------------------------------
class linq[A](seq: Seq[A]) {
def where(p: A => Boolean) = seq filter p
def select[B](p: A => B) = seq map p
def orderby[B <% Ordered[B]](f: A => B) = seq.toList sort ((a, b) => f(a) < f(b))
@seratch
seratch / gist:968871
Created May 12, 2011 16:30
Scala 2.9.0.final Changesの確認
// ----------------------
// Scala 2.9.0.final
// http://www.scala-lang.org/node/43
// ----------------------
// REPLのexitはdeprecated
scala> exit
<console>:8: warning: method exit in object Predef is deprecated: Use sys.exit() instead
exit
@seratch
seratch / gist:984337
Created May 21, 2011 07:31
memo@2.9.0.final
scala> val json = """{ "person" : { "name": "A" }, "person": { "name" : "B" } }"""
json: java.lang.String = { "person" : { "name": "A" }, "person": { "name" : "B" } }
scala> util.parsing.json.JSON.parseFull(json)
res4: Option[Any] = Some(Map(person -> Map(name -> B)))
scala>
@seratch
seratch / gist:993278
Created May 26, 2011 14:38
diff scala-2.9.0.final scala-2.9.0.1
src/scala-compiler-src.jar
src/scala-library-src.jar
diff -r scala-2.9.0.final/src/scala/tools/nsc/ast/TreeGen.scala scala-2.9.0.1/src/scala/tools/nsc/ast/TreeGen.scala
233,240c233,246
< val sym = tp.typeSymbol
< val tree =
< if (sym == UnitClass) Literal(())
< else if (sym == BooleanClass) Literal(false)
< else if (isValueClass(sym)) Literal(0)
@seratch
seratch / gist:998577
Created May 30, 2011 07:52
yield tuples from List of tuples or Map
scala> for { (k,v) <- List((1,2),(3,4)) } yield (k,v)
res0: List[(Int, Int)] = List((1,2), (3,4))
scala> for { (k,v) <- List((1,2),(3,4)).toMap } yield (k,v)
res1: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2, 3 -> 4)