Skip to content

Instantly share code, notes, and snippets.

View okumin's full-sized avatar

okumin okumin

View GitHub Profile
@okumin
okumin / FeedParser
Created August 12, 2012 19:17
フィードをパースするクラス
<?php
/**
* Copyright (c) 2012 okumin, http://okumin.com/
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
@okumin
okumin / unionfind.py
Created September 15, 2012 13:30
Union find
# -*- coding: utf-8 -*-
class UnionFind:
def __init__(self):
self.refs = {}
def find(self, x):
if x in self.refs:
ref = self.find(self.refs[x])
self.refs[x] = ref
<?php
require_once "twitteroauth/twitteroauth/twitteroauth.php";
$client = new TwitterOauth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$next_cursor = -1;
$target = "";
$f = fopen("./hogehoge.txt", "w");
while($next_cursor != 0) {
for($i = 0 ; $i < 5; $i++) {
@okumin
okumin / bulk.md
Last active August 29, 2015 14:06
Bulk insert into Redis

Bulk insert into Redis

script

import java.io.File
import java.io.PrintWriter
import io.gatling.redis.util.RedisHelper

def generateList(): Unit = {
@okumin
okumin / akka-persistence.md
Created September 28, 2014 08:55
akka-persistenceのプラグインをつくろう
@okumin
okumin / Exercises.md
Last active August 29, 2015 14:14
Purely Functional Data Structures: 第2章

Excercises

スケイラですみません(◞‸◟) もちがってる可能性があります。

Exercise 2.1

def suffixes[A](xs: List[A]): List[List[A]] = xs match {
  case Nil => List(Nil)
class MofuSpec extends WordSpec with GeneratorDrivenPropertyChecks {
def measure(seq: Seq[Int], heap: Heap[Int]): Unit = {
val h = seq.foldLeft(heap) { (h, x) => h.insert(x) }
val h2 = seq.foldLeft(h) { (h, x) => h.deleteMin() }
assert(h2.isEmpty)
}
"mofu" should {
"fumo" in {
val initial = 300000

8 Lazy Rebuilding

  • 1章: 導入
  • 2〜3章: 関数型データ構造の基本的な部分についての紹介
  • 4〜7章: 遅延評価と償却の関係 ← ここまでやった
  • 8〜11章: 関数型データ構造を設計するための汎用的なテクニック ← 残りはこの部分

この章でやること

  • batch rebuilding
def findMofu(id: Int): Future[CacheError | IOError | NotFound, Mofu] = ???
def createMofu(mofu: Mofu): Future[CacheError | IOError | DuplicateError, Mofu] = ???

val result = findMofu(5).recoverWith {
  case NotFound =>
    createMofu(Mofu(5)).recoverWith {
      case DuplicateError => UnknownError
    }
}

Summary

MySQL

/ persistAsync persist recover
akka-2.3 1547 7964 450
akka-2.4-rc1 1504 9051 390
akka-2.4-batched 702 8806 410
akka-2.4-seq 615 11711 402