Skip to content

Instantly share code, notes, and snippets.

@tcz
tcz / signal_test.c
Created October 31, 2011 19:07
Parent process killing zombies
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdlib.h>
// Array of childen's PIDs.
pid_t children[10];
@tcz
tcz / gist:1654175
Created January 21, 2012 21:51
Supervisord to init, RHEL
#!/bin/sh
#
# /etc/rc.d/init.d/supervisord
#
# Supervisor is a client/server system that
# allows its users to monitor and control a
# number of processes on UNIX-like operating
# systems.
#
# chkconfig: - 64 36
@tcz
tcz / gist:1746180
Created February 5, 2012 15:50
MySQL backup with innobackupex and s3cmd
#!/bin/bash
INNOBACKUP="/root/percona-xtrabackup/innobackupex"
INNOBACKUP_OPTIONS="--defaults-file=/etc/my.cnf --ibbackup=/root/percona-xtrabackup/mysql-5.5/storage/innobase/xtrabackup/xtrabackup_innodb55 --parallel=4 --user=root --password=XXXXXXX"
BACKUPDIR="/var/sqlbackup/"
S3BUCKET="db_backup"
echo "Removing old local backups"
cd $BACKUPDIR
@tcz
tcz / SphinxClient.php
Created July 3, 2012 19:46
PHP API for Sphinx 2.0.4
<?php
//
// $Id: sphinxapi.php 3087 2012-01-30 23:07:35Z shodan $
//
//
// Copyright (c) 2001-2012, Andrew Aksyonoff
// Copyright (c) 2008-2012, Sphinx Technologies Inc
@tcz
tcz / rot13.js
Created July 8, 2012 22:14
ROT13 Javascript BDD example with Jasmine
function rot13( text )
{
var results = [];
var charcode;
for ( var i = 0; i < text.length; ++i )
{
charcode = text.charCodeAt( i );
if ( charcode < 65 || charcode > 90 )
{
@tcz
tcz / clock.js
Created July 8, 2012 22:22
Clock Javascript BDD example with Jasmine and Sinon.js
var Clock = function( element )
{
this.element = element;
this._schedule();
}
Clock.prototype._schedule = function()
{
var self = this;
@tcz
tcz / BytesWritableUrlHandler.java
Created December 3, 2012 00:05
Xuggler integration with BytesWritable
package hu.tcz.udder;
import com.xuggle.xuggler.io.IURLProtocolHandler;
import com.xuggle.xuggler.io.IURLProtocolHandlerFactory;
import org.apache.hadoop.io.BytesWritable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.UUID;
public class BytesWritableUrlHandler implements IURLProtocolHandlerFactory {
@tcz
tcz / gist:5618763
Created May 21, 2013 10:09
Demonstrating why RecursiveArrayIterator is useless whent he items are objects.
<?php
$multi_array = array(
'foo' => array(
'bar' => (object) array( 'baz' => 'bat' ),
),
);
var_dump( iterator_to_array( new RecursiveIteratorIterator( new RecursiveArrayIterator( $multi_array ) ) ) );
@tcz
tcz / README.md
Last active December 25, 2015 15:39
Script to monitor directory and execute command when changes

Script to monitor directory and execute command when changes

This script monitors a specific directory for changes and when it detects any, it executes a command. It is very useful when writing unit tests for example because you don't need to switch windows. With a 2 monitor setup it's la leche.

Installation

# on Debian/Ubuntu use apt-get
yum -y install inotify-tools wget
wget https://gist.github.com/tcz/6999795/raw/auto.sh
@tcz
tcz / hypem.php
Last active July 26, 2016 02:14
Copy Hypem favorites to Spotify
<?php
if ($argc !== 2)
{
die("Usage: php {$argv[0]} hypem_user_name\n\n");
}
$user = $argv[1];
$page = 1;
$all_songs = array();