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 / 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 / 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 / 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 / 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;
try {
URL u = new URL("http://hanigamal.net/resume.pdf");
HttpURLConnection c = (HttpURLConnection) u.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
String fileName = Environment.getExternalStorageDirectory().getAbsolutePath();
FileOutputStream f = new FileOutputStream(new File(fileName,"my.pdf"));
@hanigamal
hanigamal / mp3oggHTTPserver.java
Created June 2, 2012 13:28
An smart MP3/OGG HTTP server that translates M3U playlist files
import java.io.*;
import java.util.*;
import java.net.*;
/**
* An smart MP3/OGG HTTP server that translates M3U playlist files
*
* <p> Mp3HTTPD version 1.04,
* Copyright &copy; 2001,2005 Jarno Elonen ([email protected])
@hanigamal
hanigamal / isNetAvailable.java
Created June 2, 2012 13:25
Network Availability
public boolean isNetworkAvailable() {
Context context = getApplicationContext();
ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
boitealerte(this.getString(R.string.alert),"getSystemService rend null");
} else {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
for (int i = 0; i < info.length; i++) {
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
@hanigamal
hanigamal / NanoHTTPD.java
Created June 2, 2012 13:23
A simple, tiny, nicely embeddable HTTP 1.0 (partially 1.1) server in Java
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
@hanigamal
hanigamal / twitter-status-bot.sh
Created June 1, 2012 19:10
Twitter status update bot
#!/bin/bash
#Twitter status update bot by http://360percents.com
#Author: Luka Pusic <[email protected]>
#REQUIRED PARAMS
username="[email protected]"
password="yourpassw0rd"
tweet="$*" #must be less than 140 chars
#EXTRA OPTIONS