Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Ayman Farhat aymanfarhat

🎯
Focusing
Block or report user

Report or block aymanfarhat

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@aymanfarhat
aymanfarhat / Euler 18.cs
Created Sep 9, 2012
Project Euler Problem 18
View Euler 18.cs
class Program
{
/* The triangle */
static int[][] triangle = null;
/* Saves respective optimal sums of nodes in the triangle */
static int[][] optimalSums = null;
static void Main(string[] args)
{
@aymanfarhat
aymanfarhat / Intersection.py
Created Jan 4, 2013
Set Intersection algorithm O(nlogn) time. Code in Python.
View Intersection.py
from itertools import chain
intersection = []
sets = [[0,4,5,2,1],[1,3,6,2,4],[4,1,2,5,7,0]]
merged = list(chain.from_iterable(sets))
merged.sort()
@aymanfarhat
aymanfarhat / String.format.js
Created Jan 6, 2013
Simple implementation of C#'s String.format() in Javascript for building strings
View String.format.js
String.prototype.format = function()
{
var args = arguments;
return this.replace(/{(\d+)}/g, function(match, number)
{
return typeof args[number] != 'undefined'? args[number]:match;
});
};
View CodeJamQ_2009_A.py
# Parses each string patterns to list of strings and lists(options)
def parse_patterns(patterns):
lines = []
def getclosing(i,pattern):
for x in xrange(i,len(pattern)):
if pattern[x] == ")":
return x
return -1
@aymanfarhat
aymanfarhat / tomorrow-night-eighties.css
Created Apr 10, 2013
An edit of https://github.com/isagalaev/highlight.js/blob/master/src/styles/tomorrow-night-eighties.css for styling code tags that are not necessarily within a pre tag, useful for inline code highlighting.
View tomorrow-night-eighties.css
/* Tomorrow Night Eighties Theme */
/* Original theme - https://github.com/chriskempson/tomorrow-theme */
/* http://jmblog.github.com/color-themes-for-google-code-highlightjs */
/* Edited by Ayman Farhat(http://aymanfarhat.com) for supporting inline code tags without pre */
.tomorrow-comment, code .comment, code .title {
color: #999999;
}
.tomorrow-red, code .variable, code .attribute, code .tag, code .regexp, code .ruby .constant, code .xml .tag .title, code .xml .pi, code .xml .doctype, code .html .doctype, code .css .id, code .css .class, code .css .pseudo {
color: #f2777a;
@aymanfarhat
aymanfarhat / urlobject.js
Last active Jul 27, 2017
JS utility function that: - Breaks down url to an object with accessible properties: protocol, parameters object, host, hash, etc... - Converts url parameters to key/value pairs - Convert parameter numeric values to their base types instead of strings - Store multiple values of a parameter in an array - Unescape parameter values
View urlobject.js
function urlObject(options) {
"use strict";
/*global window, document*/
var url_search_arr,
option_key,
i,
urlObj,
get_param,
key,
@aymanfarhat
aymanfarhat / index.js
Last active Dec 18, 2015
SwipyJS with Fries integration
View index.js
/** JS of the index **/
(function(){
var data = $('#dev_list').html();
for(var i = 0; i < 10; i++)
$("#dev_list").append(data);
/* Tab swiping init and next/prev functions */
View chocolate.py
def get_total(n,p):
if n < p:
return 0
elif n == p:
return 1
else:
return 1 + get_total(n-2,p)
n = int(raw_input("money:"))
@aymanfarhat
aymanfarhat / karger.py
Last active May 25, 2020
Implementation of Karger's algorithm in Python. Randomized algorithm for computing minimum cuts in a connected graph. Input file source is Coursera's Algo 1 course HW3: http://spark-public.s3.amazonaws.com/algo1/programming_prob/kargerMinCut.txt
View karger.py
import re
import random
# Load the file into a graph represented by a dict of lists
def load_graph():
g = {}
f = open('kargerMinCut.txt')
lines = f.readlines()
f.close()
View efficient.py
f = open('input.txt')
lines = f.readlines()
lines = list(map(lambda x: int(x.strip()), lines))
f.close()
d = {}
found = {}
for line in lines:
if line in d:
You can’t perform that action at this time.