Skip to content

Instantly share code, notes, and snippets.

@luqmaan
luqmaan / modulo3.v
Created August 12, 2013 15:25
A Verilog implementation of a finite state machine to determine the modulus of any number by three, in realtime. The number can be input in most significant bit (MSB) first or least significant bit (LSB) first order. The msb_modulus and lsb_modulus modules return the modulus of the number as the number is entered. Uses only and, or, not, xor, a…
/*
A Verilog implementation of a finite state machine to determine the
modulus of any number by three, in realtime.
The number can be input in most significant bit (MSB) first or least
significant bit (LSB) first order. The msb_modulus and lsb_modulus
modules return the modulus of the number as the number is entered.
Uses only and, or, not, xor, and nand gates. Also uses a clock to
coordinate the modules.
@luqmaan
luqmaan / jshint.json
Last active December 20, 2015 07:09
My SublimeLinter jshint settings
{
"pep8": false,
"sublimelinter_disable": [
"python",
"pep8"
],
"javascript_linter": "jshint",
"jshint_options": {
"white": false,
"indent": 4,
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')
@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]
@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 / 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 / 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 / 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 / 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 / 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(',');