Skip to content

Instantly share code, notes, and snippets.

@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 )
{
<?php
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
/**
* Session sotrage that avoids using _sf2_attributes subkey
* in the $_SESSION superglobal but instead it uses
* the root variable.
*/
class LegacySessionStorage extends NativeSessionStorage
@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();
@tcz
tcz / base_convert.php
Last active December 28, 2015 00:39
Convert from any base to any base in PHP
<?php
function convertBases($number, $from_digits, $to_digits)
{
$from_digits = str_split($from_digits, 1);
$to_digits = str_split($to_digits, 1);
$number = str_split($number, 1);
$number_dec = "0";
$ord = 0;
@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 / 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 / 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 / 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 / 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
<?php
class DrinkingGame
{
const TAIL = 'tail';
const DRUNKEST = 'zoltan';
public function __construct(array $names, Coin $coin = null) {
$this->names = array_fill_keys($names, 0);
$this->coin = $coin;