Skip to content

Instantly share code, notes, and snippets.


Bruno Bonacci BrunoBonacci

View GitHub Profile

Keybase proof

I hereby claim:

  • I am BrunoBonacci on github.
  • I am brunobonacci ( on keybase.
  • I have a public key whose fingerprint is F05B 1D2E F3BE D8C8 E12F 44EF 6BEF 76A7 B805 F61B

To claim this, I am signing this object:

View gist:cb13fc05bd720652eb17
(defn crypto-square [s]
(->> (re-seq #"\w+" s)
(map clojure.string/lower-case)
(apply str)
(#(let [size (int (Math/ceil (Math/sqrt (count %))))]
(partition size size (repeat " ") %)))
(apply map vector)
(map (partial apply str))
(clojure.string/join "\n")))
BrunoBonacci / gist:5225781
Created Mar 23, 2013
Reminder vs bitwise operation benchmark
View gist:5225781
* this benchmark compares the speed of
* the reminder operator vs the bitwise
* equivalent.
public class ReminderBenchmark {
final static long d = 8;
final static long mask = d-1;
final static long REPEAT = 1_000_000L;
View gist:5009911
# stopping the server
sudo /etc/init.d/mongod stop
# now replace local.n files
cd /var/lib/mongo/local
sudo rm -fr local.*
sudo rename 's/new-local/local/g' new-local.*
# restarting the server
sudo /etc/init.d/mongod start
BrunoBonacci / gist:5009801
Created Feb 22, 2013
creating zero-filled oplog files.
View gist:5009801
cd /var/lib/mongo/local
# as root user
for i in {0..11}
echo "Initializing new-local.$i"
dd if=/dev/zero of=new-local.$i bs=2146435072 count=1
chown mongod:mongod new-local.$i
chmod 0600 new-local.$i
BrunoBonacci / gist:5009746
Created Feb 22, 2013
MongoDB key generation
View gist:5009746
# generate the key and make it readable only by mongo server
sudo openssl rand -base64 753 > /etc/mongodb.key
sudo chown mongod:mongod /etc/mongodb.key
sudo chmod 0600 /etc/mongodb.key
BrunoBonacci / gist:5009721
Last active Dec 14, 2015
MongoDB Replica set configuration
View gist:5009721
# this is the replica set name
# every node will need to have the same name
replSet = setname
# this is the authetication encryption key
# this will be required to be same on every node
keyFile = /etc/mongodb.key
# This is the operational log size
# here we assume ~24GB for example
BrunoBonacci / gist:3028607
Created Jul 1, 2012
Vert.x Simple Telnet Server - command "cd"
View gist:3028607
////////////////////////////////////////////////////////////////////////// cd
def cd(def path, String cid) {
path = path == "" ? null : path
def newPath = virtual2real(path, cid);
if (!newPath.exists() || !newPath.isDirectory())
return [status: "ERROR", message: "### ERROR: $path: no such directory!".toString()]
// changing directory
_connections[cid].curDir = new File(newPath.canonicalPath);
BrunoBonacci / gist:3028594
Created Jul 1, 2012
Vert.x Simple Telnet Server - command handler
View gist:3028594
// Regular expression to verify/extract pathnames from commands
PATH_ELEM = "[A-Za-z0-9.-]+"
PATH = "(/?$PATH_ELEM(/$PATH_ELEM)*/?|/)"
// Commands handler
bus.registerHandler("commands") {
msg ->
def cmd = msg.body.command
switch (cmd) {
case ~$/cd( $PATH)?/$:
BrunoBonacci / gist:3028571
Created Jul 1, 2012
Vert.x Simple Telnet Server - NIO Server
View gist:3028571
// general configuration
settings = [port: 1234];
// Vert.x server and event-bus
def server = vertx.createNetServer()
def bus = vertx.eventBus
// Connection handler. Here requests are captured, parsed, and executed.
server.connectHandler { sock ->
// upon a new connection, assigning a new connection id (cid)