Skip to content

Instantly share code, notes, and snippets.

View KartikTalwar's full-sized avatar
🚀
Gone phishing

Kartik Talwar KartikTalwar

🚀
Gone phishing
View GitHub Profile
@KartikTalwar
KartikTalwar / tiny.c
Created July 12, 2012 04:37
Tiny-C Compiler
/* file: "tinyc.c" */
/* Copyright (C) 2001 by Marc Feeley, All Rights Reserved. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
* This is a compiler for the Tiny-C language. Tiny-C is a
@KartikTalwar
KartikTalwar / cppObsfucated.cpp
Created July 13, 2012 06:39
Obfuscated C++ Code
#include <stdio.h>
#include <time.h>
#define O_O const char*
#define __ if
#define ___ while
#define OO void
O_O O[]={"$%&'(#)*+,-./0#1234567#)89:;<=>#","0?@ABC5D#EFBG#",
"HIJBK#HILBM#HINO-PB#HIFBQ#HIRS#HIATU-VB#","WXY=Z.[#\\]^_`#abc'Rd#efg*h^ij#k*+l-mInd#opBqrC5D#"
,"sJBK#sJBK#HIJtIJ#uBK#HIJtIJ#uBK#","WXY=Z.[#\\]^_`#abc'Rd#efg*h^ij#","\n","I;y.;","21","-,.?29;.-",",1","41*;",
@KartikTalwar
KartikTalwar / NearestGridPoint.py
Created July 15, 2012 22:34
Nearest Grid Coordinate
def generateGrid(x, y, r=1):
matrix = []
for dy in xrange(-r, r+1):
for dx in xrange(-r, r+1):
matrix.append((x+dx, y+dy))
return matrix
print generateGrid(0, 1)
"""
@KartikTalwar
KartikTalwar / HungarianAlgorithm.py
Created July 22, 2012 05:21
Hungarian Algorithm
#!/usr/bin/python
# ecole polytechnique - c.durr - 2009
# Kuhn-Munkres, The hungarian algorithm. Complexity O(n^3)
# Computes a max weight perfect matching in a bipartite graph
# for min weight matching, simply negate the weights.
""" Global variables:
n = number of vertices on each side
U,V vertex sets
@KartikTalwar
KartikTalwar / GreedyCoin.py
Created July 28, 2012 00:07
Simple Greedy Coin Algorithm
def bestChange(denominations, amount):
if amount == 0:
return []
for i in denominations:
if i <= amount:
return [i] + bestChange(denominations, amount-i)
denominations = [100, 50, 20, 10, 5, 2, 1]
amount = 109
@KartikTalwar
KartikTalwar / LFSR.java
Created July 31, 2012 04:20
Galois linear feedback shift register (LFSR)
/*
* Galois linear feedback shift register (LFSR) in Java
* Copyright (c) 2012 Nayuki Minase
*/
import java.math.BigInteger;
import java.util.Random;
/**
@KartikTalwar
KartikTalwar / GooglePageRankCheckSum.php
Created August 2, 2012 22:34
Google PageRank Checksum Algorithm
<?php
function fch($csm)
{
if($csm < 0)
$csm += 4294967296.0;
$a = (int)fmod($csm, 10);
$t = 1;
$b = (int)($csm / 10);
@KartikTalwar
KartikTalwar / phptest.xml
Created August 18, 2012 20:02
PHP Lib Test
<?xml version="1.0" encoding="UTF-8"?>
<test>
<case>42</case>
</test>
@KartikTalwar
KartikTalwar / TwitterCheck.php
Created August 18, 2012 20:24
Twitter Followers Prereq Check
<?php
/*
Usage:
@KartikTalwar
KartikTalwar / HungarianAlgorithm.java
Created September 15, 2012 23:13
Hungarian Algorithm
import java.util.Arrays;
/* Copyright (c) 2012 Kevin L. Stern
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is