Skip to content

Instantly share code, notes, and snippets.

@thinkt4nk
thinkt4nk / confirm_code.php
Last active August 29, 2015 13:57
Random Confirm Code Generator
<?
class confirm_code
{
protected static function generate_random_bytes($length=16){
if(function_exists('openssl_random_pseudo_bytes')) {
$rnd = openssl_random_pseudo_bytes($length, $strong);
if ($strong === TRUE)
return $rnd;
}
@thinkt4nk
thinkt4nk / apache-execution-time.js
Created June 23, 2014 17:44
Parse Log Files - Execution Time
#!/usr/bin/env node
var fs = require('fs');
var moment = require('moment');
if (!!~process.argv.indexOf('-p') && process.argv.length === 4)
parseLog(process.argv[3]);
else if (!!~process.argv.indexOf('-d')) {
var infile = (process.argv.length > 3) ? process.argv[3] : null;
dailyAverages(infile);
}
@thinkt4nk
thinkt4nk / even-width.js
Last active August 29, 2015 14:05
Even, whole element width with even, whole margin
var fullWidth = 290
var numberOfElements = 7
var positionOffset = 0
process.argv.forEach(function(arg) {
var offsetRegexp = /--offset=(\d+)/
if (offsetRegexp.test(arg))
positionOffset = parseInt(arg.replace(offsetRegexp, '$1'))
})
01. Die Krupps - Robosapien
02. KMFDM - Lust
03. Ministry - We Believe
04. Decoded Feedback - Breathe
05. Front 242 - Red Team
06. SA42 - Race of the Human Race
07. Portion Control - Swerve
08. Noise Unit - Firing Line
09. Autodafeh - Treasure Hunt
10. Orange Sector - Sturm (Martin Bodewell Remix)
@thinkt4nk
thinkt4nk / gist:831085
Created February 17, 2011 05:59
ajax boilerplate
$("a.ajax").live('click',function(e) {
e.preventDefault();
var $this = $(this);
url = $(this).attr('href');
$.get(url,function(data) {
if(data) {
if( $this.hasClass('addHtmlToParent') ) {
$this.parent().append(data); // append return content to parent
} else {
eval(data); // execute return js
@thinkt4nk
thinkt4nk / gist:832701
Created February 17, 2011 21:11
calendar with events on date jui
<script type="text/javascript">
function highlightDates(date) {
for ( var i = 0; i < agenda.length; i++) {
var start = agenda[i].substring(0,4) + '-' + num_pad(parseInt(agenda[i].substring(5,7)-1),2,'0') + '-' + agenda[i].substr(8,2);
//var start = agenda[i].date;
var dateString = date.getFullYear() + '-' + num_pad(date.getMonth(),2,'0') + '-' + num_pad(date.getDate(),2,'0');
if (start == dateString) {
return [ true, 'ui-state-active' ];
}
}
@thinkt4nk
thinkt4nk / twocolumnlist.php
Created February 24, 2011 22:47
dynamic two-column list
<?php
$list = array('this','that','theother','andthis');
$evenList = (count($list)%2==0) ? true : false;
$listOne = array();
$listTwo = array();
if( $evenList ) {
$half = count($list)/2;
$listOne = array_slice($list,0,$half);
@thinkt4nk
thinkt4nk / mtoinput.js
Created February 25, 2011 15:13
mto inputs
$(document).ready(function() {
// initial input addition
$(".forum_thumbnail_addThumbnail").live('click',function() {
var $this = $(this);
$.get('/forum/ajaxGetThumbnailInput',function(data,status) {
if( status == 'success' ) {
$(data).appendTo($this.parent().parent());
$this.parent().hide();
}
});
def get_attribute(self,attribute_name):
try:
return self.data[attribute_name]
except (KeyError,TypeError):
print self.data.__class__
exit()
import pprint
import psycopg2
import psycopg2.extras
from psycopg2.extras import DictConnection
class pgImport(object):
"""Imports data to pg instance"""
def __init__(self,dbname='template1',user='postgres',password='postgres',host='localhost'):
"""Constructor"""
self.db = psycopg2.connect('dbname=%s user=%s host=%s password=%s' % (dbname,user,host,password))