Skip to content

Instantly share code, notes, and snippets.

@xergio
xergio / Lock.php
Created November 22, 2011 08:49
class Lock
<?php
class Lock {
private $mc;
private $key;
function __construct($key=null, $expire=300) {
$this->mc = MemoryCache::getInstance($expire);
$this->key = is_null($key)? "mv_lock_". rand(1000, 9999): $key;
@xergio
xergio / hashchange.js
Created December 5, 2011 15:37
Mootools event hashchange
/*
Original: https://github.com/greggoryhz/MooTools-onHashChange-Event
Example:
window.addEvent('hashchange', function(hash) { console.log(hash); });
*/
Element.Events.hashchange = {
@xergio
xergio / python_redis_publish.py
Created December 7, 2011 11:11
Python + Redis + PubSub
from python_redis_pubsub import TestPubsub
import time
if __name__ == "__main__":
test = TestPubsub()
print test.publish('test01', time.time())
@xergio
xergio / xfce-wallbase.sh
Created January 24, 2012 09:35
Desktop background rotation in XFCE4 + Wallbase.cc
#!/bin/bash
# 1. put this file in a cron job
# 2. then, setup your desktop preferences to use the $BACKDROP image list
DESKTOPS=2
SAVE_TO="/home/salvarez/tmp/wp"
BACKDROP="/home/salvarez/tmp/xfce4-backdrop.list"
export DISPLAY=:0.0;
@xergio
xergio / ConfigParser.php
Created February 21, 2012 15:09
ConfigParser.py semiclone in PHP
<?php
class ConfigParser {
private $_raw;
private $_ini;
private $_allow_no_value=false;
function __construct($allow_no_value=false) {
<?php
class Foo {
var $foo = 'bar';
var $true = true;
var $false = false;
var $bar = array(1,2,3,1.23456789);
var $ass = array("life" => 42, "foo" => "bar");
function __set($name, $value)
{
@xergio
xergio / to-utf8.sh
Created March 3, 2012 09:00
Pasar un proyecto a utf-8
#! /bin/bash
cd proyecto
# paso los originales a utf8 en archivos .utf8
for a in $(find . -name "*.php"); do iconv -f iso-8859-1 -t utf-8 <"$a" >"$a.utf8" ; done
# muevo los originales a .iso
for a in $(find . -name "*.php"); do mv "$a" "$a.iso" ; done
@xergio
xergio / django_vars.php
Created March 24, 2012 23:16
A PHP implementation to parse django template vars
<?php
/*
Sergio Álvarez Muñoz
xergio@gmail.com
https://sergio.am
Basado en el sistema de templates de Django.
Snipper adaptado de http://effbot.org/zone/django-simple-template.htm
@xergio
xergio / dns-server.rb
Created April 17, 2012 20:02
DNS for development purposes
#!/usr/bin/env ruby
# git clone https://github.com/ioquatix/rubydns
require 'rubygems'
require 'rubydns'
$R = Resolv::DNS.new
$H = Resolv::Hosts.new
Name = Resolv::DNS::Name
<?php
// https://github.com/rg3/youtube-dl/
$playlist_id = "PL35E63D54FF7AAFC4";
//$playlist_id = "PL91D82848DC945315";
$max_results = 10;
$start_index = 1;
do {