Skip to content

Instantly share code, notes, and snippets.

@lucacervasio
lucacervasio / tree.php
Last active December 20, 2015 03:18
Building a tree from plain strings
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
class tree_item {
public $title = '';
public $children = array();
public function &has_child($title) {
@lucacervasio
lucacervasio / tree.py
Last active December 20, 2015 03:19
build tree from dotted strings
#! /usr/bin/python
a = [
'uno.due',
'uno.tre',
'uno.due.quattro'
]
root = {'uno': {}}
@lucacervasio
lucacervasio / tree.rb
Created July 23, 2013 16:05
tree from dotted separated strings
#!/usr/bin/env ruby
a = {
'uno.due.tre.otto' => 2,
'uno.due.tre.sei' => 5,
'uno.due.quattro' => 'ciao',
'uno.sette.cinque' => 'true',
}
mib = {'uno' => {}}
@lucacervasio
lucacervasio / hercules.c
Last active December 20, 2015 12:29
Hercules: a multiple tcp client implementation with socket select
/*
*
* Hercules v0.2
* Copyright (C) 2010 Luca Cervasio
* Created by Luca Cervasio <[email protected]>
* All rights reserved (C) 2010 Luca Cervasio
* You're not allowed to copy or redistribute this software without the author's consent
*
*/
@lucacervasio
lucacervasio / hercules.groovy
Last active December 20, 2015 12:29
Hercules is a CPE simulator (multiple client implementation in groovy with java nio socket select
/*
Hercules is a CPE simulator built by Luca Cervasio <[email protected]>
within mosesacs project (see http://mosesacs.org, [email protected])
*/
import java.util.concurrent.ArrayBlockingQueue
import java.nio.channels.Selector
import java.nio.channels.SelectionKey
import java.nio.channels.SocketChannel
import java.nio.ByteBuffer
@lucacervasio
lucacervasio / select_server.rb
Last active December 20, 2015 12:29
Ruby tcp socket server with socket select
#!/usr/bin/env ruby
require 'socket'
@mysocket = TCPSocket.new('127.0.0.1', 9761)
while true
ready = IO.select([@mysocket])
readable = ready[0]
@lucacervasio
lucacervasio / jump.sh
Last active December 22, 2015 00:59
Setting and jumping to marks during shell fs browsing
# I made some small changes to this: http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-filesystem-from-the-command-line.html
# to install: curl https://raw.github.com/gist/6393682 >> ~/.bashrc; mkdir ~/.marks
export MARKPATH=$HOME/.marks
function jump {
cd -P "$MARKPATH/$1" 2>/dev/null || echo "No such mark: $1"
}
function mark {
mkdir -p "$MARKPATH"; ln -s "$(pwd)" "$MARKPATH/$1"
#!/usr/bin/ruby
# README
# gem install aws-sdk
# add this to bashrc
# export HT_DEV_AWS_ACCESS_KEY_ID=????
# export HT_DEV_AWS_SECRET_ACCESS_KEY=????
# put your pem file in ~/.ssh and chmod 0400
# for more info see; https://rubygems.org/gems/aws-sdk
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
#!/usr/bin/env ruby
require 'rubygems'
require 'xmpp4r'
require 'xmpp4r/muc/helper/simplemucclient'
# Most of this is borrowed from https://gist.github.com/941931
# Added support for multiple rooms and external handling of messages.
# We want the MUC functionality to just handle shit for us. Unfortunately we
# have to override/repeat the join method in order to add the directive that