Skip to content

Instantly share code, notes, and snippets.

@kotas
kotas / benchmark.rb
Created July 9, 2014 11:13
Timeline using Redis sorted set
require "benchmark"
require "redis"
require "hiredis"
require "redis/connection/hiredis"
redis = Redis.new(timeout: 60)
redis.select(10)
if ARGV.include?("create")
puts "Creating feeds"
# ID Generator for entities
#
# ## ID Generation
# It uses Twitter's Snowflake algorithm for ID generation.
# https://github.com/twitter/snowflake
#
# Our ID is an unsigned 64-bit integer that consists of four elements:
#
# - Timestamp: 41 bits, milliseconds from EPOCH_TIME
# - Shard ID: 12 bits, logical shard ID
@kotas
kotas / phpbrew.rb
Created February 27, 2014 15:57 — forked from dataich/phpbrew.rb
require 'formula'
class Phpbrew < Formula
head 'https://raw.github.com/c9s/phpbrew/master/phpbrew'
homepage 'https://github.com/c9s/phpbrew'
def install
system "chmod a+x phpbrew"
system "mkdir -p #{prefix}/bin"
system "cp phpbrew #{prefix}/bin"
# -*- coding: utf-8 -*-
from itertools import repeat
foldr = lambda f, xs: reduce(lambda x, y: f(y, x), xs)
applyn = lambda f: lambda n, times: foldr(f, repeat(n, times))
towerN = lambda n: pow if n == 1 else applyn(towerN(n - 1))
tower1 = towerN(1)
tower2 = towerN(2)
# -*- coding: utf-8 -*-
try:
import bisect
except:
pass
def main():
(num_items, num_days) = map(int, raw_input().split())
prices = sorted(int(raw_input()) for n in xrange(num_items))
module Resource {
export declare var html: {
[name: string]: string;
};
export declare var css: {
[name: string]: string;
};
var loadedCSS: { [name: string]: boolean } = {};
@kotas
kotas / genpass.py
Created January 4, 2012 08:22
Password Generator for Mac OSX
#!/usr/bin/python
# -*- encoding: utf-8 -*-
"""
Password Generator for Mac OSX
Compatible with http://www.hashapass.com/
"""
import sys
import os
@kotas
kotas / a.php
Created February 8, 2011 17:52
require_once vs autoload
<?php
function benchmark_using_require_once() {
require_once 'b.php';
B::noop();
}
function benchmark_using_autoload() {
C::noop();
}
@kotas
kotas / up.sh
Created February 3, 2011 14:21
cd up-forward
# INSTALL:
# alias up='source /path/to/up.sh'
#
# USAGE:
# $ up = cd ..
# $ up 2 = cd ../..
# $ up 3 = cd ../../..
# $ up foo = cd to the nearest `foo' directory in the ancestor path.
# ex) At /foo/bar/baz/ , then cd to /foo/
# ex) At /foo/bar/foo/baz/ , then cd to /foo/bar/foo/
@kotas
kotas / gist:580871
Created September 15, 2010 15:15
CotEditor をシェルから起動するの
#!/usr/bin/python
#
# Shell command for CotEditor
#
import sys
import os
import os.path
files = [os.path.abspath(s) for s in sys.argv[1:]]