Skip to content

Instantly share code, notes, and snippets.

View mahmoudhossam's full-sized avatar
🏗️

Mahmoud Hanafy mahmoudhossam

🏗️
  • Berlin, Germany
  • 07:23 (UTC +02:00)
View GitHub Profile
@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 / 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 / storage.cpp
Created January 22, 2012 04:58
Storing user input as strings in a vector.
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
int main()
{
std::string input = "crap";
std::vector<std::string> storage;
@mahmoudhossam
mahmoudhossam / devices.py
Created January 28, 2012 11:36
Writes devices' status to a file.
import sys
files = ['lamp.txt', 'tv.txt', 'computer.txt']
device_number = int(sys.argv[1])
state = int(sys.argv[2])
#checks if the device number given is valid.
def check_devnum():
return 0 < device_number < 3
@mahmoudhossam
mahmoudhossam / Test.java
Created February 7, 2012 22:11
something I don't even know
import java.util.ArrayList;
import javax.swing.*;
public class Test{
enum concentrations {MATH, SCIENCE, ENGLISH, WEB};
public static void main(String[] args) {
ArrayList<String> names = new ArrayList<String>(); //stores student's names
#!/usr/bin/python2
ex = [1, 2, 3, 4, 5, 6]
bs = 2
def extract(lst, bs):
result = []
for i in range(bs):
result.append(lst.pop())
result.reverse()
@mahmoudhossam
mahmoudhossam / xkcd.py
Created March 30, 2012 13:23
xkcd comic grabber
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#
# xkcd.py
#
# xkcd comic grabber
from urllib2 import urlopen
from BeautifulSoup import BeautifulSoup
@mahmoudhossam
mahmoudhossam / abs.clj
Created May 4, 2012 13:15
The abs function, implemented in Clojure.
(defn abs [x]
(if (> x 0) x (* -1 x)))
<?xml version="1.0" encoding="UTF-8" ?>
<!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your site. -->
<!-- It contains information about your site's posts, pages, comments, categories, and other content. -->
<!-- You may use this file to transfer that content from one site to another. -->
<!-- This file is not intended to serve as a complete backup of your site. -->
<!-- To import this information into a WordPress site follow these steps: -->
<!-- 1. Log in to that site as an administrator. -->
<!-- 2. Go to Tools: Import in the WordPress admin panel. -->
@mahmoudhossam
mahmoudhossam / Stack.py
Created August 20, 2012 07:30
A naive stack implementation
class Stack:
def __init__(self):
self.values = []
def push(self, x):
self.values.append(x)
def pop(self):
x = self.values[-1]