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 / helpers.swift
Created August 18, 2019 02:40 — forked from kastiglione/helpers.swift
Swift helpers, and the lldb setup to use them. Presented @ SLUG https://speakerdeck.com/kastiglione/advanced-debugging-and-swift
extension UIView {
/// Example: call someView.nudge(0, 30)
func nudge(_ dx: CGFloat, _ dy: CGFloat) {
self.frame = self.frame.offsetBy(dx: dx, dy: dy)
CATransaction.flush()
}
}
extension UIView {
/// Example: po UIView.root
@aessam
aessam / MatHeart.py
Last active February 23, 2019 01:51
Drawing heart with math
# http://mathworld.wolfram.com/HeartCurve.html
from math import pi, sin, cos
import time
import numpy as np
r = 1
result = []
for i in range(38):
result.append([])
result[i] = list(map(lambda x: ' ', range(38)))
@aessam
aessam / ApplyFilter.py
Last active March 31, 2019 22:47
I was trying to understand how convolutional network works with filters, I decided to replicate it.
from PIL import Image, ImageDraw
import random
from sys import argv
if len(argv) != 3:
print("<<script>> Image outputDir")
exit(1)
image_name = argv[1]
out = argv[2]
@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 = ""