Skip to content

Instantly share code, notes, and snippets.

View tototoshi's full-sized avatar

Toshiyuki Takahashi tototoshi

View GitHub Profile
@tototoshi
tototoshi / ScalaQueryCase.scala
Created November 20, 2011 01:41
ScalaQueryでCase文を実行する
import org.scalaquery._
import ql._
import basic.{BasicTable => Table, _}
import BasicDriver.Implicit._
import session.{ Session, Database }
/*
scala_query_example=> select * from Coffees;
id | name | supid | price
----+-----------------+-------+-------
@tototoshi
tototoshi / DynamicVariable.scala
Created November 19, 2011 12:31
scala.util.DynamicVariable のサンプル
import scala.util.DynamicVariable
object Main extends App {
val dyn = new DynamicVariable[Int](0)
println(dyn.value)
dyn.withValue(100) {
@tototoshi
tototoshi / ScalaQuerySQLExample2.scala
Created November 19, 2011 04:30
ScalaQueryでSQLを実行する(パラメータありばーじょん)
scala> import org.scalaquery.session.Database
import org.scalaquery.session.Database
scala> import org.scalaquery.session.Database.threadLocalSession
import org.scalaquery.session.Database.threadLocalSession
scala> import org.scalaquery.simple.StaticQuery._
import org.scalaquery.simple.StaticQuery._
scala> val db = Database.forURL("jdbc:postgresql:scala_query_example", driver="org.postgresql.Driver", user="user", password="password")
@tototoshi
tototoshi / ScalaQuerySQLExample1.scala
Created November 19, 2011 04:26
ScalaQueryでSQLを実行する
import org.scalaquery.session.Database
scala> import org.scalaquery.session.Database
import org.scalaquery.session.Database
scala> import org.scalaquery.session.Database.threadLocalSession
import org.scalaquery.session.Database.threadLocalSession
scala> import org.scalaquery.simple.StaticQuery._
import org.scalaquery.simple.StaticQuery._
@tototoshi
tototoshi / RemoteCalculator.scala
Created November 10, 2011 17:32
daimonscala#21
import scala.util.control.Exception._
class ServerIsDownException extends Exception
object A extends App {
val remoteCalculatorService = new AnyRef {
def add(a: Int, b: Int): Int = {
a + b match {
case odd if odd % 2 == 1 => odd
@tototoshi
tototoshi / Twitter4jStreamingAPISample.scala
Created November 4, 2011 03:24
Twitter4jでストリーミングAPIを使ってみる
import twitter4j._
import conf._
/* build.sbt
scalaVersion := "2.9.1"
libraryDependencies ++= Seq(
"org.twitter4j" % "twitter4j-core" % "2.2.5",
"org.twitter4j" % "twitter4j-stream" % "2.2.5"
@tototoshi
tototoshi / namaewatashi.scala
Created September 3, 2011 15:34
名前渡し
def repeat(n: Int)(f: => Unit) {
for (i <- 0 until n) {
f
}
}
repeat(3){
println("Hello")
}
@tototoshi
tototoshi / my-py-search-documentation.el
Created August 11, 2011 16:57
pythonのドキュメント検索
(defvar my-py-docs-python-org-url "http://docs.python.org")
(defun my-py-search-documentation-interactive (word)
(interactive "sSEARCH: ")
(my-py-search-documentation word))
(defun my-py-search-documentation-at-point ()
(interactive)
(let ((word (current-word)))
(when word
@tototoshi
tototoshi / ggrks_switch_lang.js
Created July 12, 2011 01:16
Googleの検索言語切り替え(en<->ja)ブックマークレット
javascript:void((function () {
var url = location.href;
var ja = url.search(/hl=ja/);
var en = url.search(/hl=en/);
if (url.search(/google\.(co\.jp|com)\/search/) < 0) return;
if (ja > 0) {
location.href = url.replace(/hl=ja/, "hl=en");
} else if (en > 0) {
@tototoshi
tototoshi / rsed.py
Created July 6, 2011 08:28
カレントディレクトリ以下を再帰的にsedしまくる
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
import subprocess
def do_sed(fullpath, old, new):
sed_script = "s/%s/%s/g" % (old, new)
command = ["sed", "-i", fullpath, "-e", sed_script]