Skip to content

Instantly share code, notes, and snippets.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fabrizioc1
fabrizioc1 / redis_failover_proxy.go
Created February 9, 2016 18:40
Redis Failover Proxy
package main
import (
"fmt"
"log"
"net"
"sync"
"time"
"strings"
"runtime"
@fabrizioc1
fabrizioc1 / binary_search_tree.rb
Last active August 29, 2015 14:01
Binary Search Tree in Ruby
=begin
3,5,2,7,1
3
2 5
1 7
=end
@fabrizioc1
fabrizioc1 / rspec_performance_test.rb
Last active December 22, 2015 00:00 — forked from danbronsema/rspec performance test
rspec performance test
context 'performance' do
before do
require 'benchmark'
@posts = []
@users = []
8.times do |n|
user = Factory.create(:user)
@users << user
aspect = user.aspects.create(:name => 'people')
connect_users(@user, @aspect0, user, aspect)
class Player
def initialize
@max_health = 20
@last_health = @max_health
@taking_damage = false
@directions = [:backward, :forward]
@current_direction = :forward
@reached_wall = false
end
@fabrizioc1
fabrizioc1 / election_candidate.rb
Created July 10, 2013 05:48
Zookeeper leader election using Ruby
# http://zookeeper.apache.org/doc/r3.3.4/recipes.html#sc_leaderElection
require 'rubygems'
require 'bundler/setup'
require 'zookeeper'
require 'hashie'
class ElectionCandidate
ROOT_PATH = "/election"
NODE_PATH = "candidate_"
@fabrizioc1
fabrizioc1 / java_timezones.groovy
Last active December 15, 2015 20:09
List time zones with UTC and DST offsets
new File("/tmp/java_timezones.txt").withWriter { out ->
TimeZone.getAvailableIDs().each{ timezoneId ->
timezone = TimeZone.getTimeZone(timezoneId)
def items = [timezone.getID(),
(int)(timezone.getRawOffset()/1000),
(int)(timezone.getDSTSavings()/1000)]
out.print sprintf("%6d %32s %6d\n",items[1],items[0],items[2])
}
}
@fabrizioc1
fabrizioc1 / tcpdump_memcached.sh
Created February 26, 2013 06:30
Using TCPDUMP to capture Memcached packets
sudo tcpdump -w /tmp/memcached.pcap -i any -A -vv 'port 11211'
@fabrizioc1
fabrizioc1 / memory_estimate.rb
Last active December 12, 2015 00:48
Estimate Linux process memory usage
# can probably cross reference with ltrace
# this removes shared libraries from the total memory count
def memory_estimate(pid)
`sudo pmap #{pid}`.lines.reject{|line|
line[%r[/lib[^.]+\.so]] or line[/^ total/]
}.drop(1).reduce(0){|total,line|
total + line.match(/(\d+)K/)[1].to_i
}
end
@fabrizioc1
fabrizioc1 / graham_scan.hs
Created January 5, 2013 01:31
Graham Scan Algorithm
-- Read: http://en.wikipedia.org/wiki/Graham_scan
-- ================================================ --
-- =========== Definitions/Imports ============== --
-- ================================================ --
import Data.List
-- ch03/ex09.hs
data Direction = LeftTurn | RightTurn | Straight deriving (Show,Eq)
data Point2D = Point2D {x :: Double, y :: Double} deriving (Show,Ord,Eq)