Skip to content

Instantly share code, notes, and snippets.

Avatar

Ameer Ayoub ameerkat

View GitHub Profile
@ameerkat
ameerkat / score.py
Created Mar 10, 2018
Calculate the object by object mIOU for the 2018 Data Science Bowl
View score.py
# score.py
import os
import settings
from tqdm import tqdm
from skimage.io import imread
import numpy as np
import metrics
from keras.models import Model, load_model
from skimage.morphology import label
from skimage.transform import resize
@ameerkat
ameerkat / app.config
Created Apr 7, 2017
Simple log4net format for console logging
View app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
@ameerkat
ameerkat / MD5.cs
Created Oct 29, 2016
MD5 Implementation in C# based on Wikipedia psuedocode
View MD5.cs
using System;
using System.Linq;
namespace MD5
{
/// <summary>
/// RFC for MD5 https://tools.ietf.org/html/rfc1321
/// Based on the pseudo code from Wikipedia: https://en.wikipedia.org/wiki/MD5
/// </summary>
public class MD5
View missing_number.py
def missing_number(s_final):
for starting_length in range(1, (len(s_final)/2) + 1):
s = s_final[:] # copy
skipped = -1
starting_number = int(s[:starting_length])
plus_one = starting_number + 1 # the two valid options
plus_two = starting_number + 2
s = s[starting_length:]
round_passed = True
while s and round_passed:
@ameerkat
ameerkat / SendScreencap
Created Mar 16, 2015
Send yourself a text and screenshot url. Useful for monitoring a long pending build/deploy operation.
View SendScreencap
import tempfile, uuid, pyscreenshot
from twilio.rest import TwilioRestClient
from azure.storage import BlobService
# Your Account Sid and Auth Token from twilio.com/user/account
twilio_account_sid = ""
twilio_auth_token = ""
client = TwilioRestClient(twilio_account_sid, twilio_auth_token)
# Screencap
@ameerkat
ameerkat / 2012_C.py
Created Apr 17, 2012
2012 Code Jam Qualifier C
View 2012_C.py
def rotate(n, i):
j = 0
s = str(n)
while(j < i):
s = s[-1] + s[:-1]
j += 1
return int(s)
def rn(n, m):
count = 0
@ameerkat
ameerkat / 2012_B.py
Created Apr 17, 2012
2012 Code Jam Qualifier B
View 2012_B.py
def gen_trip(n, p):
flag = False
trips = []
for i in range(0,11):
for j in range(0, 11):
for k in range(0, 11):
if i + j + k == n:
if(max([i,j,k]) - min([i,j,k]) <= 2 and max([i,j,k]) >= p):
trips.append([i, j, k])
if(max([i,j,k]) - min([i,j,k]) <= 1):
@ameerkat
ameerkat / 2012_A.py
Created Apr 17, 2012
2012 Code Jam Qualifier A
View 2012_A.py
d = {}
s1 = "yeqz ejp mysljylc kd kxveddknmc re jsicpdrysi rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd de kr kd eoya kw aej tysr re ujdr lkgc jv"
s2 = "aozq our language is impossible to understand there are twenty six factorial possibilities so it is okay if you want to just give up"
for ch in range(len(s1)):
d[s1[ch]] = s2[ch]
f = open("A.in")
t = int(f.readline().strip())
for i in range(1,t+1):
print "Case #"+ str(i) + ": " + ''.join([(d[ch] if ch in d else ch) for ch in f.readline()]),
@ameerkat
ameerkat / ubgd.py
Created Feb 16, 2012
Univariate Batch Gradient Descent
View ubgd.py
# Univariate Batch Gradient Descent - Linear Regression
# Derived from Andrew Ng's Lectures on Machine Learning (Lecture 2)
# Ameer Ayoub <ameer.ayoub@gmail.com> 2/16/2012
import math
import matplotlib.pyplot as plt
def pd_sqr_err0(theta0, theta1, x, y):
m = len(x)
return sum([(1.0/m)*((theta0 + theta1 * x[i]) - y[i]) for i in range(m)])
@ameerkat
ameerkat / splitter.py
Created Nov 27, 2011
scanned page splitter
View splitter.py
from PIL import Image
import math, os, sys
def calculate_seam(im, band_width, middle_bias = True, middle_bias_strength = 2):
pix = im.load()
size = im.size
max_std_dev = 0
max_col = 1
for i in range(band_width, im.size[0]-band_width+1):
multiplier = (1-(4*math.sqrt((i-im.size[0]/2)**2)/im.size[0]/2))**middle_bias_strength
You can’t perform that action at this time.