Skip to content

Instantly share code, notes, and snippets.

@ameerkat
ameerkat / order_statistics.py
Created December 10, 2010 21:04
Order statistics using randomized pivot
# Order Statistics
# Ameer Ayoub <ameer.ayoub@gmail.com>
import random, copy
# From quicksort
# Nonrandomized Pivot
def partition(l, p, q, pivot=None):
r = copy.copy(l)
if pivot:
r[pivot], r[p] = r[p], r[pivot]
@ameerkat
ameerkat / euler39optimized.py
Created April 5, 2011 04:28
Fully optimized euler #39!
from fractions import gcd
def euler39optimized():
sum_count = [0] * 1001
y = 2
while y**2 <= 500:
for z in [x for x in range(y) if gcd(y, x) == 1]:
a = y**2 - z**2
b = 2*y*z
c = y**2 + z**2
@ameerkat
ameerkat / inc_v_num.py
Created May 19, 2011 01:20
Increment version number in drupal module info file
# increment_version_num.py
# Utility to incremement version number in drupal info files
# Ameer Ayoub <ameer.ayoub@gmail.com>
import re, sys, os
major_v = 0
minor_v = 0
def inc_dv_num(s, minor = True):
global major_v, minor_v
@ameerkat
ameerkat / fib3.cpp
Created June 14, 2011 21:39
Calculating Fibonacci numbers with matrices
/* Fibonacci Calculation using Matrices
* Ameer Ayoub <ameer.ayoub@gmail.com>
* Jun 13, 2011
*/
#include <iostream>
#include <math.h>
using namespace std;
const int fib_matrix_size = 2;
@lifthrasiir
lifthrasiir / README.txt
Created July 10, 2011 19:04
A little program that converts "a hundred" to "100". (Updated!)
These little programs read a spelt (EDIT: it is not "spoken") number from the
standard input and write the corresponding number to the standard output. Weigh
just 243 bytes and 227 bytes of C. (EDIT: was originally 256 and 240 bytes.)
The longer version handles numbers up to 999,999,999,999,999, that is, just
shy of 1,000 trillions. The shorter version handles numbers up to 19,999,999,
or 999,999,999 if your "int" is 64 bits long. The input should be correct,
although it will handle "a" and "and" correctly and ignore some invalid
words.
using System;
using StructureMap;
namespace ConsoleApplication1
{
class Program {
private static void Main(string[] args) {
IContainer container = ConfigureDependencies();
IAppEngine appEngine = container.GetInstance<IAppEngine>();
@ameerkat
ameerkat / sorts.py
Created December 7, 2010 15:04
Various sorts implemented in Python (Insertion, Bubble, Merge, Quick, Counting)
# BunchO Sorting Algorithms
# Ameer Ayoub <ameer.ayoub@gmail.com>
# Last Modified 12/2/2010
import random
#
# Insertion Sort
#
def insertion_sort(l):
"""Given an input list, returns a sorted permutation of the list
@jeresig
jeresig / .vimrc
Created May 4, 2011 16:46
VIM Config
au BufRead,BufNewFile jquery.*.js set ft=javascript syntax=jquery
set nocompatible
set autoindent
set tabstop=2
set showmatch
set vb t_vb=
set ruler
set nohls
set incsearch
syntax on
@bzerangue
bzerangue / google-weather-api-conditions.xml
Created February 1, 2011 23:13
Google Weather API Conditions List
<?xml version="1.0" encoding="UTF-8"?>
<!--Google Weather API Conditions. Compiled by Dennis Delimarsky, http://dennisdel.com/content/conditions.xml-->
<!--Tweaked by Brian Zerangue, February 1, 2011-->
<conditions>
<type handle="partly-sunny">Partly Sunny</type>
<type handle="scattered-thunderstorms">Scattered Thunderstorms</type>
<type handle="showers">Showers</type>
<type handle="scattered-showers">Scattered Showers</type>
<type handle="rain-and-snow">Rain and Snow</type>
<type handle="overcast">Overcast</type>
@ameerkat
ameerkat / BoyerMooreStringSearch.py
Created October 14, 2010 17:46
Boyer Moore string search implementation in Python
# Boyer Moore String Search implementation in Python
# Ameer Ayoub <ameer.ayoub@gmail.com>
# Generate the Bad Character Skip List
def generateBadCharShift(term):
skipList = {}
for i in range(0, len(term)-1):
skipList[term[i]] = len(term)-i-1
return skipList