This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package clj; | |
import java.util.concurrent.ConcurrentHashMap; | |
import java.util.concurrent.ConcurrentMap; | |
/** | |
* The cache works with as few locking as possible. Lookup is done in two steps | |
* on cache miss: | |
* <ol> | |
* <li>On a cache miss a retriever is inserted into the cache which will obtain |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pathname' | |
class Pathname | |
# Insert directory parts for leading characters of the basename, | |
# an optional integer argument specifies the limit. | |
def distribute(levels = nil) | |
dir, basename = split | |
name, ext = basename.to_s.split /\./, 2 | |
pn = dir |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
REP = 100_000 | |
dat = [1, 2, 3, 2, 4, 5, 4, 4] | |
Benchmark.bmbm 25 do |x| | |
x.report "Jan low level" do | |
REP.times do | |
dups = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
# create some data | |
DAT = (3..7).map do |i| | |
Array.new(10 ** i) { rand 100 } | |
end | |
2.times do | |
Benchmark.bm 15 do |b| | |
DAT.each do |ar| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package nio; | |
import java.nio.ByteBuffer; | |
import java.util.Random; | |
public final class BBCompactPerfTest { | |
private static final int SEQ = 1000000; | |
private static final int REP = 100; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'monitor' | |
# Simple semaphore implementation using Monitor and ConditionVariable | |
class Semaphore | |
def initialize(initial_value = 0) | |
@val = initial_value | |
@lock = Monitor.new | |
@available = ConditionVariable.new | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby19 | |
# Read a directory tree and convert newer sources | |
# on the fly. | |
require 'pathname' | |
EXTENSIONS=%w{.jpg .JPG} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/dash | |
# convert argument into human readable format | |
# argument must be numeric and without sign. | |
num=$1 | |
expr "$num" : '[0-9]\+$' >/dev/null || { echo "ERROR: must be digits only: '$num'">&2; exit 1;} | |
scale=3 # scale for bc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby19 | |
require 'set' | |
keys = File.read(ARGV.shift).scan(/\w+/).to_set | |
index = Hash.new {|h,word| h[word] = Set.new} | |
ARGF.each do |line| | |
line.scan /\w+/ do |word| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -fe | |
# Do a complete apt update to the current | |
# state of affairs. | |
test `id -u` -eq 0 || exec sudo "$0" "$@" | |
set -x | |
apt-get update | |
apt-get autoremove --yes |