Skip to content

Instantly share code, notes, and snippets.

🌴
On vacation

t k tahia-khan

🌴
On vacation
Block or report user

Report or block tahia-khan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tahia-khan
tahia-khan / perm_trie.py
Last active Aug 29, 2015
Given a string, prints out all possible permutations using a Trie. Solutions for both with and without duplicate characters. Implemented in python.
View perm_trie.py
__author__ = 'shawli'
#no duplicates
class Trie:
def __init__(self, ch=""):
self.ch = ch #character
self.br = [] #branches
@tahia-khan
tahia-khan / gobtime.go
Created Jun 9, 2015
Quickly benchmark how long gobbing and ungobbing takes
View gobtime.go
package main
import (
"encoding/gob"
"fmt"
"os"
"time"
)
func main() {
@tahia-khan
tahia-khan / iprange_to_cidrs.go
Created Jul 27, 2015
rough script, still in development
View iprange_to_cidrs.go
package main
import (
"fmt"
"math"
"strconv"
"strings"
)
func IPToInt(ip string) uint {
@tahia-khan
tahia-khan / getshelf.py
Last active Aug 29, 2015
get goodreads shelves
View getshelf.py
import xmltodict
import os
import json
import requests
def request_user_shelves(parms):
p = dict(parms.items() + {"key":os.environ.get("GOODREADS_ACCESS_KEY")}.items())
resp = requests.get("https://www.goodreads.com/shelf/list.xml",p)
data_dict = xmltodict.parse(resp.content)
data_dict = data_dict['GoodreadsResponse']['shelves']
View qsort.c
#include <stdio.h>
void qsort(int *X, int L, int U) {
int T, M, i, tmp;
if (L < U) {
T = X[L];
M = L;
for (i = L+1; i < U; i++) {
if (X[i] < T) {
M += 1;
View ll.c
#include <stdio.h>
#include <stdlib.h>
typedef struct Node {
struct Node *prev;
struct Node *next;
int data;
} Node;
View bst.py
class Node:
def __init__(self, data):
self.data = data
self.lchild = None
self.rchild = None
def insert(self, key):
if key < self.data:
if self.lchild:
self.lchild.insert(key)
@tahia-khan
tahia-khan / graph.c
Created Nov 8, 2015
adjacency list implementation in c
View graph.c
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#define N 10
typedef struct {
int y;
int weight;
struct Edge *next; /* next in adj list */
View graph.py
# graph.py
class Vertex:
def __init__(self, x):
self.x = x
self.edges = {}
def __str__(self):
return "Vertex %d: %s" % (self.x, self.edges)
@tahia-khan
tahia-khan / detect_cycles.py
Last active Nov 9, 2015
given adjacency matrix, detect # of cycles in directed graph
View detect_cycles.py
def find_cycles(g, x, path, num_cycles):
if x in path:
num_cycles+=1
return num_cycles
path.append(x)
N = len(g[x])
for i in range(N):
if g[x][i]:
You can’t perform that action at this time.