Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am pr4v33n on github.
  • I am praveen_t (https://keybase.io/praveen_t) on keybase.
  • I have a public key ASB-NcvzFizUOVdZkP_KsczQYjNfyQR64Tl4UwrtmjSBcQo

To claim this, I am signing this object:

// gviztablelog.js
// https://github.com/pr4v33n
// Adds a `gvizTableLog` function to window object.
// https://developers.google.com/chart/interactive/docs/reference#DataTable
(function() {
window.gvizTableLog = function(dataTable) {
var rowIndex = 0, tableData = [], columnIndex = 0, columnLabels = [];
while (columnIndex < dataTable.getNumberOfColumns()) {
columnLabels.push(dataTable.getColumnLabel(columnIndex) ||
//stateChangeHandler will fire when the state has changed, i.e. data is received back
// This is non-blocking (asynchronous)
function stateChangeHandler() {
//readyState of 4 or 'complete' represents that data has been returned
if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete') {
//Gather the results from the callback
var str = xmlHttp.responseText;
if (str != "") {
//document.getElementById('msgPanel').innerHTML += str;
var msgs = str.split('#');

I was reading the gist @https://gist.github.com/2012250

I found the autovivification functionality of it pretty cool. If only I could have a parent reference...

Obviously this was not going to be a one-line tree. But that wasn't the goal

A simple variant:

from collections import defaultdict
@pr4v33n
pr4v33n / tree.md
Created January 8, 2013 22:36 — forked from hrldcpr/tree.md

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

@pr4v33n
pr4v33n / demo.py
Created February 17, 2012 00:37
cedric's challenge
"""
Challenge: http://beust.com/weblog/2012/02/16/a-new-coding-challenge-2/
Author: Praveen Kumar T
The Test:
--------
The probability distribution of the number of fixed points of a
uniformly distributed random permutation approaches a Poisson
distribution with expected value 1 as n grows.
he first n moments of this distribution are exactly those of
@pr4v33n
pr4v33n / appengine.txt
Created January 30, 2012 13:36
Batch operations
09:41:38 PM) h0x5f3759df: Hi, is there any limit on batch write for db.put() ?
(09:42:41 PM) h0x5f3759df: if i have to put 100 entities, Should i put them in batches of 10 using db.put() or can i do db.put() on all 100 in a single go?
(09:48:36 PM) mbw: you should be able to do all at once
(09:54:38 PM) dw: h0x5f3759df: the limit is on the size of the underlying RPC iirc, which is (i think?) is 10mb
(09:59:07 PM) Sonderblade left the room (quit: Quit: L?mnar).
(09:59:37 PM) mbw: the sdk will split it up for you
(10:00:03 PM) mbw: it didnt used to do that,but will now
(10:00:35 PM) proppy: 1mb
(10:00:45 PM) proppy: for db.put() is the limit
(10:00:49 PM) mbw: 1mb per entity, not rpc
@pr4v33n
pr4v33n / appengine.txt
Created January 30, 2012 13:06
ListProperty and Index generation
class Foo(db.Model):
bar = db.ListProperty(required=True)
If i have 5 entities of kind "Foo"
Entity1.bar = ["abc"]
Entity2.bar = ["def"]
Entity3.bar = ["ghi"]
Entity4.bar = ["klm", "nop"]
Entity5.bar = ["qrs", "tuv", "wxy"]
@pr4v33n
pr4v33n / demo1.cpp
Created November 22, 2011 06:56
xd13
#include <iostream>
#include <math.h>
using namespace std;
class Complex
{
public:
Complex();
Complex(double,double);
void setCr(double);
@pr4v33n
pr4v33n / ismultiple.cpp
Created October 9, 2011 16:05
isMultiple
bool isMultiple(int a, int b) {
return !(b%a);
}
bool isMultiple(int a, int b) {
return (b%a == 0);
}
bool isMultiple(int a, int b) {
return (b%a)?false:true;