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 / 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 / mac.ahk
Last active February 28, 2022 00:20
Example of AutoHotkey. Mac like keybinds
;================================================================
;mac風キーバインド(Cmd+Q) など
; https://gist.github.com/daimatz/1385713
;================================================================
#InstallKeybdHook
#UseHook
;================================================================
;関数
@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 {
@daimatz
daimatz / dictionary-app.el
Created September 20, 2011 01:43
Emacs Lisp Tips
;; Mac の Dictionary.app を、 Emacs の popwin.el から使う
;; dict.py is from http://sakito.jp/mac/dictionary.html
(defun dictionary ()
"dictionary.app"
(interactive)
(let ((word (if (and transient-mark-mode mark-active)
(buffer-substring-no-properties (region-beginning) (region-end))
(read-string "Dictionary: ")))
(cur-buffer (current-buffer))
(tmpbuf " * dict-process *"))
@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"