Skip to content

Instantly share code, notes, and snippets.

@prggmr
prggmr / gist:f6ccc28f59595aff3f84
Created August 20, 2014 06:24
Update ALL MySQL Columns
SELECT CONCAT( 'ALTER TABLE ', TABLE_SCHEMA,'.',TABLE_NAME , ' MODIFY ', COLUMN_NAME, ' ', DATA_TYPE , '(', CHARACTER_MAXIMUM_LENGTH , ') CHARACTER SET utf8 ;' ) FROM COLUMNS WHERE TABLE_SCHEMA = 'vpd1' AND CHARACTER_SET_NAME != 'utf8';
@prggmr
prggmr / gist:a7b46fee526b140f8292
Last active August 29, 2015 14:05
Token Generator using clientid and secret.
import hashlib
def gen_token(clientid, secret, length=512):
clientid_token = hashlib.sha512(clientid).hexdigest()
secret_token = hashlib.sha512(secret).hexdigest()
token = secret_token+clientid_token
token = hex(pow(int(str(token), 16), 2)).replace('0x','')
b = 1
# Change divisor +/- to increase / decrease length
div = 512/length
@prggmr
prggmr / round_robin.php
Created July 28, 2012 13:45
Round Robin Algorithm
<?php
/**
* Rotates an array for the round robin algorithm
*/
function round_robin_array($array)
{
// we always keep index 0
$top = array_shift($array);
$last = array_pop($array);
@prggmr
prggmr / sample_xml
Created April 27, 2012 15:43
XML Sample
<Genre-Reference><Genre>
<Id>16</Id>
<Name>Reggae/Ska</Name>
<Genre-Category>MUSIC</Genre-Category>
<Genre-Type>MAIN</Genre-Type>
<Created-Date>2001-04-24</Created-Date>
<Last-Updated-Date>2001-04-24</Last-Updated-Date>
</Genre>
<Genre>
<Id>20</Id>
@prggmr
prggmr / jquery.click_hold.js
Created April 13, 2012 15:42
jQuery click and hold function
$.fn.click_hold = function(fn, delay) {
var timeout = 0;
$(this).live("mousedown", function(evt) {
var $this = $(this).data("mousedown", true);
timeout = setInterval(function() {
if ($this.data("mousedown") === true) {
console.log("held");
fn(evt);
} else {
console.log("released");
@prggmr
prggmr / python_gxmlimport.py
Last active February 20, 2023 21:35
Tool to import enormous XML files into mysql using lxml.etree
def does_exist(tbl, where = None, where_field = 'id'):
"""Builds a MySQL SELECT statement
"""
where_clause = "WHERE `%s` = %%s" % where_field
query = "SELECT COUNT(`id`) AS total FROM %s %s" % (
tbl, where_clause
)
cur.execute(query, (where,))
return cur.rownumber != 0
@prggmr
prggmr / gist:1001179
Created May 31, 2011 20:12
Prggmr Autoload ZF
spl_autoload_register(function($file) {
if (!defined('PRGGMR_VERSION')) {
if (strpos($file, 'prggmr') !== false) {
include_once 'prggmr/prggmr.php';
}
}
});