Skip to content

Instantly share code, notes, and snippets.

View mardambey's full-sized avatar
👾
Getting things done.

Hisham Mardam-Bey mardambey

👾
Getting things done.
View GitHub Profile
sub vcl_hash {
set req.hash += req.url;
set req.hash += req.http.host;
set req.http.X-Calc-Hash = "true";
if( req.http.Cookie ~ "JSESSIONID" ) {
set req.http.X-Varnish-Hashed-On =
regsub( req.http.Cookie, "^.*?JSESSIONID=([a-zA-z0-9]{32}\.[a-zA-Z0-9]+)([\s$\n])*.*?$", "\1" );
@mardambey
mardambey / testRunner.html
Created April 14, 2011 03:56
Simple test runner in JS.
<html>
<head>
<title>Mate1 Test Runner</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript">
// A test is the base class for all tests
// that will be run by the test runner.
Test = function() {
@mardambey
mardambey / gist:1326933
Created October 31, 2011 04:42
Sample Kafka stdin producer
package com.edate.data.test
import java.util.Properties
import kafka.producer.ProducerConfig
import kafka.producer.Producer
import kafka.message.Message
import kafka.producer.ProducerData
import kafka.producer.ProducerData
import kafka.producer.Partitioner
/**
@mardambey
mardambey / mod_js.erl
Created March 31, 2012 22:45
mod_js is a *prototype* module that uses erlang_js to allow filtering stanza's through JavaScript for altering, dropping, etc.
%% mod_js is a prototype module that uses erlang_js
%% to allow filtering stanza's through JavaScript
%% for altering, dropping, etc.
%%
%% NOTE: The JavaScript path is hardcoded to "test.js"
%% at the end of this file.
%%
-module(mod_js).
-author('hisham.mardambey@gmail.com').
@mardambey
mardambey / mod_msg_filter.erl
Created April 25, 2012 03:58
mod_msg_filter allows the filtering of "message" stanzas across an HTTP service.
%%
%% mod_msg_filter allows the filtering of "message"
%% stanzas across an HTTP service. The URL of the
%% service must be passed as part of the module's
%% configuration. Both JIDs and their resources are
%% passed as part of the query string and the result
%% is expected to be one of:
%%
%% <status value="denied">
%% <stanza1><error/></stanza1>
@mardambey
mardambey / AkkaKafkaMailboxTest.scala
Last active August 3, 2019 05:03
Akka 2.0 actors with Kafka 0.7.x backed durable mailboxes.
import akka.actor.Actor
import akka.actor.ActorSystem
import akka.agent.Agent
import com.typesafe.config.ConfigFactory
import akka.event.Logging
import akka.actor.Props
import kafka.utils.Utils
import java.nio.ByteBuffer
@mardambey
mardambey / KafkaEmbedded.scala
Created May 10, 2012 02:58
Embedded Kafka broker / producer / simple consumer in a single process useful for testing or for persistent queues.
import java.util.Properties
import kafka.server.KafkaServer
import kafka.server.KafkaConfig
import kafka.producer.ProducerConfig
import kafka.producer.Producer
import kafka.message.Message
import kafka.producer.ProducerData
import kafka.consumer.ConsumerConfig
import kafka.consumer.Consumer
import kafka.utils.Utils
@mardambey
mardambey / gist:2654382
Created May 10, 2012 16:41
Reset Kafka offsets in ZooKeeper by deleting the corresponding nodes.
/**
* Notes: This code uses AsyncValue[T], a custom class that uses actors
* to allow concurrent operations on the provided type. It can be replaced
* by an Atomic object from the java.util.concurrent package or something
* that provides similar functionality.
*/
/**
* Resets the offsets for the given group / topic pair.
@mardambey
mardambey / AsyncValue.scala
Created May 12, 2012 01:51
An actor wrapping an object of type T providing async get/set calls without blocking (sacrificing accuracy).
import scala.actors.Actor
case class Set(value:Any)
case class Get()
case class Destroy()
/*
* An actor wrapping an object of type T providing async get/set
* calls without blocking (sacrificing accuracy).
*
@mardambey
mardambey / ConsistentHashRouter.scala
Created August 23, 2012 02:22
An Akka router that sends messages to its routees based on a consistent hash.
object ConsistentHashRouter {
/**
* Creates a new ConsistentHashRouter, routing to the specified routees
*/
def apply(routees: Iterable[ActorRef]): ConsistentHashRouter =
new ConsistentHashRouter(routees = routees map (_.path.toString))
}
case class ConsistentHashRouter(