Skip to content

Instantly share code, notes, and snippets.

View thinkerbot's full-sized avatar

Simon Chiang thinkerbot

View GitHub Profile
@thinkerbot
thinkerbot / Vagrantfile
Created January 29, 2014 21:55
Kafka round trip perf test
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
#!/usr/bin/env ruby
# ruby dance_moves.rb
$stdout.sync
string = "get down"
def dance(move, string)
string = string.send(move)
print "%s\r" % string
sleep 0.3

I'm going to do my best to parrot things I picked up from the scala course... What you've done here by declaring functions with {} works but I don't think it is the intended syntax. Odersky presented it like this:

() is how you call a function, ie they wrap parameters just like you would expect. If one parameter is a function literal then you get the a form like this:

val nums = List(0,1,0)                          //> nums  : List[Int] = List(0, 1, 0)
nums.map((x) => {x.toString})                   //> res0: List[String] = List(0, 1, 0)

Note: cqlsh converts timestamps into current timezone

You can prove this manually:

$ cqlsh
cqlsh> CREATE KEYSPACE mykeyspace WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
cqlsh> use mykeyspace;
cqlsh> CREATE TABLE objects (id int PRIMARY KEY, name text, date timestamp);
cqlsh> INSERT INTO objects (id, name, date) VALUES (1, 'one', '2010-01-01T00:00:00Z');

cqlsh> SELECT * FROM objects;

drop schema if exists a cascade;
create schema a;
drop schema if exists b cascade;
create schema b;
create table b.things (id int);
insert into b.things (id) values (1);
insert into b.things (id) values (2);
insert into b.things (id) values (3);

Notes

Starting/stopping processes occurs in serial, ergo make sure the start/stop commands go quickly or the whole thing hangs. I It's a good idea to use env.sh scripts to setup the execution environment so you have something fully reproducible. Here is the command to get the ruby environment via rvm.

rvm info environment | sed -n -e 's/: \{1,\}/=/' -e 's|.rvm/bin:.*|.rvm/bin:$PATH"|' -e 's/    \([A-Z]\)/export \1/p'

An example usage:

check process process_name with pidfile /path/to/pidfile.pid

start program = "/usr/bin/env -i KEY=VALUE /path/to/env.sh /path/to/monit_exec start /path/to/pidfile.pid /path/to/stdin_file /path/to/stdout_file /path/to/logfile.log commmand args..."

@thinkerbot
thinkerbot / xyz.cql
Created August 26, 2014 16:48
Examples of cql queries
DROP KEYSPACE IF EXISTS example;
CREATE KEYSPACE example WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 3 };
USE example;
DROP TABLE IF EXISTS xyz;
create table xyz (
xpart int,
x int,
z int,
y int,
@thinkerbot
thinkerbot / pipe-exec
Last active August 29, 2015 14:06
Hold open a fifo from both ends, allowing input from external processes
#!/usr/bin/env ruby
begin
require 'optparse'
options = {
:direction => "in"
}
OptionParser.new do |opts|
opts.banner = %{
usage: pipe-exec [options] FIFO_FILE COMMAND....

RSpec issues with include

We're extracting modules from intellisource and that's a good engineering practice. We can localize and document the footprint of modules by requiring and including them where they're used.

[helper-module.gem]
module HelperModule

class HelperClass

@thinkerbot
thinkerbot / README.md
Last active August 29, 2015 14:14
Clean merge

One way to merge nested configs cleanly:

  • flatten key paths
  • merge

This approach overcomes the issue of performing a deep merge when an overlay has the ability to specify a value or a hash. This does not deal with merging array values.

Here is the issue:

c1 = {"a" => 1}