Skip to content

Instantly share code, notes, and snippets.

View shalaby's full-sized avatar

Muhammad Shalaby shalaby

  • Egypt
View GitHub Profile
@shalaby
shalaby / generateCsv.php
Created March 4, 2014 20:05
Generate CSV file from a PHP array
function generateCsv($data, $delimiter = ',', $enclosure = '"') {
$handle = fopen('php://temp', 'r+');
foreach ($data as $line) {
fputcsv($handle, $line, $delimiter, $enclosure);
}
rewind($handle);
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);
@shalaby
shalaby / unZip.php
Created March 4, 2014 20:06
Unzip files with PHP
function unzip_file($file, $destination){
// create object
$zip = new ZipArchive() ;
// open archive
if ($zip->open($file) !== TRUE) {
die ('Could not open archive');
}
// extract contents to destination directory
$zip->extractTo($destination);
// close archive
@shalaby
shalaby / sanitizeDatabasInput.php
Created March 4, 2014 20:08
Sanitize database inputs
function cleanInput($input) {
$search = array(
'@<script[^>]*?>.*?</script>@si', // Strip out javascript
'@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
'@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
'@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments
);
$output = preg_replace($search, '', $input);
@shalaby
shalaby / detectLocationByIP.php
Created March 4, 2014 20:10
Detect location by IP
function detect_city($ip) {
$default = 'UNKNOWN';
if (!is_string($ip) || strlen($ip) < 1 || $ip == '127.0.0.1' || $ip == 'localhost')
$ip = '8.8.8.8';
$curlopt_useragent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)';
$url = 'http://ipinfodb.com/ip_locator.php?ip=' . urlencode($ip);
@shalaby
shalaby / 0_reuse_code.js
Created March 4, 2014 20:26
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@shalaby
shalaby / extract.php
Created March 5, 2014 08:45
Automatically creates variables with the same name as the key in the POST array
$expected=array('username','age','city','street');
foreach($expected as $key){
if(!empty($_POST[$key])){
${key}=$_POST[$key];
}
else{
${key}=NULL;
}
}
@shalaby
shalaby / detectAjaxRequest.php
Created March 7, 2014 19:49
Detect ajax request in php
/* decide what the content should be up here .... */
$content = get_content(); //generic function;
/* AJAX check */
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
/* special ajax here */
die($content);
}
/* not ajax, do more.... */
#!/bin/bash
#######################################################################################################
#######################################################################################################
#######################################################################################################
###### #######
###### #######
###### This script will help you to recover the accidentally #######
###### deleted data from crashed linux file systems #######
###### Script created by (Srijan Kishore) #######
###### #######
@shalaby
shalaby / .bashrc
Created March 22, 2014 14:17 — forked from Gen2ly/.bashrc
# Bash-configuration for user
# Check for an interactive session
[ -z "$PS1" ] && return
## Settings ##
set_prompt_style () { # Custom prompt
local bldpur='\e[1;35m' # Purple
local bldblu='\e[1;34m' # Blue
@shalaby
shalaby / importCSV.sql
Last active March 30, 2022 10:59
Import csv to mariadb
mysql -uroot -p --local-infile
LOAD DATA LOCAL INFILE "file.csv"
INTO TABLE db.table
FIELDS TERMINATED BY ','
ENCLOSED BY '\"'
LINES TERMINATED BY '\n'