Skip to content

Instantly share code, notes, and snippets.

View mahmoudhossam's full-sized avatar
🏗️

Mahmoud Hanafy mahmoudhossam

🏗️
  • Berlin, Germany
  • 12:59 (UTC +02:00)
View GitHub Profile
import requests
def unshorten(url):
try:
r = requests.head(url, allow_redirects=True)
except:
return r.url
return r.url
@mahmoudhossam
mahmoudhossam / BubbleSort.java
Created August 19, 2011 16:44
Bubble Sort attempt#1
import java.util.Arrays;
public class BubbleSort {
public static void main(String[] args){
int[] numbers = {9, 2, 7, 4, 6};
int[] sorted = sort(numbers);
System.out.println(Arrays.toString(sorted));
}
public static int[] sort(int[] input){
@mahmoudhossam
mahmoudhossam / Bottles.java
Created October 26, 2011 18:46
A failed attempt at 99 bottles of beer in Java.
public class Bottles {
public static void main (String args[]) {
String lyrics = "%1$d bottles of beer on the wall, %1$d bottles" +
" of beer.\nTake one down and pass it around, %2$d bottles of" +
" beer on the wall.\n";
String lyricsTwo = "%1$d bottle of beer on the wall, %1$d bottle" +
" of beer.\nTake one down and pass it around, %s bottles of beer" +
" on the wall.\n";
String lyricsOne = "%1$d bottle of beer on the wall, %1$d bottle" +
@mahmoudhossam
mahmoudhossam / find_dups.py
Created November 6, 2011 09:19
A function that returns duplicates in a list of integers
def find_dups(l):
orig = []
dups = []
for i in l:
if i in orig:
dups.append(i)
else:
orig.append(i)
return dups
@mahmoudhossam
mahmoudhossam / pairs.py
Created November 6, 2011 09:38
A function that takes two equal-sized sets, returns a set of pairs of the elements of the two sets.
import copy
def mating_pairs(m, f):
males = copy.deepcopy(m)
females = copy.deepcopy(f)
pairs = set()
for i in m:
pairs.add((males.pop(), females.pop()))
return pairs
@mahmoudhossam
mahmoudhossam / complement.py
Created November 7, 2011 02:24
Finds a DNA sequence complement
#!/usr/bin/python2
"""
A DNA sequence is a string made up of the letters A, T, G, and C.
To find the complement of a DNA sequence, As are replaced by Ts,
Ts by As, Gs by Cs, and Cs by Gs. For example, the complement
of AATTGCCGT is TTAACGGCA.
This function finds the complement.
@mahmoudhossam
mahmoudhossam / max_min.py
Created November 7, 2011 04:55
functions that find the biggest, smallest number or either in a list of numbers.
"""
functions that find the biggest, smallest number or either in a list of numbers.
"""
def min_index(seq):
value = seq[0]
index = 0
for i in seq:
if i < value:
@mahmoudhossam
mahmoudhossam / StartingPoint.java
Created November 13, 2011 18:03
A file manager for Android
package com.tumblr.taabouzeid.file.explorer;
import java.io.File;
import java.util.ArrayList;
import org.apache.commons.io.FilenameUtils;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
@mahmoudhossam
mahmoudhossam / main.xml
Created November 13, 2011 18:34
Simple file manager layout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tvLocation"
android:layout_width="wrap_content"
@mahmoudhossam
mahmoudhossam / selection_sort.py
Created November 28, 2011 13:17
A python implementation of the selection sort algorithm
'''
Created on Nov 26, 2011
@author: Mahmoud
'''
def sort(seq):
pos = 0
length = len(seq)
for i in seq: