Skip to content

Instantly share code, notes, and snippets.

@bkamapantula
bkamapantula / graph.json
Created February 28, 2014 22:05
test graph file
{"nodes":[{"degc":0.1135135135,"group":1,"name":"93\n","bwn":0.0302200404,"deg":21},{"degc":0.0810810811,"group":1,"name":"81\n","bwn":0.0132142387,"deg":15},{"degc":0.027027027,"group":1,"name":"28\n","bwn":0.0013243649,"deg":5},{"degc":0.0540540541,"group":1,"name":"54\n","bwn":0.005441404,"deg":10},{"degc":0.0486486486,"group":1,"name":"40\n","bwn":0.0040485988,"deg":9},{"degc":0.027027027,"group":1,"name":"34\n","bwn":0.0011102586,"deg":5},{"degc":0.1243243243,"group":1,"name":"69\n","bwn":0.0279832556,"deg":23},{"degc":0.0864864865,"group":1,"name":"24","bwn":0.0169650797,"deg":16},{"degc":0.0810810811,"group":1,"name":"25","bwn":0.0128248822,"deg":15},{"degc":0.0486486486,"group":1,"name":"26","bwn":0.0031609679,"deg":9},{"degc":0.0810810811,"group":1,"name":"27","bwn":0.015093073,"deg":15},{"degc":0.0702702703,"group":1,"name":"20","bwn":0.0086559008,"deg":13},{"degc":0.0972972973,"group":1,"name":"21","bwn":0.0197618924,"deg":18},{"degc":0.0540540541,"group":1,"name":"49\n","bwn":0.0051206979,"deg":10
1 2
2 16
3 19
4 20
5 12
6 1
7 8
8 17
9 11
10 4
@bkamapantula
bkamapantula / generate-pairs-from-n-items.py
Created November 1, 2013 18:38
Generate list of unique pairs (a, b) from N elements ensuring all elements participate in a and b.
import sys, random
fout = open('pairs.txt', 'w')
# total number of people participating
total_people = int(sys.argv[1])
a, b = [], []
for i in xrange(1, total_people+1):
a.append(i)
@bkamapantula
bkamapantula / cin.html
Created July 18, 2013 20:12
Crime in India - CIN
Crime in India
Crime in India is a portal to track the number of crimes categorized by crime type. The data used by CIN is from NCRB (National Crime Records Bureau).
Category: Side project
@bkamapantula
bkamapantula / map.html
Last active December 19, 2015 23:09
MAP
Mps Attending Parliament
This project tracks the number of MPs attending parliament in every parliament session.
Category: Side project
@bkamapantula
bkamapantula / searchPattern
Created June 7, 2013 15:36
Sorts file uniquely and searches for a pattern using egrep
sort filename.txt| uniq > test.txt; egrep -e 'pattern' test.txt
@bkamapantula
bkamapantula / implode.php
Created April 19, 2013 15:09
PHP implode
"SELECT .... mysql_column IN('".implode("','", $str).'\')'."GROUP BY ....";
@bkamapantula
bkamapantula / radioButtonCreation.js
Created January 31, 2013 21:15
Creating radio buttons on the fly
<script>
$(document).ready(function(event) {
var data = <?php echo json_encode($uploadedData);?>;
for (var j=0; j<data.length; j++) {
if(j == 0) {
$('<input >', {type: 'radio', value: data[j]['type'], name: "radioButtons", checked: true }).appendTo('#target');
}
else {
$('<input >', {type: 'radio', value: data[j]['type'], name: "radioButtons" }).appendTo('#target');
}
@bkamapantula
bkamapantula / read-csv.php
Created January 27, 2013 06:36
Read CSV file in PHP
<?php
function csvToArrayTwo($file, $delimiter) {
if (($handle = fopen($file, 'r')) !== FALSE) {
$i = 0;
while (($lineArray = fgetcsv($handle, 4000, $delimiter, '"')) !== FALSE) {
for ($j = 0; $j < count($lineArray); $j++) {
$arr[$i][$j] = $lineArray[$j];
}
$i++;
}
@bkamapantula
bkamapantula / embedImage.py
Created December 9, 2012 23:46
Embed image in webpage using Python and CGI
# http://stackoverflow.com/a/7389616/514874
data_uri = open('/path/to/image/image.png', 'rb').read().encode('base64').replace('\n', '')
img_tag = '<img src="data:image/png;base64,{0}" width="400" height="275">'.format(data_uri)
# I embedded .png image generated by Pyplot. Full credit to Glider@SO (http://stackoverflow.com/users/940789/glider) for making this work!