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 / TwitterExport.php
Created March 1, 2013 23:34
Allow the export of complete user time-lines from the twitter service. It joins together all pages of status updates into one large XML block that can then be reformatted/processed with other tools.
<?php
/**
* This script will allow the export of complete user time-lines from the twitter
* service. It joins together all pages of status updates into one large XML block
* that can then be reformatted/processed with other tools.
*
* @since 10/13/08
*
* @copyright Copyright © 2008, Adam Franco
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
import android.accounts.Account;
import android.accounts.AccountManager;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Build;
import android.preference.PreferenceManager;
public final class AccountUtils {
@hanigamal
hanigamal / gist:4439967
Created January 3, 2013 01:11
Mikrotik Script: Webserver behind NAT
/ip firewall
dst-nat protocol=tcp dst-port=80 Action dst-nat to-address=20.20.20.45 to-ports=80
add action=dst-nat chain=dstnat comment="" disabled=no dst-port=80 protocol=tcp to-addresses=20.20.20.45 to-ports=80
#Creating pppoe interface and ADSL internet connection
/ interface pppoe-client
add name="pppoe-out1" max-mtu=1480 max-mru=1480 interface=ether5 \
user="USERNAMEl" password="PASSWORD" profile=default \
@hanigamal
hanigamal / gist:4439957
Last active August 25, 2017 02:47
Validate Credit Cards
#!/usr/local/bin/perl
#
# CC-Verify script for Visa, MasterCard, Amex and Novus Cards
# Written 29 June 1996 by Spider ([email protected])
# http://w3works.com
# http://www.servtech.com/public/spider
#
# Loosely based on a re-post of original by Melvyn Myers
# (initial author unknown) but this revision covers all 13,
# 15 and 16 digit cards using the Mod 10 algorithm.
@hanigamal
hanigamal / gist:4439949
Created January 3, 2013 01:04
Assembla API
<?php
require_once('assembla.plugin');
$key = '...'; //this is your assembla space id
$username = '...'; //this is an assembla user account name
$password = '...'; //this is the password for the above user
$A = new Assembla($key, $username, $password);
//$tickets = $A->listTickets();
@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 =
@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: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 / 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 / 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
}