Skip to content

Instantly share code, notes, and snippets.

@luqmaan
luqmaan / getKloutScore.php
Created December 20, 2011 17:55
Get's a users klout score
function getKloutScore($handle, $key) {
$url = "http://api.klout.com/1/klout.json?users=$handle&key=$key";
$response = file_get_contents($url);
$result = json_decode($response, true);
$score = $result[users][0][kscore];
return $score;
@luqmaan
luqmaan / gist:3975949
Created October 29, 2012 19:27
Strip the MailChimp email templates of their comments
@luqmaan
luqmaan / alterColor.js
Created November 29, 2012 14:38
Darkens or lightens a CSS RGB color.
/**
* Darkens or lightens a CSS RGB color. Derived from http://www.sitekickr.com/coda/jquery/darken-background-color-element.html
* @param {string} rgb "rgb(26,26,26)""
* @param {string} type "darken" or "lighten"
* @param {int} percent
* @return {string} returns the altered RGB color
*/
function alterColor(rgb, type, percent) {
rgb = rgb.replace('rgb(', '').replace(')', '').split(',');
@luqmaan
luqmaan / dabblet.css
Created December 12, 2012 17:06
spark a animation
/* spark a animation */
@keyframes pound1 {
0% {
transform: rotateX(90deg) scale(0);
}
100% {
transform: rotateX(0deg) scaleX(1) scaleY(1) scaleZ(1);
}
@luqmaan
luqmaan / mon.py
Last active December 14, 2015 16:48
LiveReload for the terminal. Performs a shell command whenever a matching file changes. Just specify the command to run and the file extensions to monitor.
#!/usr/bin/env python
""" Example:
Enter command to run when a matched file changes:
g++ hashing.cpp - o main & & ./main
Enter space seperated list of file extensions to monitor:
.cpp .h
"""
import os
@luqmaan
luqmaan / gist:5268070
Last active December 15, 2015 13:29
Dump memory in C++. Be sure to change the type from unsigned char* to whatever is needed. Original at http://stackoverflow.com/questions/1286725/hex-dump-from-memory-location.
void Dump( unsigned char* *mem, unsigned int stop ) {
cout << "mem = " << mem << endl;
unsigned char * p = reinterpret_cast< unsigned char*>( mem );
for ( int i = 0; i < n; i++ ) {
std::cout << " " << i << " " << (mem+i) << " " << std::hex << int(p[i]) << std::dec << " " << endl;
}
}
@luqmaan
luqmaan / api.json
Created April 19, 2013 13:53
Is there a faster/easier way to loop through the NSArray of NSDictionaries and find a NSDictionary with a specific key/value?
"routes": [{
"id": "Hillsborough Area Regional Transit_6",
"textColor": "FFFFFF",
"color": "09346D",
"description": "",
"longName": "56th Street",
"shortName": "6",
"type": 3,
"agencyId": "Hillsborough Area Regional Transit",
"url": "http://www.gohart.org/routes/hart/06.html"
@luqmaan
luqmaan / test.py
Created June 23, 2013 19:37
Generates a big test file for the Sort! Sort!! and Sort!!! problem from UVA Online Judge. http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2296
#!/usr/bin/env python
import random
fname = 'test-input.txt'
fout = None
debug = False
def write(out):
global fout
@luqmaan
luqmaan / numpy_algo.py
Last active December 19, 2015 07:29
From the PyBulls meeting on July 21. NumPy based solution to the Sort! Sort!! and Sort!!! problem from UVA Online Judge. http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2296
#!/usr/bin/env python
import numpy
import linecache
out_str = ""
def picklines(thefile, whatlines):
return [x for i, x in enumerate(thefile) if i in whatlines]
import networkx as nx
def draw_graph(G):
from matplotlib import pyplot
pos = nx.graphviz_layout(G, prog='dot')
labels = dict((n, '%d' % n) for n, d in G.nodes(data=True))
edge_labels = dict(((u, v,), d['op']) for u, v, d in G.edges(data=True))
nx.draw_networkx(G, pos=pos, labels=labels, node_size=1000,
width=2, node_color='white', edge_color='blue')