Skip to content

Instantly share code, notes, and snippets.

View tonosaman's full-sized avatar

Optional Exit of T.Ono tonosaman

View GitHub Profile
@tonosaman
tonosaman / finagle-pingpong.scala
Created October 4, 2011 09:08
finagle ping pong
// scala>:load <thisfile>
// stop by <Ctrl-C>
import com.twitter.finagle.stream._
import com.twitter.finagle.Service
import com.twitter.concurrent._
import com.twitter.finagle.builder.{ClientBuilder, ServerBuilder}
import org.jboss.netty.handler.codec.http.{HttpMethod, HttpVersion, DefaultHttpRequest, HttpRequest}
import org.jboss.netty.buffer.{ChannelBuffers, ChannelBuffer}
@tonosaman
tonosaman / FoldUnion.scala
Created June 4, 2012 21:04 — forked from jorgeortiz85/FoldUnion.scala
Folding over Scala union types
type ¬[A] = A => Nothing
type [T, U] = ¬[¬[T] with ¬[U]]
type ¬¬[A] = ¬[¬[A]]
type |∨|[T, U] = { type λ[X] = ¬¬[X] <:< (TU) }
class FoldUnion[T](t: T) {
def boxClass(x: java.lang.Class[_]): java.lang.Class[_] = x.toString match {
case "byte" => manifest[java.lang.Byte].erasure
case "char" => manifest[java.lang.Character].erasure
case "short" => manifest[java.lang.Short].erasure
@tonosaman
tonosaman / gist:2892315
Created June 7, 2012 23:23
SalesForce Report CSV downloader
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from mechanize import Browser
from urllib import quote
import re
def fetch_sf_csv(report_id):
login_uri = "https://login.salesforce.com/"
username = "example@salesforce.com"
password = "<your-password>"
@tonosaman
tonosaman / BrainfuckDecorder.scala
Created July 13, 2012 03:09
Brainf*ck decorder
// Brainf*ck decorder
// usage:
// $ scala <thisfile>
object BrainfuckDecorder extends util.parsing.combinator.RegexParsers {
val memory = collection.mutable.Map.empty[Int, Int].withDefaultValue(0)
var pointer = 0
def read = memory(pointer)
def write(x: Int) = memory(pointer) = x
override val whiteSpace = """[^><+-.,\[\]]+""".r
import Data.Maybe
import Control.Applicative
import Control.Monad
import Data.Char (isSpace, digitToInt)
import Debug.Trace
main :: IO ()
main = print . runParser $ "(1+2-3*4)*2"
runParser :: String -> Maybe Int
@tonosaman
tonosaman / numplace.hs
Created October 15, 2014 03:55
日本経済新聞2014年10月11日ナンプレソルバー
import Control.Applicative
import Data.Array (Array,array,assocs,(//),(!))
import Data.Maybe (isJust,listToMaybe)
import Data.List (sortBy,transpose,nub,(\\))
import Data.Ord (comparing)
import Debug.Trace
type Loc = (Int, Int)
type Mesh = Array Loc (Maybe Int)
@tonosaman
tonosaman / SuggestFormlet.fs
Last active August 29, 2015 14:15
WebSharper input formlet with radio button suggestions.
module SuggestFormlet
// [References]
// - msdn.microsoft.com/ja-jp/magazine/cc967279.aspx
// - www.websharper.com/question/74314/None/4/redirecting-from-websharper-formlets
open IntelliFactory.WebSharper
module Server =
type Suggests = (string * string) list
@tonosaman
tonosaman / Howto-build-openocd.md
Last active April 27, 2023 14:01
Olimex ARM-USB-OCD-H / openocd-0.9.0 / libftd2xx1.1.12 / Raspberry Pi 2 / Ubuntu 15.04

for RPi2 JTAG debugging with Olimex ARM-USB-OCD-H

System constitution

  • probe device: Olimex ARM-USB-OCD-H
  • target device: Raspberry Pi 2
    • files for booting: bootcode.bin, start.elf, config.txt from here
    • jtag target image armjtag.bin: from here
    • config.txt: edit to add a line kernel=armjtag.bin
  • host machine: Ubuntu 15.04
    • openocd-0.9.0 as debugger host:
      • probe device driver: libftd2xx1.1.12

(Ruby)tap

  • tapself を返す。

  • tapブロックで行った処理は副作用を伴う

    • 同じオブジェクトに連続的に破壊的代入を行うメソッドチェーンとして利用可能。

P = Struct.new(:name)

(Ruby)Procオブジェクト: メソッドを第一級オブジェクトとして扱う

  • Procオブジェクトの作り方いろいろ

    > def hoge(a, b); a + b;  end
    > p = method(:hoge).to_proc
    > p = Proc.new { |a, b| a + b } 
    > p = lambda { |a, b| a + b }
    > p = proc { |a, b| a + b }
    > p = ->(a, b) { a + b }