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 / eyeOnMe.sh
Last active January 24, 2016 01:18
Bash script that takes a screenshot every seconds for an hour then make a video form the shots, it is good script if you want to know where did the time go.
#!/bin/sh
seconds=120
if [ ! -d "$HOME/watcher" ]; then
mkdir "$HOME/watcher"
fi
echo "Taking screenshots, the plan is to go like that for an hour"
for counter in $(seq -f "%05g" 0 $seconds)
do
@aessam
aessam / Polyline.py
Created January 21, 2016 13:48
Implementation of Polyline algorithm
# The reference for the implementation is this link
# https://developers.google.com/maps/documentation/utilities/polylinealgorithm?hl=en
# it decodes and encodes some test values, have fun playing with it.
def encode_coordinate(value):
value = int(value * 1E5)
value = ~(value << 1) if value < 0 else (value << 1)
res = []
@aessam
aessam / generate_video_thumb_grid
Created June 16, 2015 14:38
A command line to create video a 4x4 thumbnail grid
#!/bin/sh
secs=`exiftool "${1}" |grep "Media Duration"|cut -d':' -f4 -f3 -f2 |sed 's/:/ /g'| awk '{print ((($1*60)+$2)*60)+$3}'`
tmp=`dd if=/dev/urandom bs=4098 count=200 of=/dev/stdout|shasum|head -c 10; echo`
ffmpeg -i "${1}" -vf fps=1/$(($secs/14)) $tmp%04d.png
montage -geometry 480x270+2+2 `ls $tmp*.png` -tile 4x4 result_$tmp.png
rm $tmp*.png
noxt=`a="${1}";IFS=".";set $a;echo $1`
mv "result_$tmp.png" "$noxt.png"
@aessam
aessam / Generate Password
Created June 15, 2015 23:09
Using simple commands in Linux terminal to generate password, too lazy to search for password generator :D
if [ -z "${1}" ]
then
passlen=32
else
passlen=${1}
fi
dd if=/dev/urandom bs=4098 count=200 of=/dev/stdout|base64|head -c $passlen ; echo
@aessam
aessam / DirectoryCompare
Created June 15, 2015 12:31
Compare 2 Directories and list the files not in sync (file names only)
from collections import Counter
import os.path
def get_tree(d):
retList = []
os.chdir(d)
for path,dirs,files in os.walk("."):
for fn in files:
retList.append(os.path.join(path,fn))
os.chdir("..")
@aessam
aessam / DownloadYouTube
Created June 8, 2015 18:03
The script I use to download videos form YouTube, it also download Lists, u will need node and YouTube-dl to run it.
#!/usr/local/bin/node
var spawn = require('child_process').spawn;
function downloadVid(vidURL){
process.stdout.write('\nyoutube-dl -f 18 ' + vidURL.split("&")[0] + "\n");
yt = spawn("youtube-dl",["-f","18",vidURL.split("&")[0]]);
yt.stdout.on('data', function (data) {
process.stdout.write(data);
});
yt.on('close', function (code) {
process.stdout.write('child process exited with code ' + code + "\n");
@aessam
aessam / gut
Created May 24, 2015 23:22
Extract the title form URL command line then Tweet it :D -gut = Get URL Title- [Works on Mac Only and you will need T gem -as command line for Twitter-]
if [ -z "${1}" ]
then
u=`pbpaste`
else
u=${1}
fi
co=`curl -s $u | grep "<title>"`
co="${co/<title>/}"
co="${co/<\/title>/ $u}"
echo $co
@aessam
aessam / text_bounce
Last active August 29, 2015 14:19
old style text fun
import sys, time
def inc(i):
return i+1
def dec(i):
return i-1
func = [inc, dec]
s = input("Say something: ")
@aessam
aessam / upper_n_lower
Last active August 29, 2015 14:18
Upper and lower case function using bitwise.
def check_range(frm,to,trgt):
return 1 if frm<=trgt and to>=trgt else 0
def lower_character(c):
comp = check_range(ord('A'),ord('Z'),c)
return (comp<<5)|c if comp==1 else c
def upper_character(c):
comp = check_range(ord('a'),ord('z'),c)
return c&((comp<<5)^0x7f) if comp==1 else c
@aessam
aessam / a1_check_anagram.py
Created March 26, 2015 22:55
[Better and some how shouldn't be broken] Solving Anagram check problem using python and Linear Algebra and the complexity is O(n), which is 2nd lovely after constant :D
import math
def stringNorm(s):
odd = 0
even = 0
for c in s:
if not c==" ":
if ord(c)%2==0:
even+=math.pow(ord(c),2)
else: