Skip to content

Instantly share code, notes, and snippets.

View aymanfarhat's full-sized avatar
🏠
Working from home

Ayman Farhat aymanfarhat

🏠
Working from home
View GitHub Profile
@aymanfarhat
aymanfarhat / sendmail.py
Created January 1, 2014 10:24
Python snippet for sending email using unix sendmail
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from subprocess import Popen, PIPE
html = MIMEText("<html><head><title>Test Email</title></head><body>Some HTML</body>", "html")
msg = MIMEMultipart("alternative")
msg["From"] = "you@yourmail.com"
msg["To"] = "recipient@mail.com"
msg["Subject"] = "Python sendmail test"
{
"title":"Tool Title",
"description": "Tool Description",
"version": "",
"author": {
"name":"",
"email":"",
"website":""
},
"repository_url": "",
// http://paulirish.com/2011/requestanimationframe-for-smart-animating
// shim later with setTimeout fallback
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function( callback ){
window.setTimeout(callback, 1000 / 60);
var async = function(func,callback){
return function(){
var args = arguments;
setTimeout(function(){
var values = func.apply(this, args);
callback.call(this, values);
}, 0);
};
};
var client = new DBClient();
var db = client.setDatabase("test"); // If test doesnt exist creates it
var collection = db.getCollection("coll");
// Find documents in a collection that match criteria
collection.selectDoc({name:"ayman"},function(data){
// Callback for accessing and managing the returned data
});
@aymanfarhat
aymanfarhat / YoutubeAPIHelper.php
Created October 9, 2013 14:03
Youtube public API wrapper in PHP
class YoutubePublicAPI {
// Developers key to access the API
private $key;
private $base_url = "https://www.googleapis.com/youtube/v3/";
public function __construct($params){
$this->key = $params["key"];
}
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:
@aymanfarhat
aymanfarhat / karger.py
Last active May 2, 2021 03:33
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
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()
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 / index.js
Last active December 18, 2015 09:49
SwipyJS with Fries integration
/** 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 */