Skip to content

Instantly share code, notes, and snippets.

View tototoshi's full-sized avatar

Toshiyuki Takahashi tototoshi

View GitHub Profile
@tototoshi
tototoshi / array_merge_kowai.php
Last active August 29, 2015 13:59
array_merge 怖い
<?php
/* !! 入力配列の中にある数値添字要素の添字の数値は、 結果の配列ではゼロから始まる連続した数値に置き換えられます。 */
$a = array(
'a' => 'aaa',
'100' => '100100100',
);
$b = array(
'b' => 'bbb',
@tototoshi
tototoshi / notification_center.py
Created May 27, 2014 02:55
OS X での通知
import subprocess
script = 'display notification "Finished" with title "Job Finished" sound name "Tritone"'
p = subprocess.Popen(["osascript"], stdin=subprocess.PIPE)
p.stdin.write(script)
p.stdin.close()
p.wait()
@tototoshi
tototoshi / is_animated_gif.php
Last active August 29, 2015 14:02
PHP で GIF を読む
<?php
class GIFReader
{
const TRAILER = 0x3b;
const IMAGE_INTRODUCER = 0x2c;
const EXTENSION_INTRODUCER = 0x21;
const GRAPHIC_CONTROL_LABEL = 0xf9;
@tototoshi
tototoshi / XHRImage.js.scala
Created June 28, 2014 15:55
Scala.js で xhr で画像をとってきて表示する
package com.github.tototoshi.gifplayer
import scala.scalajs.js
import js.annotation.JSExport
import org.scalajs.dom
@JSExport
object GIFPlayer extends js.JSApp {
def main(): Unit = {
@tototoshi
tototoshi / a.sql
Created July 19, 2014 14:14
timestamp with time zone
example=# CREATE TABLE tstest (ts1 timestamp, ts2 timestamp with time zone);
CREATE TABLE
example=# \d tstest;
Table "public.tstest"
Column | Type | Modifiers
--------+-----------------------------+-----------
ts1 | timestamp without time zone |
ts2 | timestamp with time zone |
example=# INSERT INTO tstest VALUES (current_timestamp, current_timestamp);
@tototoshi
tototoshi / Test.scala
Last active August 29, 2015 14:16
scalacache bug?
case class User(id: Int, name: String)
object Test {
import scalacache._
import memoization._
import redis._
implicit val scalaCache = ScalaCache(RedisCache("localhost", 6379))
@tototoshi
tototoshi / future.scala
Created March 26, 2015 03:54
Future.successful と Future.apply
import scala.concurrent.Future
// def successful[T](result: T): Future[T] を使った場合
// result を評価する時点でブロックされるので
// a b c の順に表示される
println("a")
val f1 = Future.successful { Thread.sleep(1000); println("b") }
println("c")
// def apply[T](body: ⇒ T)(implicit execctx: ExecutionContext): Future[T]
import java.util.List
import twitter4j.Query
import twitter4j.QueryResult
import twitter4j.Tweet
import twitter4j.Twitter
import twitter4j.TwitterFactory
import scala.collection.JavaConversions._
object SimpleTwitterSearchApp {
def search(word: String = "#rpscala") {
(ns sample
(:import (twitter4j Query
QueryResult
Tweet
Twitter
TwitterFactory)))
(def twitter-api (.. (TwitterFactory.) getInstance))
(defn make-query [word]
import scala.collection.JavaConversions._
import java.util.List
import twitter4j.{TwitterFactory, Twitter, Tweet, QueryResult, Query}
object SimpleTwitterSearchApp {
def search(word: String = "#rpscala"): List[Tweet] = {
val query = new Query
query.setQuery(word)
val twitter = new TwitterFactory().getInstance()