Skip to content

Instantly share code, notes, and snippets.

View taotetek's full-sized avatar
💭
Left for Gitlab. Microsoft still contracts with ICE.

taotetek taotetek

💭
Left for Gitlab. Microsoft still contracts with ICE.
View GitHub Profile
require 'rubygems'
require 'jmx'
require 'rmi'
class HitBean < RubyDynamicMBean
def initialize(name, desc)
super name, desc
@hits = 0
end
CREATE TABLE watched_table (
id SERIAL PRIMARY KEY,
value INT,
date_updated TIMESTAMP NOT NULL DEFAULT now()
);
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();
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
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...'
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
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();
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()
require 'benchmark'
a = "this"
b = "is"
c = "a"
d = "benchmark"
n = 100000000
Benchmark.bmbm do |x|
@taotetek
taotetek / timer_test.py
Created January 29, 2011 16:12
Sending timed signals to multiple processes using twisted and zeromq
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()