Skip to content

Instantly share code, notes, and snippets.

View hanigamal's full-sized avatar
๐ŸŽฏ
Focusing at office

Hani Gamal hanigamal

๐ŸŽฏ
Focusing at office
View GitHub Profile
@hanigamal
hanigamal / ReadvCard.java
Created June 2, 2012 13:38
Android: Handling vCard
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import a_vcard.android.syncml.pim.PropertyNode;
import a_vcard.android.syncml.pim.VDataBuilder;
import a_vcard.android.syncml.pim.VNode;
import a_vcard.android.syncml.pim.vcard.VCardException;
import a_vcard.android.syncml.pim.vcard.VCardParser;
@hanigamal
hanigamal / DialANumber.java
Created June 2, 2012 14:21
Android: Dial A Number
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
@hanigamal
hanigamal / DialANumber.java
Created June 2, 2012 14:21
Android: Dial A Number
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
@hanigamal
hanigamal / gravatar.php
Created June 6, 2012 23:06
Get either a Gravatar URL or complete image tag for a specified email address.
/**
* Get either a Gravatar URL or complete image tag for a specified email address.
*
* @param string $email The email address
* @param string $s Size in pixels, defaults to 80px [ 1 - 512 ]
* @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ]
* @param string $r Maximum rating (inclusive) [ g | pg | r | x ]
* @param boole $img True to return a complete IMG tag False for just the URL
* @param array $atts Optional, additional key/value attributes to include in the IMG tag
* @return String containing either just a URL or a complete image tag
@hanigamal
hanigamal / tashkeel-regex.php
Created June 11, 2012 16:04
Regex for the whole unicode range
$string = <<<EOF
<p dir="rtl">
ุฃูŽููŽู„ุงูŽ ูŠูŽุชูŽุฏูŽุจูŽู‘ุฑููˆู†ูŽ ุงู„ู’ู‚ูุฑู’ุขู†ูŽ ูˆูŽู„ูŽูˆู’ ูƒูŽุงู†ูŽ ู…ูู†ู’ ุนูู†ุฏู ุบูŽูŠู’ุฑู ุงู„ู„ู‘ู‡ู ู„ูŽูˆูŽุฌูŽุฏููˆุงู’ ูููŠู‡ู ุงุฎู’ุชูู„ุงูŽูู‹ุง ูƒูŽุซููŠุฑู‹ุง
</p>
EOF;
preg_match('/<p dir=(?:"rtl"|\'rtl\')>([\x{0600}-\x{06FF}\x{0750}-\x{077F}\x{FB50}-\x{FDFF}\x{FE70}-\x{FEFF} \r\n]+)<\/p>/um', $string, $matches);
$match = $matches[1];
@hanigamal
hanigamal / S3_regex.pl
Created June 11, 2012 17:03
Parse S3 log files using Perl regular expressions
#!/usr/bin/perl -w
use strict;
while (my $line=<>) {
my ($date, $host, $url_with_method, $status, $size, $referrer, $agent) = $line =~
m/^\S+\s+\S+\s+\[(\S+\s+[\-|\+]\d{4})\]\s+(\S+)\s+\S+\s+\S+\s+\S+\s+\S+\s+"(\S+\s+\S+\s+[^"]+)"\s+(\d{3})\s+\S+\s+(\d+|-)\s+\d+\s+\d+\s+\d+\s+"(.*?)"\s+"(.*?)"/;
# Print relevant bits
}
@hanigamal
hanigamal / ajax.jquery.js
Created June 25, 2012 14:42
JSONP Snipp
Since you use JSONP, you should code it like this IMHO :
$.ajax(URL, {
crossDomain:true,
dataType: "jsonp",
success:function(data,text,xhqr){
$.each(data, function(i, item) {
alert(item);
});
}
@hanigamal
hanigamal / gist:4439927
Created January 3, 2013 01:00
Shuffle Chars
import re, random
def shuffle_one(word):
if len(word) <= 3:
return word
middle = list(word[1:-1])
random.shuffle(middle)
return word[0] + ''.join(middle) + word[-1]
@hanigamal
hanigamal / gist:4439936
Created January 3, 2013 01:02
To extract the <name> part of the file name, provided the dot separates <name> from <date> you can use parameter substitution in this way
#!/bin/bash
cd /path/to/backup/directory
for file in *.tgz
do
name=${file%%[.]*}
echo $name
if [ $name = $current_backup_name ]
then
# do new backup here
# delete older one here
@hanigamal
hanigamal / gist:4439943
Created January 3, 2013 01:03
resmanager.js
if (!Util) {
var Util = {};
}
Util.ResourceManager = function(culture, resourcePath)
{
this.createResObj(culture, resourcePath);
}
Util.ResourceManager.prototype =