Skip to content

Instantly share code, notes, and snippets.

View mahmoudhossam's full-sized avatar

Mahmoud Hanafy mahmoudhossam

  • Berlin, Germany
  • 10:48 (UTC +02:00)
View GitHub Profile
@mahmoudhossam
mahmoudhossam / Reverse.java
Created January 4, 2012 19:10
How to reverse strings in Java.
public class Reverse {
public static void main(String[] args) {
System.out.println(reverse("Mahmoud"));
}
public static String reverse(String src) {
StringBuilder builder = new StringBuilder();
for(int i = src.length() - 1; i >= 0; i--) {
builder.append(src.charAt(i));
@mahmoudhossam
mahmoudhossam / quicksort.py
Created December 11, 2011 16:53
A quicksort implementation in python.
def quicksort(lst):
for i in range(len(lst)):
for j in range(i,len(lst)):
if lst[i] > lst[j]:
lst[i], lst[j] = lst[j], lst[i]
return lst
@mahmoudhossam
mahmoudhossam / toTen.py
Created December 11, 2011 16:39
A function that counts to 10 without using a loop.
def toTen(x):
if(x < 11):
print x
toTen(x + 1)
@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:
@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 / 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 / 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 / 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 / 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 / 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