Skip to content

Instantly share code, notes, and snippets.

@edvakf
edvakf / A
Last active April 28, 2016 02:19
$ mkdir rack-test
$ cd rack-test
$ vi Gemfile
$ vi config.ru
$ vi unicorn_config.rb
$ bundle install --path=.bundle
$ bundle exec unicorn -c ./unicorn_config.rb
# apache2を再起動
sudo systemctl restart apache2
# apache2の設定を再読み込み
sudo systemctl reload apache2
# apache2を止める
sudo systemctl stop apache2
var a = SIMD.Float32x4(1.0,2.0,3.0,4.0);
var b = SIMD.Float32x4(5.0,6.0,7.0,8.0);
var c = SIMD.Float32x4.add(a,b);
console.log(SIMD.Float32x4.extractLane(c, 0));
console.log(SIMD.Float32x4.extractLane(c, 1));
console.log(SIMD.Float32x4.extractLane(c, 2));
console.log(SIMD.Float32x4.extractLane(c, 3));
var a = SIMD.Int32x4(1,2,3,4);
var b = SIMD.Int32x4(5,6,7,8);
@edvakf
edvakf / Rpc.scala
Last active August 29, 2015 14:24
ThriftRpc
import com.ning.http.client.providers.netty.NettyResponse
import org.apache.thrift.protocol.TBinaryProtocol
import org.apache.thrift.transport.{TMemoryInputTransport, TMemoryBuffer, THttpClient}
import org.apache.thrift.{TException, TServiceClient, TServiceClientFactory}
import play.api.Play.current
import play.api.libs.ws.WS
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import scala.util.control.NonFatal
@edvakf
edvakf / mymaybe.hs
Created May 18, 2015 11:41
mymaybe.hs
data MyMaybe a = MyNothing | MyJust a deriving (Show)
instance Functor MyMaybe where
fmap f MyNothing = MyNothing
fmap f (MyJust a) = MyJust (f a)
instance Applicative MyMaybe where
pure x = MyJust x
MyNothing <*> _ = MyNothing
_ <*> MyNothing = MyNothing
@edvakf
edvakf / mylist.hs
Created May 18, 2015 11:40
mylist.hs
data MyList a = MyEmpty | MyCons a (MyList a) deriving (Show)
instance Functor MyList where
fmap f MyEmpty = MyEmpty
fmap f (MyCons x xs) = MyCons (f x) (fmap f xs)
instance Applicative MyList where
pure x = MyCons x MyEmpty
MyEmpty <*> _ = MyEmpty
_ <*> MyEmpty = MyEmpty
@edvakf
edvakf / rt-router.php
Last active August 29, 2015 14:18
フレームワークではなくライブラリとして使うPHPのルーター案
<?php
if ($m = RT::get('/works/:id' /*pathパターン*/, [':id:uint' /*pathのパラメータ*/])) {
getWorks($m[':id']);
} else if ($m = RT::get('/works/', ['page:uint:1' /*GETパラメータ。デフォルト1*/, 'type:string:' /*GETパラメータ。デフォルト空文字*/, 'tags:string[]' /*GETパラメータ。配列のみ受け取る。デフォルトは空配列?*/])) {
getWorks($m['page'], $m['type'], $m['tags']);
object ProcessEnumerator {
// wraps a ProcessBuilder with Play's Enumerator
// and executes the process in Future
// so that the process' output can be streamed
def apply(process: ProcessBuilder): Enumerator[String] = {
val in = new PipedInputStream()
val out = new PipedOutputStream(in)
Future(process.#>(out).run())
val reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))
@edvakf
edvakf / go.md
Last active June 28, 2017 02:46

golang使いまわせる処理一覧

md5

func md5hash(text []byte) string {
	h := md5.New()
	h.Write(text)
	return fmt.Sprintf("%x", h.Sum(nil))
}
@edvakf
edvakf / heapq.go
Created October 27, 2014 01:07
heapq.go
package heapq
import "errors"
type intMaxHeap struct {
buf []int
length int
}
func (h *intMaxHeap) Cap() int {