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 | |
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>'; |
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
error_reporting(E_ALL); | |
ini_set("display_errors", "on"); |
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
ls -R /path | awk ' | |
/:$/&&f{s=$0;f=0} | |
/:$/&&!f{sub(/:$/,"");s=$0;f=1;next} | |
NF&&f{ print s"/"$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
# -*- 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) |
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
<html> | |
<head> | |
<title>DOM selection jQuery-ish on IE8+</title> | |
</head> | |
<body> | |
<script> | |
window.$ = function(selector) { | |
return document.querySelector(selector); | |
}; |
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 Paypal { | |
/** | |
* Last error message(s) | |
* @var array | |
*/ | |
protected $_errors = array(); | |
/** | |
* API Credentials |
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
//http://stackoverflow.com/questions/834303/php-startswith-and-endswith-functions/834355#834355 | |
//Note: Be careful with empty strings, you might want a different behaviour | |
function startsWith($haystack, $needle) | |
{ | |
$length = strlen($needle); | |
return (substr($haystack, 0, $length) === $needle); | |
} | |
function endsWith($haystack, $needle) |
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 | |
backup_tables('','','',''); | |
/* backup the db OR just a table */ | |
function backup_tables($host,$user,$pass,$database,$tables = '*') | |
{ | |
$link = mysql_connect($host,$user,$pass); | |
mysql_select_db($database,$link); | |
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
for i in `cat urls.txt`; do curl -s -o /dev/null -w "%{http_code} " $i; echo $i; done |
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 | |
function tokenize($string) | |
{ | |
$string = preg_replace("/ +/", " ", $string); | |
return explode(" ", strtolower($string)); | |
} | |
function train($dataset, $text, $class) | |
{ | |
$tokens=tokenize($text); |
OlderNewer