Skip to content

Instantly share code, notes, and snippets.

@xexu
xexu / dom.html
Last active December 17, 2015 20:49
DOM selection jQuery-ish on IE8+
<html>
<head>
<title>DOM selection jQuery-ish on IE8+</title>
</head>
<body>
<script>
window.$ = function(selector) {
return document.querySelector(selector);
};
@xexu
xexu / replacer.py
Created April 28, 2013 21:02
replace utility for large files
# -*- coding: utf-8 -*-
import os, codecs, sys
dir = os.getcwd()
file = sys.argv[1]
Dict = [['a', 'b'], ['c', 'd']]
fname = os.path.join(dir, file)
@xexu
xexu / recursive list
Last active December 16, 2015 18:29
Rescursive list of files
ls -R /path | awk '
/:$/&&f{s=$0;f=0}
/:$/&&!f{sub(/:$/,"");s=$0;f=1;next}
NF&&f{ print s"/"$0 }'
@xexu
xexu / PHP Debug
Last active October 13, 2015 22:38
Just add this code on top of the file if the page goes blank to show errors
error_reporting(E_ALL);
ini_set("display_errors", "on");
@xexu
xexu / randomStringFromCharacterSet.php
Created February 17, 2012 18:06
Function to generate random strings of a given length containing characters from a given set
<?php
function randomStringFromCharacterSet($length, $possibleCharacters){
return substr(str_shuffle(str_repeat($possibleCharacters,$length)),0,$length);
}
//Example of usage
$possibleCharacters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$length = 5;
for($i=0;$i<10;$i++){
echo randomStringFromCharacterSet($length, $possibleCharacters).'</br>';