Skip to content

Instantly share code, notes, and snippets.

@daimatz
daimatz / CityHash_1_0_3.java
Last active July 14, 2023 06:36
Java implementation of CityHash 1.0.3 that behaves as same hash function as BigQuery.
/*
* Copyright (C) 2012 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
@daimatz
daimatz / Build.scala
Last active August 29, 2015 14:05
sbt assembly for Finatra application
import sbt._
import sbt.Keys._
import sbtassembly.Plugin.{MergeStrategy, assemblySettings, defaultMergeStrategy}
import sbtassembly.Plugin.AssemblyKeys.{assembly, mergeStrategy}
import sbtassembly.AssemblyUtils
object AppBuild extends Build {
lazy val app = Project(
id = "app",
base = file("app"),
@daimatz
daimatz / httpd.py
Created July 23, 2014 17:34
SimpleHTTPServer with custom headers
#!/usr/bin/env python
import SimpleHTTPServer
import BaseHTTPServer
import sys
"""
Usage:
python httpd.py [port] [additional headers ...]
@daimatz
daimatz / Main.java
Last active May 10, 2021 09:35
QPS Control example
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Random;
class Main {
object Main {
def main(args: Array[String]) = {
val data = testData()
val start1 = System.currentTimeMillis()
data.foreach(isValidIpFormat1)
val end1 = System.currentTimeMillis()
println("1: " + (end1 - start1))
val start2 = System.currentTimeMillis()
@daimatz
daimatz / Lambda.scala
Created January 28, 2014 06:44
Lambda を渡す。 g のほうがわずかに速いか
object Main {
def main(args: Array[String]) {
val to_s: Int => String = _.toString
val start = System.currentTimeMillis()
(0 until 5000000).foreach { i =>
f(to_s, i)
// g(i)
}
val end = System.currentTimeMillis()
println(end - start)
@daimatz
daimatz / CaseBench.scala
Last active January 4, 2016 08:28
h は遅い
import scala.collection.mutable.ArrayBuffer
import scala.util.Random
object Main {
def main(args: Array[String]) {
val data = testdata()
val start = System.currentTimeMillis()
val ret = f(data) // g, h
val end = System.currentTimeMillis()
println(ret)
case class User(username: String, password: String)
trait UserRepositoryComponent {
val userRepository: UserRepository
// ordinal class
class UserRepository {
def authenticate(user: User): User = {
println("authenticating user: " + user)
user
}
@daimatz
daimatz / github-wiki-toc.user.js
Last active December 28, 2015 09:48
GitHub Wiki TOC JS
// ==UserScript==
// @name GitHub Wiki TOC
// @namespace http://www.daimatz.net/
// @version 0.11
// @description Add TOC to GitHub Wiki Page
// @include https://github.com/*/*/wiki/*
// @license MIT License(http://en.wikipedia.org/wiki/MIT_License)
// ==/UserScript==
(function() {
@daimatz
daimatz / thread-proc.rb
Created October 25, 2013 04:06
Proc オブジェクトを単純に並列実行する例
f = Proc.new { puts "start f"; sleep 10; puts "end f" }
g = Proc.new { puts "start g"; sleep 5 ; puts "end g" }
puts "start"
[f, g].map{ |prc| Thread.new{ prc.call } }.map(&:join)
p Thread.list
puts "all end"