Skip to content

Instantly share code, notes, and snippets.

View headius's full-sized avatar

Charles Oliver Nutter headius

View GitHub Profile
com.hazelcast.core.SampleHazelcast.getTopic("default").instance_eval{addMessageListener{|m|puts "Message received = "+m};publish "message-object"}
@headius
headius / hazel2.rb
Created October 7, 2015 22:05 — forked from enebo/hazel2.rb
topic = com.hazelcast.core.SampleHazelcast.getTopic "default"
topic.addMessageListener { |msg| puts "Message received = " + msg }
topic.publish "my-message-object"
@headius
headius / Gemfile
Last active August 29, 2015 14:25 — forked from brixen/Gemfile
source 'https://rubygems.org'
gem 'sequel'
gem 'progress_bar'
gem 'pg'
gem 'aws-sdk'
gem 'oga'
/**
* Best attempt at breaking the code of arity values! We figure out how many fixed/required parameters
* must be supplied. Then we figure out if we need to mark the value as optional. Optional is indicated
* by multiplying -1 * (fixed + 1). Keyword args optional and rest values can indicate this optional
* condition but only if no required keyword arguments are present.
*/
public int arityValue() {
int oneForKeywords = requiredKwargs > 0 ? 1 : 0;
int fixedValue = pre() + post() + oneForKeywords;
boolean hasOptionalKeywords = kwargs - requiredKwargs > 0;
@headius
headius / blurgh
Last active August 29, 2015 14:13 — forked from enebo/blurgh
# ignores kwargs
if (rest)
postIndex = args.length - postCount;
elsif (preCount + optLength <= args.length)
postIndex = preCount + optLength
else
optCount = args.length - preCount - postCount
postIndex = preCount + optCount
end
@headius
headius / test.rb
Last active January 2, 2016 10:09 — forked from rosenfeld/output.txt
Example utility for doing synchronized updates of instance variables.
module Atomically
GLOBAL_MUTEX = Mutex.new
def atomically(varname, &block)
# check first to avoid locking if possible
instance_variable_get(varname) || ___atomically_update___(varname, &block)
end
def ___atomically_update___(varname)
# lock and do ||= update
___mutex___.synchronize do
require 'benchmark'
class Request
def initialize(first, last, city, state, country)
@hash =
{
'first'.freeze => first,
'last'.freeze => last,
'city'.freeze => city,
'state'.freeze => state,
@headius
headius / kew.rb
Last active December 16, 2015 14:29 — forked from ahoward/kew.rb
class Kew
require 'socket'
def initialize
@in, @out = IO.pipe
end
def push(object)
buf = Marshal.dump(object)
@out.puts(buf.size)
@headius
headius / 0-README.md
Last active December 15, 2015 19:09 — forked from jstorimer/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.

@headius
headius / heh.rb
Created April 26, 2012 16:09 — forked from enebo/heh.rb
java_import some.package.DialogListener
facebook.authorize(self, [].to_java(:string), MyListener.impl { def onComplete(values); ... end; ...)