This file contains 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 file; | |
import java.io.File; | |
import java.io.FileFilter; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.concurrent.BlockingQueue; | |
import java.util.concurrent.SynchronousQueue; | |
import java.util.concurrent.TimeUnit; |
This file contains 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 lambda; | |
public class FinalTest { | |
public static Runnable create(final int limit) { | |
return new Runnable() { | |
@Override | |
public void run() { | |
for (int i = 0; i < limit; ++i) { |
This file contains 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
module Enumerable | |
def n_min(n) | |
raise "Illegal argument: #{n.inspect}" unless n > 0 | |
mins = [] | |
each do |item| | |
mins.push item | |
mins.sort! | |
mins.pop if mins.size > n |
This file contains 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/bash | |
# create fifo and ensure cleanup on exit | |
fifo=fifo-$$ | |
mkfifo "$fifo" | |
trap 'rm "$fifo"' 0 | |
# other command | |
cat -n <"$fifo" & | |
bg=$! |
This file contains 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/ruby | |
def trace(old, new) | |
printf "%p old=%p new=%p\n", caller[0], old, new | |
end | |
def fetch(io) | |
s = io.gets and s.chomp! | |
s | |
end |
This file contains 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 'socket' | |
DELIMITER = "\x04".freeze | |
server = TCPServer.new '127.0.0.1', 5556 | |
printf "Server at port %p\n", server.addr | |
loop do | |
Thread.new(server.accept) do |client| | |
printf "Client %p START\n", client |
This file contains 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
class Foo | |
def self.method_added(m) | |
t = Thread.current | |
unless t[:_hook] | |
t[:_hook] = true | |
begin | |
alias_method "_#{m}", m |
This file contains 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
class Grid | |
def initialize(dim_x, dim_y) | |
@x = dim_x | |
@y = dim_y | |
@store = {} | |
end | |
def [](coord) | |
@store[validate_coord coord] |
This file contains 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
HTML_TAG_REPLACEMENTS = { | |
'br' => "\n", | |
} | |
HTML_QUOTE_REPLACEMENTS = { | |
'quot' => '"', | |
'amp' => '&', | |
} | |
def strip_html(str, tag = HTML_TAG_REPLACEMENTS, quot = HTML_QUOTE_REPLACEMENTS) | |
str.gsub %r{ |
This file contains 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/ruby | |
# Implementation of a bit set which stores membershio in binary | |
# Strings managed in chunks. | |
class BitSet | |
ZERO = "\000".encode(Encoding::BINARY).freeze | |
DEFAULT_SEGMENT_SIZE = 1024 * 1024 | |
# Create the BitSet instance. If max_num is given, we preallocate | |
# as much memory as needed. |