Skip to content

Instantly share code, notes, and snippets.

class RiakCallback
def before_destroy(record)
raise 'Invalid Riak Client' unless record.walk_server_client.is_a? Riak::Client
@client = record.walk_server_client
record.riak_keys.each do |key|
delete(key[0], key[1])
end
end
def exists?(key, bucket_name)
@gerep
gerep / weird.rb
Created November 5, 2013 15:52 — forked from jimweirich/weird.rb
def foo(a=:default, b)
puts "a=#{a}, b=#{b}"
end
foo(:value)
foo(:x, :y)
@gerep
gerep / ap.rb
Last active December 27, 2015 12:09
Arithmetic Progression
@n = 3
@sequence = '0 8 12'.split(' ').map(&:to_i).sort
def ratio
(@sequence[-1] - @sequence[0])/@n.to_i
end
def missing(n, sequence, diff)
numbers = []
n.times do |c|
@gerep
gerep / search.bash
Last active February 12, 2016 17:49
#! /usr/bin/env bash
#
# search [file(s)]
#
# This script will read the files passed as parameters and those files
# will contain a list of IPs separated by lines and will search for
# each of those IPs in both omg-switch log files
#
# When no argument is passed, it will open the page on the current branch
@gerep
gerep / UniqueNumberWithChannels.go
Created February 23, 2016 16:20
Using channels to return a unique number
package main
import "fmt"
func main() {
id := make(chan string)
go func() {
var counter int64
for {
@gerep
gerep / FastestCDN.go
Created February 23, 2016 16:43
Using channels to test the fastest CDN response
package main
import (
"fmt"
"net/http"
)
type response struct {
name string
resp *http.Response
@gerep
gerep / sed.bash
Last active February 25, 2016 20:49
This sed command will search for the tab <KEY>. count 12 characters and replace them with *. The same happens with the tag <KEYVAL>
sed -e 's/<KEY>[0-9]\{12\}/(&)/g' -e 's/(<KEY>.*)/<KEY>*************/g' -i blah.log
sed -e 's/<KEYVAL>[0-9]\{12\}/(&)/g' -e 's/(<KEYVAL>.*)/<KEYVAL>*************/g' -i blah.log
@gerep
gerep / heartbeat.go
Created February 28, 2016 13:07
Heartbeat example
package main
import (
"fmt"
"time"
)
func main() {
heartbeat := time.Tick(1 * time.Second)
for {
@gerep
gerep / responseChannel.go
Created February 28, 2016 13:15
Using a channel to get a response from a goroutine
package main
import (
"fmt"
"net/http"
)
type work struct {
url string
resp chan *http.Response
package main
import (
"fmt"
"time"
)
func main() {
message := make(chan string, 2) // buffer
count := 3