Skip to content

Instantly share code, notes, and snippets.

View ta1hia's full-sized avatar
🌴
gone fishin' (05/15/2025 - 06/03/2025)

tahia ta1hia

🌴
gone fishin' (05/15/2025 - 06/03/2025)
View GitHub Profile
@ta1hia
ta1hia / perm_trie.py
Last active August 29, 2015 13:56
Given a string, prints out all possible permutations using a Trie. Solutions for both with and without duplicate characters. Implemented in python.
__author__ = 'shawli'
#no duplicates
class Trie:
def __init__(self, ch=""):
self.ch = ch #character
self.br = [] #branches
@ta1hia
ta1hia / gobtime.go
Created June 9, 2015 23:21
Quickly benchmark how long gobbing and ungobbing takes
package main
import (
"encoding/gob"
"fmt"
"os"
"time"
)
func main() {
@ta1hia
ta1hia / iprange_to_cidrs.go
Created July 27, 2015 20:45
rough script, still in development
package main
import (
"fmt"
"math"
"strconv"
"strings"
)
func IPToInt(ip string) uint {
@ta1hia
ta1hia / getshelf.py
Last active August 29, 2015 14:28
get goodreads shelves
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']
#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;
@ta1hia
ta1hia / ll.c
Created November 7, 2015 20:08
#include <stdio.h>
#include <stdlib.h>
typedef struct Node {
struct Node *prev;
struct Node *next;
int data;
} Node;
@ta1hia
ta1hia / bst.py
Last active November 8, 2015 04:45
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)
@ta1hia
ta1hia / graph.c
Created November 8, 2015 18:39
adjacency list implementation in 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 */
@ta1hia
ta1hia / graph.py
Last active November 9, 2015 00:18
# graph.py
class Vertex:
def __init__(self, x):
self.x = x
self.edges = {}
def __str__(self):
return "Vertex %d: %s" % (self.x, self.edges)
@ta1hia
ta1hia / detect_cycles.py
Last active November 9, 2015 01:13
given adjacency matrix, detect # of cycles in directed graph
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]: