Skip to content

Instantly share code, notes, and snippets.

View barinek's full-sized avatar

Barinek barinek

  • Initial Capacity
  • Boulder, CO
View GitHub Profile
@barinek
barinek / ara's isolation
Created March 31, 2010 21:04
ara's isolation
a.rb
require 'rubygems'
require 'mysql'
loop do
# Datum.transaction do
connection = Mysql.new('localhost', 'root', 'password', 'ara_example')
connection.autocommit false
@barinek
barinek / Net::HTTP Mock
Created March 20, 2010 14:36
Net::HTTP Mock
http_mock = mock('Net::HTTPResponse')
http_mock.stubs(:code => '200', :body => 'response body', :message => 'response message')
Net::HTTP::Post.any_instance.expects(:body=).with("post body").once
Net::HTTP.any_instance.expects(:request).with(anything).once.returns(http_mock)
@barinek
barinek / ohm models with zset
Created February 21, 2010 18:01
ohm models with zset
module Ohm
class Model
def self.zset(name, model = nil)
attr_zset_reader(name, model)
collections << name unless collections.include?(name)
end
def self.attr_zset_reader(name, model)
define_method(name) do
@barinek
barinek / basic mvn template
Created February 17, 2010 15:58
basic mvn template
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>template</groupId>
<artifactId>template</artifactId>
<version>1.0</version>
#!/usr/bin/env ruby
require 'rubygems'
require 'net/http'
require 'uri'
class SimpleCometClient
def initialize()
@uri = URI.parse('http://www.localhash.com/publishers/myspace/stream')
@http = Net::HTTP.new(@uri.host, @uri.port)
@barinek
barinek / dynamic typing
Created February 8, 2010 21:17
dynamic typing
def foo(first, second = first, third = second.size)
[first, second, third]
end
puts foo("hello")
create trigger activity_duplicate_check before insert on activities
for each row begin
set @activity_id=new.activity_id;
set @poll_result_id=new.poll_result_id;
set @created_at=new.created_at;
set @data_collector_id=new.data_collector_id;
begin
declare found_ids int default 0;
declare found_created_at datetime default 0;
public Set<OutboundTask> add(LinkedHashSet<T> itemsToFilter) {
LinkedHashMultimap<Stream<T>, T> filteredItems = Multimaps.newLinkedHashMultimap();
Set<OutboundTask> outboundTasks = Sets.newHashSet();
for (T filterable : itemsToFilter) {
filterAction(filteredItems, filterable);
filterActor(filteredItems, filterable);
filterTag(filteredItems, filterable);
filterTo(filteredItems, filterable);
filterRegarding(filteredItems, filterable);
class ActiveRecord::ConnectionAdapters::MysqlAdapter
def create_partitioned_table(table_name, &block)
partition_sql = <<-sql
ENGINE=InnoDB AUTO_INCREMENT=610925 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
partition by range (to_days(created_at))
(
partition p_0 values LESS THAN (to_days('2000-01-01')),
sql
partitions = (-4..4).collect do |i|
@barinek
barinek / LRU Memory Store
Created January 19, 2010 00:43
LRU Memory Store
class LRUMemoryStore < ActiveSupport::Cache::Store
def initialize(max_size = 1000)
@max_size = max_size
@data = {}
@lru = []
end
def read(name, options = nil)
super