Skip to content

Instantly share code, notes, and snippets.

View aessam's full-sized avatar
:octocat:
Doing code pushups

Ahmed Essam aessam

:octocat:
Doing code pushups
View GitHub Profile
@aessam
aessam / Remote-Jobs-graph.py
Created November 25, 2018 22:29
Playing with graphviz
from graphviz import Digraph
dot = Digraph(comment='Hunting Jobs')
dot.node('A', 'You')
dot.node('B', '50% - You decide to apply for a job')
dot.node('C', '50% - You decide to n\'t Apply to job')
dot.node('D', '20% - Pass Screening')
dot.node('E', '80% - Don\'t pass screening')
@aessam
aessam / img2ascii.py
Created July 11, 2018 02:36
Version 2 of Image 2 ASCII, supports color (5 bits).
"""
The basic idea is that I loop through all characters and count the number of
pixels and make <Hashtable number of pixels as a key and character as value>
The table will not have 255 value so to cover this I had to calculate the
slope of change as a base step for the colors.
example, if we have 50 value and we need 255 value, then each 255/50 = 5.1
Then with each gray color we will devied by 5 so we have index to
be fetched from the keys of the pixels table
@aessam
aessam / viewHierarchy.swift
Last active June 20, 2018 20:41
collection of function that help while debugging UIView.
extension UIView {
func viewHierarchy(views: [UIView], prefix: String) {
for view in views {
print("\(spaces)-\(view)")
viewHierarchy(view.subviews, spaces + " ")
}
func ancestry(view: UIView) {
var v: UIView? = view
var output = [UIView]()
@aessam
aessam / DataModalFiller.m
Created May 5, 2018 21:18
In 2015 I have built my own "Codable" for ObjectiveC automatic data serializer (You don't have to provide data type, it will infer the needed data type)
@protocol DataModalMarker
@end
@interface DataModalFiller : NSObject
+ (instancetype)sharedInstance;
- (id)deserilize:(id)target;
@end
#import "DataModalFiller.h"
@aessam
aessam / UIntCheckOverFlow.swift
Created April 14, 2018 15:51
Check if 2 variables UInt32 summation overflow or not before doing the actual summation.
func checkOverFlow(a: UInt32, b: UInt32) -> Bool{
let c = 0xFFFFFFFF - a
return c < b;
}
print("\(checkOverFlow(a: 0xFFFFFFFF, b: 1))")
@aessam
aessam / IterableTree.swift
Last active April 14, 2018 15:40
Traverse Binary tree using Iterator pattern, the implementation is efficient as it doesn't do any eager processing or allocation.
class Node<T> {
var left: Node?
var right: Node?
var value: T
init(value: T, left: Node<T>?, right: Node<T>?) {
self.value = value
self.left = left
self.right = right
}
@aessam
aessam / c_me.py
Created February 18, 2018 00:32
The script takes grabs the title of the active window and print out the amount of time spent on the output file, after that you can use this data to see how much time you spend on each application.
from AppKit import NSWorkspace
from time import sleep
from time import time
import sys
if len(sys.argv) != 2:
sys.exit("Usage: SCRIPT output_file.txt")
file = open(sys.argv[1],"a")
lastname = ""
@aessam
aessam / tmux
Last active March 13, 2017 03:17
# http://www.hamvocke.com/blog/a-guide-to-customizing-your-tmux-conf/
set -g history-limit 300000
bind | split-window -h
bind - split-window -v
unbind '"'
unbind %
bind r source-file ~/.tmux.conf
@aessam
aessam / image2ascii.py
Last active December 24, 2016 04:18
The scripts convert images to ascii art, it count pixels for character and use it as base for color density.
"""
The basic idea is that I loop through all characters and count the number of
pixels and make <Hashtable number of pixels as a key and character as value>
The table will not have 255 value so to cover this I had to calculate the
slope of change as a base step for the colors.
example, if we have 50 value and we need 255 value, then each 255/50 = 5.1
Then with each gray color we will devied by 5 so we have index to
be fetched from the keys of the pixels table
@aessam
aessam / ReverseLinkedList.py
Created January 29, 2016 13:06
Reverse Linked list without recursion.
# this code is compatible with Python 2.x
from pprint import pprint
sample = {"n":{"n":{"n":{"v":1},"v":2},"v":3},"v":4}
def reverseLinkedList(lst):
previous = None
current = lst
while current != None:
if "n" in current: