Skip to content

Instantly share code, notes, and snippets.

View mahmoudhossam's full-sized avatar
🏗️

Mahmoud Hanafy mahmoudhossam

🏗️
  • Berlin, Germany
  • 20:07 (UTC +02:00)
View GitHub Profile
@mahmoudhossam
mahmoudhossam / pascal.scala
Created January 31, 2013 13:07
Pascal Triangle in scala.
def pascal(c: Int, r: Int): Int = {
if(c == 0 || c == r) 1 else pascal(c, r-1) + pascal(c-1, r-1)
}
@mahmoudhossam
mahmoudhossam / age.c
Created September 1, 2012 15:21
Trying to calculate a person's age using pointers
#include <stdio.h>
int age(int* year);
int main()
{
printf("Enter your birth year: ");
char buf[50];
char* input = gets(buf);
int year = atoi(input);
@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]
<?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 / abs.clj
Created May 4, 2012 13:15
The abs function, implemented in Clojure.
(defn abs [x]
(if (> x 0) x (* -1 x)))
@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
#!/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 / 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
@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 / 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;