Anuj Dutta andhapp

View MySingleton.js
1 2 3 4 5 6 7 8 9 10
define(function(){
var instance = null;
 
function MySingleton(){
if(instance !== null){
throw new Error("Cannot instantiate more than one MySingleton, use MySingleton.getInstance()");
}
this.initialize();
}
View standalone.rb
1 2 3 4 5 6 7 8 9 10
#!/usr/bin/env ruby
 
puts "Run this in another terminal:"
puts ""
puts " sudo ./trace-gc-standalone.sh #{$$}"
puts ""
puts "... wait for the 'Ready!' message, switch back here and press enter to start."
 
GC::Profiler.enable
$stdin.gets
View lib-rails_compatible_simple_delegator.rb
1 2 3 4 5 6 7 8 9 10
# See:
# * http://thepugautomatic.com/2014/03/simpledelegator-autoloading-issues-with-rails/
# * https://groups.google.com/forum/#!topic/rubyonrails-core/PjGUK72BmFA
# * https://gist.github.com/henrik/9314943
 
require "delegate"
 
class RailsCompatibleSimpleDelegator < SimpleDelegator
def self.const_missing(name)
if ::Object.const_defined?(name)
View stub v should_receive
1 2 3 4 5 6 7 8 9 10
## stub v should_receive
 
## This is just a simple example to show uses of stub, and should_receive. Imagine you have the following code:
 
# topic.rb
class Topic < ActiveRecord::Base
has_many :stories
 
def add_story(story)
unless exists? story
View 0-README.md

This is a proof-of-concept of a couple of concurrent data structures written in Ruby.

The implementations are heavily commented for those interested. There are benchmarks (with results) included below. The results are interesting, but, as always, take with a grain of salt.

Data structures

AtomicLinkedQueue is a lock-free queue, built on atomic CAS operations.

View tracepoint.rb
1 2 3 4 5 6 7 8 9 10
class Foo
def self.foo; end
def foo; end
end
 
tp = TracePoint.new("call") do |trace|
p [trace.defined_class, trace.method_id, trace.event, trace.lineno]
end
 
tp.enable
View development.txt
1 2 3 4 5 6 7 8 9 10
TracePoint:
disable 1
enable 1
 
Object:
require 1983
load_dependency 485
[] 18
hash 15
initialize 6
View proxy.rb
1 2 3 4 5 6 7 8
#!/usr/bin/env ruby
# A quick and dirty implementation of an HTTP proxy server in Ruby
# because I did not want to install anything.
#
# Copyright (C) 2009 Torsten Becker <torsten.becker@gmail.com>
 
require 'socket'
require 'uri'
View httpd_bench_python-SimpleHTTPServer.txt
1 2 3 4 5 6 7 8 9 10
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
 
Benchmarking 127.0.0.1 (be patient)
 
 
Server Software: SimpleHTTP/0.6
Server Hostname: 127.0.0.1
Server Port: 5000
View ruby-2.1.rb
1 2 3 4 5 6 7 8 9 10
class Foo
public def my_public_method
1 + 2
end
 
protected def my_protected_method
3 + 4
end
 
private def my_private_method
Something went wrong with that request. Please try again.