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
func BidirectionalCopy(conn net.Conn, channel net.Conn) { | |
start := time.Now() | |
var done = make(chan int, 1) | |
go copy("to ssh channel", conn, channel, done) | |
go copy("from ssh channel", channel, conn, done) | |
written := <-done | |
conn.Close() | |
channel.Close() |
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
func copy(dest io.Writer, src io.Reader) int64 { | |
// If dest has a ReadFrom method, we use that. This gives us zero copy | |
// when copying between sockets, for example. | |
if reader_from_dest, ok := dest.(io.ReaderFrom); ok { | |
written, _ := reader_from_dest.ReadFrom(src) | |
return written | |
} | |
buf := make([]byte, 1024 * 16) |
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 "rubygems" | |
require "ruby2ruby" | |
require 'parse_tree' # gem ParseTree | |
#require 'ruby2ruby' | |
#require 'sexp_processor' | |
#require 'unified_ruby' | |
def Continuation.create(*args, &block) | |
cc = nil |
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
/* | |
* Save this file as "kvs.js". | |
* | |
* Usage: | |
* | |
* node kvs.js set foo bar | |
* | |
* ... sets the "foo" entry to bar, and overwrites the kvs.js script with the updated data. | |
* | |
* node kvs.js set foo bar |
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
$count = 1000000 | |
def bench0(&block) | |
r = Time.now | |
$count.times do end | |
Time.now - r | |
end | |
def bench1(&block) | |
r = Time.now | |
$count.times(&block) |
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
brew install dovecot | |
sudo dscl . -create /Users/_dovecot | |
sudo dscl . -create /Users/_dovecot UserShell /usr/bin/false | |
sudo dscl . -create /Users/_dovecot UniqueID 104 | |
sudo dscl . -create /Users/_dovecot PrimaryGroupID 104 | |
sudo dscl . -create /Users/_dovecot NFSHomeDirectory /var/empty | |
sudo dscl . -passwd /Users/_dovecot '' |
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 File | |
class Fingerprint | |
attr_reader :inode | |
def initialize(path) | |
@path = path | |
@inode = File.stat(@path).ino rescue nil | |
end | |
def ==(other) |
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 ActiveRecord::Associations::AssociationCollection | |
# Does the AssociationCollection contains entries? | |
def empty?(*args) | |
if fetch_first_or_last_using_find?(args) | |
if !args.last.is_a?(Hash) | |
args.push :select => "1" | |
elsif (!args.last[:select]) | |
args.last = { :select => "1" }.update(args.last) | |
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
module BetterObjectIdWarning | |
def self.activate | |
return if @activated | |
@activated = true | |
Object.class_eval { | |
def id | |
return object_id if @in_object_id_warning | |
@in_object_id_warning = true |
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 ThinkingSphinx::FacetIdsSearch < ThinkingSphinx::FacetSearch | |
def initialize(*args) | |
options = args.extract_options! | |
@fast_facet_names = options.delete(:facets) || raise("Missing facet names") | |
@fast_facet_names = [ @fast_facet_names ].flatten.map(&:to_s) | |
args.push options | |
super *args | |
end | |
OlderNewer