Skip to content

Instantly share code, notes, and snippets.

@physacco
physacco / ruby20-default-gems.txt
Created April 20, 2013 15:38
Ruby 2.0 default gems.
bigdecimal (1.2.0)
io-console (0.4.2)
json (1.7.7)
minitest (4.3.2)
psych (2.0.0)
rake (0.9.6)
rdoc (4.0.0)
test-unit (2.0.0.0)
@physacco
physacco / commaSplitNumber.js
Created April 18, 2013 03:48
Print number in comma-splited format in JavaScript.
// Print number in comma-splited format.
// Written by physacco. 2011-05-13.
//
// Tested on:
// - Mozilla SpiderMonkey JavaScript-C 1.7.0 2007-10-03.
// - Mozilla Rhino 1.7 release 0.7.r2.fc12 2009 07 28.
function commaSplitNumber(num) {
var numstr = num.toString();
var dec, frac;
@physacco
physacco / convert_time.js
Last active December 16, 2015 08:59
Parse and format time in JavaScript.
// Parse and format time.
// Written by physacco. 2011-05-13.
//
// Tested on:
// - Mozilla SpiderMonkey JavaScript-C 1.7.0 2007-10-03.
// - Mozilla Rhino 1.7 release 0.7.r2.fc12 2009 07 28.
//
// To run it with nodejs, substitute print with console.log.
// YYYY-mm-dd HH:MM:SS
@physacco
physacco / Makefile
Created April 18, 2013 03:24
Simple C program that connects to MySQL server.
myclient: myclient.o
gcc -omyclient -rdynamic -L/usr/lib/mysql -lmysqlclient -lz -lcrypt -lnsl -lm -lssl -lcrypto myclient.o
myclient.o: myclient.c
gcc -omyclient.o -c myclient.c
@physacco
physacco / libmysql_api.md
Created April 18, 2013 03:07
Some notes about libmysql's API and the python MySQLdb module.

C API _mysql

|--------------------------------+-------------------------------------+------------------------------------------|
| C API                          | _mysql                              | Note                                     |
|--------------------------------+-------------------------------------+------------------------------------------|
| mysql_affected_rows()          | conn.affected_rows()                |                                          |
| mysql_autocommit()             | conn.autocommit()                   | COM_QUERY set autocommit=                |
| mysql_character_set_name()     | conn.character_set_name()           |                                          |

| mysql_close() | conn.close() | COM_QUIT |

@physacco
physacco / check_postgresql.sh
Created April 17, 2013 08:42
Scripts used to start/stop/check postgresql. (2010)
#!/bin/sh
PidFile=/usr/local/pgsql/data/postmaster.pid
foo()
{
if [ -f "$PidFile" ]; then
pgrep postgres | grep `head -1 $PidFile`
fi
}
@physacco
physacco / lxc-commands.md
Created April 16, 2013 03:16
All lxc commands found on our server.

Commands

lxc                  convenience Wrapper for LXC programs
lxc-attach           start a process inside a running container
lxc-cgroup           manage the control group associated with a container
lxc-checkconfig      check the current kernel for lxc support
lxc-checkpoint       checkpoint a running container (not implemented yet)
lxc-clone            clone a new container from an existing one
lxc-console          Launch a console for the specified container

lxc-create creates a container

@physacco
physacco / monit
Created April 11, 2013 11:16
monit init script for Redhat/Fedora.
#!/bin/sh
# monit: monit init script for Redhat/Fedora.
# Written by physacco. 2013/04/11
# To start at boot time:
# 1. copy this file to /etc/init.d/monit
# 2. chkconfig monit on
# ---------------------
@physacco
physacco / ruby-pcap-usage.md
Last active December 15, 2015 23:59
Usage of the ruby-pcap gem.

Pcaplet example

# examples/tcpdump.rb
require 'pcaplet'
include Pcap

pcaplet = Pcaplet.new
pcaplet.each_packet do |pkt|
@physacco
physacco / test_pcap.c
Created April 9, 2013 08:49
A "hello world" example for libpcap.
#include <stdio.h>
#include <stdlib.h>
#include <pcap/pcap.h>
/* callback function when packet have captured */
static void mycb(u_char *user,
const struct pcap_pkthdr *h, const u_char *packet)
{
static int count = 1;
printf("Packet %d:\n", count);