Skip to content

Instantly share code, notes, and snippets.

@jeffomatic
jeffomatic / gist:1997346
Created March 7, 2012 23:47
factual-ruby-driver monkey patch for namespace lookup
require 'factual/query/crosswalk'
unless Factual::Query::Crosswalk.instance_methods.include?(:namespace)
class Factual
module Query
class CrosswalkNamespace < Base
def initialize(api, params = {})
@path = "places/crosswalk"
@action = :crosswalk
// Remove the overlay node from the DOM
$('#overlay').parent().remove();
// Restore the scrollbars
$('html').css( "overflow", "scroll" );
@jeffomatic
jeffomatic / gist:2439567
Created April 21, 2012 21:00
Blog excerpt, Bloodrayne metrics, JSON message format
[
"tableName",
[
[ "field1", "type", "value" ],
[ "field2", "type", "value" ],
...
]
]
@jeffomatic
jeffomatic / gist:2439573
Created April 21, 2012 21:02
Blog: Bloodrayne Metrics, Code: metrics usage example
void RecordLevelEndData()
{
// Grab in-game data
float fHealth = GetPlayerHealth();
unsigned nScore = GetPlayerScore();
// Get an object that sends data to the
// "performance" table
wfStat* pStat = wfMetrics::Create( "performance" );
@jeffomatic
jeffomatic / gist:2439580
Created April 21, 2012 21:03
blog: Bloodrayne metrics, code: metrics data example
[
"performance",
[
// Project-specific metadata
[ "svn_revision", "s", "195388" ],
[ "platform", "s", "ps3" ],
[ "system_id", "s", "08EB4EEF3C76C468" ],
[ "timestamp", "d", "__server_timestamp__" ],
// Programmer-specified data
@jeffomatic
jeffomatic / gist:2522979
Created April 29, 2012 00:52
Blog: Redis as a mutex service, Code: redis_spinlock
# CAVEAT EMPTOR: This is excerpted code that I pulled out of context,
# re-arranged, renamed the variables of, and otherwise dicked around with
# a lot without having put it back into a Ruby interpreter, so it's
# possible that there's some gnarly typo or bug in here. In short, don't
# cut-and-paste this code.
class AlreadyLockedException < Exception; end
def redis_spinlock(redis, lock_handle, opts = {}, &critical_section)
lock_set = opts[:lock_set] || 'named_locks'
@jeffomatic
jeffomatic / gist:2527662
Created April 29, 2012 03:07
Blog: Redis as a mutex service, Code: cache_lookup
# CAVEAT EMPTOR: This is excerpted code that I pulled out of context,
# re-arranged, renamed the variables of, and otherwise dicked around with
# a lot without having put it back into a Ruby interpreter, so it's
# possible that there's some gnarly typo or bug in here. In short, don't
# cut-and-paste this code.
# In our example, "cache" is some resource accessible by all of our
# processes and provides a run-time interface similar to Ruby's Hash
# class.
def cache_lookup(redis, resource_handle, cache, &run_on_cache_miss)
@jeffomatic
jeffomatic / gist:3233944
Created August 2, 2012 05:22
blog: jl_signal, code: usage example
// Declare and instantiate a signal for functions that take a
// single char arg.
JL_SIGNAL( char ) oKeyPressSignal;
// Two objects of unrelated type.
Piano oPiano; // plays notes
Transcriber oTranscriber; // generates text logs
// Lets assume the following instance method declarations:
//
@jeffomatic
jeffomatic / gist:3233989
Created August 2, 2012 05:28
blog: jl_signal, code: inheritance-based delegate
// For the purposes of this example, let's assume our slots only accept
// one parameter.
template< typename TSlotParam >
class Delegate
{
public:
virtual ~Delegate() {}
virtual void Invoke( TSlotParam v ) = 0;
};
@jeffomatic
jeffomatic / gist:3234045
Created August 2, 2012 05:33
blog: jl_signal, code: catastrophic signal connection
JL_SIGNAL() oSignal;
void f1() { oSignal.Disconnect( &f1 ); }
void f2() { /* do something */ }
oSignal.Connect( &f1 );
oSignal.Connect( &f2 );
oSignal.Emit();