This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$expected=array('username','age','city','street'); | |
foreach($expected as $key){ | |
if(!empty($_POST[$key])){ | |
${key}=$_POST[$key]; | |
} | |
else{ | |
${key}=NULL; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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.... */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
####################################################################################################### | |
####################################################################################################### | |
####################################################################################################### | |
###### ####### | |
###### ####### | |
###### This script will help you to recover the accidentally ####### | |
###### deleted data from crashed linux file systems ####### | |
###### Script created by (Srijan Kishore) ####### | |
###### ####### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql -uroot -p --local-infile | |
LOAD DATA LOCAL INFILE "file.csv" | |
INTO TABLE db.table | |
FIELDS TERMINATED BY ',' | |
ENCLOSED BY '\"' | |
LINES TERMINATED BY '\n' |
OlderNewer