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
#Copyright 2022 Google LLC.
#SPDX-License-Identifier: Apache-2.0
import os
import psutil
from google.cloud.storage import Client
def get_mem_mb():
return psutil.Process().memory_info().rss / (1024 * 1024)
#Copyright 2022 Google LLC.
#SPDX-License-Identifier: Apache-2.0
WITH
initial_log AS (
SELECT
commit_hash,
author_name,
author_email,
TIMESTAMP_SECONDS(author_date) AS author_date,
REGEXP_EXTRACT(file, "(tools|examples)/[^/]+/.*") AS type,
@aymanfarhat
aymanfarhat / bq_load.sh
Last active August 9, 2022 12:33
Example of extracting and flattening git logs and writing them into BigQuery
#Copyright 2022 Google LLC.
#SPDX-License-Identifier: Apache-2.0
bq --location="EU" load \
--replace \
--source_format="NEWLINE_DELIMITED_JSON" \
--autodetect \
your_dataset.your_table \
./logs.jsonl
@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()
@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"
@aymanfarhat
aymanfarhat / docker-compose.yml
Last active December 5, 2019 12:13
Example of docker-izing a wordpress setup in docker-compose
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
@aymanfarhat
aymanfarhat / Intersection.py
Created January 4, 2013 19:52
Set Intersection algorithm O(nlogn) time. Code in Python.
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 / urlobject.js
Last active July 27, 2017 00:04
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
function urlObject(options) {
"use strict";
/*global window, document*/
var url_search_arr,
option_key,
i,
urlObj,
get_param,
key,
{
"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);