Skip to content

Instantly share code, notes, and snippets.

@clr
clr / access.log
Created October 30, 2012 22:21
Wide Finder ErlangGames
208.115.113.86 - - [29/Oct/2012:17:11:45 -0700] "GET /Case%20History/new_page_1.htm HTTP/1.1" 404 89 "-" "Mozilla/5.0 (compatible; Ezooms/1.0; [email protected])" "dakotalargeanimalclinic.com"
218.30.103.53 - - [29/Oct/2012:17:37:02 -0700] "GET /robots.txt HTTP/1.1" 200 54 "-" "Sogou web spider/4.0(+http://www.sogou.com/docs/help/webmasters.htm#07)" "www.dakotalargeanimalclinic.com"
208.115.111.70 - - [29/Oct/2012:17:46:47 -0700] "GET /robots.txt HTTP/1.1" 200 54 "-" "Mozilla/5.0 (compatible; Ezooms/1.0; [email protected])" "dakotalargeanimalclinic.com"
74.125.182.28 - - [29/Oct/2012:17:54:04 -0700] "GET /Equine_Nutrition/teeth_check_horse.html HTTP/1.1" 200 4111 "http://www.google.com/search" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.4 (KHTML, like Gecko; Google Web Preview) Chrome/22.0.1229 Safari/537.4" "www.dakotalargeanimalclinic.com"
70.238.130.51 - - [29/Oct/2012:17:54:04 -0700] "GET /photo_gallery/black_cat_mouth_open.JPG HTTP/1.1" 200 632815 "http://www.google.com/search?num=10&hl=en&sit
@clr
clr / gist:3944385
Created October 24, 2012 06:29
Application Development on Riak: Getting Started

The CRUD model is a well-known pattern in application development. In the CRUD lingo, you can Create, Read, Update, or Delete your data object. This lines up well with the Resource Access Pattern, with which many are familiar as a component of a RESTful API.

The Resource Access Pattern is very popular because of its simplicity. Writing a Resource Access Pattern on top of Riak is really simple too. Riak uses a RESTful HTTP syntax, and maps the operations to CRUD like so:

CRUD Verb HTTP Verb URL Description
Create PUT /buckets/resource-type/keys/key-name Make a new resource at the given key and store the submitted data.
POST /buckets/resource-type Make a new resource and get the unique key generated for it.
Read GET /buckets/resource-type/keys/key-name Get the resource data back for the given key.
Update PUT /buckets/resource-type/keys/key-name Store the submitted data for the given key.
@clr
clr / gist:3908781
Created October 17, 2012 22:36
Dmitri's blog post

Rails Rumble with Riak and Ripple - Three Developers and a Lot of Rs

This past weekend, Bryce Kerley, David Andersen, and I had the pleasure and honor of participating in Rails Rumble 2012. This event is a 48-hour competition to design, build and deploy a web application in Ruby and Rails (or one of the other Rack-based web framework). Developing at this pace is grueling, to say the least (especially since it took place immediately after we all flew home from Ricon 2012), but also really exciting. You get the whole product cycle experience, from design to feature releases to testing and QA, all in one intense weekend.

Our application is Brainload. It's a social flashcard/memorization aid tool, which lets users create, share and review flash cards on various topics (useful for memorizing programming language syntax, new APIs, school exam preparations, and building foreign language vocabulary). You can launch

Rolling with Eventual Consistency

Keywords: riak, ripple, statistics, eventually consistent, race condition, CRDT, map/reduce, analytics

In a previous post I wrote about the different mindset that a software engineer should have when building for a key-value database as opposed to a relational database. When working with a relational database, you describe the model first and then query the data later. With a key-value database, you focus first on what you want the result of the query to look like, and then work backward toward a model.

As an example, I described averaging some value:

"In a SQL database, we can just call average() on that column, and it will compute the answer at query time. In a key-value store, we can add logic in the application layer to catch the object before it enters Riak, fetch the average value and number of included elements from Riak, compute the new rolling average, and save that answer back in Riak

<!DOCTYPE html>
<html lang="en">
<head>
<title>WebGLiak</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
color: #808080;
font-family:Monospace;
require File.expand_path('../helper', __FILE__)
class TestExample < Test::Unit::TestCase
def setup
threads = []
3.times do |line|
threads << Thread.new do
data = File.readlines(File.join(ROOT_DIR,'test','data'))[line]
data.split(',').each do |value|
DataPointDocument.create(:value => value.to_i)
@clr
clr / Rakefile
Created August 10, 2012 17:21
ubigraph thingie
gem 'bundler'
require 'bundler'
require 'riak'
require 'xmlrpc/client'
require 'rake'
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
@clr
clr / prime_finder.erl
Created May 23, 2012 01:21
Prime Finder ErlangGames
-module(prime_finder).
-include_lib("eunit/include/eunit.hrl").
-export([roots/1,timer/3]).
roots_test_() ->
[
?_assertEqual([3, 7], roots(21)),
?_assertEqual([576019, 576029], roots(331803648551)),
?_assertEqual([2, 2, 576019, 576029], roots(1327214594204)),
?_assertEqual([179425661, 179426129], roots(32193651796496269))
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
210.152.135.197 NPVS20951-STEPIDC step1idc kita kita-gate
192.168.66.198 NPVS20951-FP01IDC s1fp01idc fp01idc.s1
192.168.66.199 NPVS20951-FP02IDC s1fp02idc fp02idc.s1
192.168.66.200 NPVS20951-FP03IDC s1fp03idc fp03idc.s1
192.168.66.201 NPVS20951-FP04IDC s1fp04idc fp04idc.s1
192.168.66.207 NPVS20951-FP05IDC s1fp05idc fp05idc.s1
## Name of the riak node
-name riak@<<servername>>
## Cookie for distributed erlang. All nodes in the same cluster
## should use the same cookie or they will not be able to communicate.
-setcookie riak
## Heartbeat management; auto-restarts VM if it dies or becomes unresponsive
## (Disabled by default..use with caution!)
##-heart