Skip to content

Instantly share code, notes, and snippets.

@fabrizioc1
fabrizioc1 / NoCacheFilter.java
Created September 8, 2012 00:14
Servlet filter to skip cache in WebSphere Commerce
package com.fct.wcs.cache;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
@fabrizioc1
fabrizioc1 / sql_profiler_wcde7.md
Created September 18, 2012 18:58
Installing RAD SQL Profiler in WebSphere Commerce Developer 7
@fabrizioc1
fabrizioc1 / http-proxy.go
Last active October 27, 2020 12:32
Http proxy server in Go
package main
import (
"fmt"
"io"
"log"
"net/http"
)
type HttpConnection struct {
@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)
@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 / 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 / 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 / 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_"
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 / 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)