Skip to content

Instantly share code, notes, and snippets.

View yuvadm's full-sized avatar

Yuval Adam yuvadm

View GitHub Profile
@yuvadm
yuvadm / Chat.java
Created January 24, 2011 14:33
JGroups TCP over WAN
import org.jgroups.JChannel;
import org.jgroups.Message;
import org.jgroups.ReceiverAdapter;
import org.jgroups.View;
import org.jgroups.util.Util;
public class Chat {
public static void main(String[] args) throws Exception {
JChannel ch = new JChannel("tcp.xml");
@yuvadm
yuvadm / fabfile.py
Created March 16, 2011 13:41
Fabric example for SSH keyfile connection
from fabric.api import *
env.hosts = ['host.name.com']
env.user = 'user'
env.key_filename = '/path/to/keyfile.pem'
def local_uname():
local('uname -a')
def remote_uname():
@yuvadm
yuvadm / haproxy.cfg
Created March 17, 2011 10:10
A basic HAProxy configuration for a proxy server with stats
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
#log loghost local0 info
maxconn 4096
#chroot /usr/share/haproxy
user haproxy
group haproxy
daemon
#debug
@yuvadm
yuvadm / transpose.py
Created August 6, 2011 13:26
Transposing a matrix in Python
matrix = [(0,1,2), (0,1,2), (0,1,2)]
transposed = zip(*matrix) # pythonic transpose!
print transposed
# >>> [(0, 0, 0), (1, 1, 1), (2, 2, 2)]
@yuvadm
yuvadm / decorators.py
Created October 21, 2011 11:54
Django login_required with 403 on fail
try:
from functools import update_wrapper, wraps
except ImportError:
from django.utils.functional import update_wrapper, wraps # Python 2.4 fallback.
from django.http import HttpResponseForbidden
from django.utils.decorators import available_attrs
def user_passes_test(test_func):
def decorator(view_func):
@yuvadm
yuvadm / gist:1351791
Created November 9, 2011 15:31 — forked from hay/gist:1351230
Enterprisify your Java Class Names!
<!doctype html>
<html>
<head>
<title></title>
<style>
body {
background: white;
text-align: center;
padding: 20px;
font-family: Georgia, serif;
@yuvadm
yuvadm / app.py
Created March 17, 2012 22:22
ep.io Bottle Deployment Template
from bottle import app, route
@route('/')
def index():
return 'Oh Hai!'
application = app()
@yuvadm
yuvadm / hack.sh
Created March 31, 2012 10:37 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@yuvadm
yuvadm / client.ovpn
Created June 7, 2012 19:47
OpenVPN Installation on Ubuntu 12.04
##############################################
# Sample client-side OpenVPN 2.0 config file #
# for connecting to multi-client server. #
# #
# This configuration can be used by multiple #
# clients, however each client should have #
# its own cert and key files. #
# #
# On Windows, you might want to rename this #
# file so it has a .ovpn extension #
@yuvadm
yuvadm / partial_app.py
Created June 8, 2012 18:39
Real-time messaging using Tornado/sock.js/Redis/Brukva
class ConnectionHandler(SockJSConnection):
def __init__(self, *args, **kwargs):
super(ConnectionHandler, self).__init__(*args, **kwargs)
self.client = brukva.Client()
self.client.connect()
self.client.subscribe('some_channel')
def on_open(self, info):
self.client.listen(self.on_chan_message)