Skip to content

Instantly share code, notes, and snippets.

@halit
halit / exam.asm
Last active August 29, 2015 13:59
segment .text
global _start
_start:
XOR R5, R5 ; clear r5
XOR R6, R6 ; clear r6
INC R6 ; increment r6
SRC R1 ; shift right with carry
JC _carry ; if carry jump _carry
@halit
halit / path.c
Created April 4, 2014 18:56
matrix traverse problem
// =====================================================================================
//
// Filename: path.c
//
// Description:
//
// Version: 1.0
// Created: 03/26/2014 09:31:02 PM
// Revision: none
// Compiler: gcc
@halit
halit / fft.c
Created April 3, 2014 18:42
fast fourier transform with recursion
void _fft(double* buf, double* out, unsigned int n, unsigned int step){
if(step<n){
_fft(out, buf, n, step*2);
_fft(out+step, buf+step, n, step*2);
int i;
for(i=0;i<n;i += 2*step){
double t = cexp(-I*PI*i/n)*out[i+step];
buf[i/2] = out[i] + t;
buf[(i+n)/2] = out[i] - t;
@halit
halit / node.c
Last active August 29, 2015 13:58
simple abstract syntax tree and eval
#include <stdio.h>
#include <stdlib.h>
typedef union{
int i;
char c;
}_value;
typedef struct _node{
struct _node* left;
struct _node* right;
@halit
halit / html.py
Created January 28, 2014 18:33
html wrapper
class Tag(object):
"""HTML tag class"""
def __init__(self, item, value, **atts):
"""
HTML tag constructor
"""
self.__item = item
self.__value = value
self.__attributes = [' %s="%s"' % i for i in atts.items()]
self.__element = "<{item}{attributes}>{value}</{item}>".format(
@halit
halit / tailf.py
Created January 27, 2014 16:28
file follower
import sys
def tailf(f_file):
f_file.seek(0, 2)
while True:
l = f_file.readline()
if not l:
continue
yield l
@halit
halit / eco.py
Created January 25, 2014 18:41
Toy virtual economy
from faker import Faker
import random
fake = Faker()
pop = 100 # total population
mxval = 100 # max value
mnval = 1000 # min value
import requests
import re
from multiprocessing import Pool
url = "http://www.cs.umd.edu/~gasarch/bookrev/bookrev.html"
r_url = re.compile("HREF=.*.pdf\"")
r_replace_t = "HREF=\""
r_replace_w = "http://www.cs.umd.edu/~gasarch/bookrev/"
site_content = requests.get(url).content
# Thanking everyone who wished me on my birthday
import requests
import json
# Aman's post time
AFTER = 1353233754
@halit
halit / bitget.c
Last active December 17, 2015 05:19
getting bit value function inspired by duff's device
#define bitGet(v, n) ((v >> n) & 1)
int bitGet(int v, int n){
switch(n - 1){
case 7: v >>= 1;
case 6: v >>= 1;
case 5: v >>= 1;
case 4: v >>= 1;
case 3: v >>= 1;
case 2: v >>= 1;