This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'rubygems' | |
require 'optparse' | |
require 'ostruct' | |
# >> Helper functions | |
# deep copy | |
def dcopy(o) | |
return Marshal.load(Marshal.dump(o)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP FUNCTION IF EXISTS SPLIT; | |
DROP FUNCTION IF EXISTS _SPLIT; | |
DROP FUNCTION IF EXISTS RTSPLIT; | |
DROP FUNCTION IF EXISTS LTSPLIT; | |
DELIMITER // | |
-- Simple Split (no trim) | |
CREATE FUNCTION SPLIT(S CHAR(255), DELIM VARCHAR(30), S_INDEX TINYINT UNSIGNED) RETURNS VARCHAR(255) | |
BEGIN | |
RETURN _SPLIT(S, DELIM, S_INDEX, '', 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Random integer between 2 signed integers | |
DROP FUNCTION IF EXISTS RANDINT; | |
DELIMITER // | |
CREATE FUNCTION RANDINT(a INT, b INT) RETURNS INT | |
BEGIN | |
RETURN FLOOR( ABS(a-b) * RAND() ) + IF(a > b, b, a); | |
END// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import maxint | |
from random import choice, sample, shuffle | |
from string import ascii_uppercase as U, ascii_lowercase as L, digits as D, punctuation as P | |
def populate(punctuation, extra): | |
chars = U + L + D | |
if isinstance(extra, basestring): | |
chars += extra | |
if punctuation: | |
chars += P |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from resource import getrusage, RUSAGE_SELF | |
def monitor(unit="M", alert=None): | |
unit = unit.upper() | |
unit_transformation = { | |
"B" : 1./1024., | |
"K" : 1., | |
"M" : 1024., | |
"G" : 1024.*1024., | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.sub = function(regex, replacement){ | |
var s = this.toString(); | |
var matches = s.match(regex); | |
if ( matches !== null ){ | |
for(i in matches){ | |
var item = matches[i]; | |
if ( !item.escaped() ){ | |
s = s.replace(item, replacement); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
<div id="editor"></div> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> | |
<style> | |
.clearfix:after { | |
clear: both; | |
} | |
.clearfix:before, .clearfix:after { | |
content: " "; | |
display: table; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import getrandbits | |
def probability_counter(counter=None): | |
if counter is None: | |
counter = 1 | |
counter += int((getrandbits(counter) + 1) >> counter == 1) | |
return counter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import redis | |
from operator import methodcaller | |
class RedisTransaction(object): | |
def __init__(self, **kwargs): | |
''' Transaction timeout sets TTL for copied keys ''' | |
if 'timeout' in kwargs: | |
self.TRANSACTION_TIMEOUT = kwargs['timeout'] | |
else: | |
self.TRANSACTION_TIMEOUT = 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class T { | |
protected $Context = array(); | |
protected $Compiled = NULL; | |
public $Regex_Variable = '~\{\{\s+[a-z_0-9\|:\.]+\s+\}\}~imsu'; | |
public $Separator_Filter = '|'; | |
public $Separator_Directive = ':'; | |
protected $HTML_Encoder = NULL; | |
protected $HTML_ENCODE = TRUE; | |
protected $VALUE_CACHE = array(); |
OlderNewer