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 'jmx' | |
require 'rmi' | |
class HitBean < RubyDynamicMBean | |
def initialize(name, desc) | |
super name, desc | |
@hits = 0 | |
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
CREATE TABLE watched_table ( | |
id SERIAL PRIMARY KEY, | |
value INT, | |
date_updated TIMESTAMP NOT NULL DEFAULT now() | |
); |
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
CREATE FUNCTION notify_trigger() RETURNS trigger AS $$ | |
DECLARE | |
BEGIN | |
PERFORM pg_notify('watchers', TG_TABLE_NAME || ',id,' || NEW.id ); | |
RETURN new; | |
END; | |
$$ LANGUAGE plpgsql; | |
CREATE TRIGGER watched_table_trigger AFTER INSERT ON watched_table | |
FOR EACH ROW EXECUTE PROCEDURE notify_trigger(); |
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
def insert_thread(url) | |
insert_conn = DriverManager.get_connection(url) | |
cnt = 0 | |
while cnt < 10 | |
stmt = insert_conn.create_statement | |
stmt.execute("INSERT INTO watched_table (value) VALUES (1)") | |
cnt = cnt + 1 | |
sleep 3 | |
end | |
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
def listen_thread(url) | |
listen_conn = DriverManager.get_connection(url) | |
stmt = listen_conn.create_statement | |
stmt.execute("LISTEN watchers") | |
stmt.close | |
while true | |
sleep 1 | |
puts 'polling...' |
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 'bundler/setup' | |
require 'java' | |
require 'yaml' | |
$LOAD_PATH << 'vendor/jars/' | |
require 'postgresql-9.0-801.jdbc3.jar' | |
# set up our database connection to the example database... | |
java_import java.sql.DriverManager |
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
CREATE FUNCTION beam_me_up() RETURNS TRIGGER AS $$ | |
require 'yaml' | |
payload = new.to_yaml | |
$Plans["engage"] = PL::Plan.new("NOTIFY watchers, '#{payload}'") | |
$Plans["engage"].exec() | |
$$ LANGUAGE 'plruby'; | |
CREATE TRIGGER beam_me_up_trigger AFTER INSERT ON watched_table | |
FOR EACH ROW EXECUTE PROCEDURE beam_me_up(); |
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 'java' | |
require 'jredis-core-all-a.0-SNAPSHOT-jar-with-dependencies.jar' | |
java_import 'org.jredis.ri.alphazero.JRedisClient' | |
pool = [] | |
(1..1000).each do |thread_num| | |
pool << Thread.new(thread_num) { | |
jredis = JRedisClient.new() |
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 'benchmark' | |
a = "this" | |
b = "is" | |
c = "a" | |
d = "benchmark" | |
n = 100000000 | |
Benchmark.bmbm do |x| |
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
import zmq | |
from twisted.internet.task import LoopingCall | |
from twisted.internet import reactor | |
from datetime import datetime | |
from time import sleep | |
from multiprocessing import Process | |
class PulseTransmitter(object): | |
def __init__(self): | |
self.context = zmq.Context() |
OlderNewer