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 / NodeScreenCapture
Last active August 29, 2015 13:56
Share your screen to local network, it can be helpful in cases of meetings and you don't have projector, be creative and use it as much.
var imgStr = "";
setInterval(function(){
// Make sure to change the command based on the OS you are using.
require('child_process').spawn('screencapture', ['-C', '-x','cme.png']).on('close', function (code) {
imgStr = require("fs").readFileSync('cme.png','base64');
});
},1000);
require("http").createServer(function(req,res){
@aessam
aessam / reverseLinkedList
Created July 12, 2014 02:49
Node minimal reverse Linked List
targetList = {n:{n:{n:{v:1},v:2},v:3},v:4};
function reverseLinkedList(n){
if(n.n){
v = reverseLinkedList(n.n); // simply get the child until you hit the end.
v.n=n; // in the new Order parent node is the child of its child.
}else{
delete targetList.n; // without this line the list will be circuler
targetList = n; // replace the head with the tail
}
return n;
@aessam
aessam / tree.js
Last active August 29, 2015 14:04
Simple Tree structure functions (add to tree, get max, get min, get tree width)
#!/usr/local/bin/node
// If the incoming value > then add to left, if the value is < add to right
// if the left/right has value will go recursively until empty node is found
function addToTree(tree,v){
if(tree["v"] && tree["v"]!=v){
var direction = "";
if(tree["v"]>v) direction = "l";
if(tree["v"]<v) direction = "r";
@aessam
aessam / Merge Sort without recursion
Last active August 29, 2015 14:07
JS code the generates random array of numbers and sort it using merge sort without using recursive function call
// Inspired by the game 2048 :D
function merge(left, right) {
var result = [];
while(left.length || right.length) {
if(left.length && right.length) {
if(left[0]<right[0]) {
result.push(left.shift());
} else {
result.push(right.shift());
@aessam
aessam / fixAndroidResourcesFilenames.js
Last active August 29, 2015 14:07
Usually the images come in whatever the designer name it and most of the time Android SDK don't like this naming, this is NodeJS script that fixes the filenames for Android PNG.
#!/usr/local/bin/node
var fs = require("fs");
var filenames = fs.readdirSync(".");
var a = "a".charCodeAt(0);
var z = "z".charCodeAt(0);
var c0 = "0".charCodeAt(0);
var c9 = "9".charCodeAt(0);
var acceptableChars = {"_":true,".":true}
@aessam
aessam / Hex
Created November 10, 2014 18:50
Simple C application that reads file and print it as HEX,
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int lineBreaker = 12;
void printInHex(char* file, int length){
char* temp = (char*)malloc(lineBreaker+1);
memset(temp,0,lineBreaker+1);
for (int i=0;i<length;i++){
printf("0x%02x ",file[i]);
@aessam
aessam / MonitorMobileOperators
Created February 15, 2015 19:37
The script is to monitor the 3 mobile operators in Egypt, you will need some sort of NLP/Text mining to make some use of the result.
# Make sure to use this command before using the script
# pip install TwitterAPI
# The script is part of the demo of Twitter API, so no big deal here.
from TwitterAPI import TwitterAPI
import json
ACCESS_TOKEN_KEY = "GET IT FROM https://apps.twitter.com"
@aessam
aessam / check_anagram.py
Created March 24, 2015 21:31
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):
norm = 0
for c in s:
if not c==" ":
norm+=math.pow(ord(c),2)
return math.sqrt(norm)
def anagram_detection(s1,s2):
@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:
@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