Skip to content

Instantly share code, notes, and snippets.

@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))
public Dictionary<string,Object> getChildrenRecursive()
{
Dictionary<string,Object> categoryDictionary = new Dictionary<string, Object>();
Dictionary<string, Object>[] children;
if (this.hasChildren())
{
// Get child nodes
Duke.CategoryDataTable ChildTable = this.CategoryAdapter.GetAllByParentCategory(categoryCode);
children = new Dictionary<string, Object>[ChildTable.Rows.Count];
for (int i = 0; i < ChildTable.Rows.Count; i++)
<%
Action<System.Data.DataTable, int> printCategoriesRecursively = null;
printCategoriesRecursively = (System.Data.DataTable categoryRows, int depth) => {
if (categoryRows==null || categoryRows.Rows.Count==0) return;
%>
<ul class="node-list depth-<%=depth%>">
<%
foreach (System.Data.DataRow CategoryRow in categoryRows.Rows) {
%>
<li>
@thinkt4nk
thinkt4nk / serializeObject.js
Created April 6, 2011 13:54
Serialize an object from jquery serialized array
$.fn.serializeToObject = function() {
var serial_array = this.serializeArray();
var serial_object = {};
$(serial_array).each(function() {
if( !serial_object[this.name] )
{
serial_object[this.name] = this.value;
}
});
return serial_object;
@thinkt4nk
thinkt4nk / dynamic_image_loading.js
Created May 10, 2011 15:45
Dynamic Image Loading with jquery
// load an image - with a callback on load
function loadImageDynamic(image_url,callback,container) {
if( container != 'undefined' ) {
container = 'body';
}
var image_load = 0;
$('<img/>')
.attr('src',image_url)
.load( function(e) {
if( image_load < 1 ) { // webkit hack to protect from multiple loads on cached images