Skip to content

Instantly share code, notes, and snippets.

View ken-muturi's full-sized avatar

muturiken ken-muturi

View GitHub Profile
@ken-muturi
ken-muturi / MYSQL 24 hrs time check.sql
Created November 17, 2013 05:23
MYSQL 24 hrs time check.....
SELECT DATE_FORMAT(CURRENT_TIMESTAMP(), '%H%i') AS _hour, IF ( DATE_FORMAT(CURRENT_TIMESTAMP(), '%H%i') BETWEEN 1300 AND 1600, 1, 0) AS _check
@ken-muturi
ken-muturi / duplicates_count.sql
Created November 17, 2013 05:26
Duplicate Count
SELECT trim(user_name), COUNT(user_name) AS dup_count
FROM dataentry_users
GROUP BY trim(user_name)
HAVING (COUNT(trim(user_name)) > 1)
@ken-muturi
ken-muturi / flash_session.php
Created November 17, 2013 05:28
Flash Session Implementation
public static function get_flash_data($key)
{
if (isset($_SESSION['flash'][$key])) {
$flash_data = $_SESSION['flash'][$key];
unset($_SESSION['flash'][$key]);
return $flash_data;
} else {
return null;
@ken-muturi
ken-muturi / xs_clean.php
Created November 17, 2013 05:30
XSS Clean
public static function xss_clean($array)
{
foreach ($array as $key => $data) {
if (is_array($data)) {
$array[$key] = self::xss_clean($data);
} else {
@ken-muturi
ken-muturi / new_gist_file.php
Created November 17, 2013 06:18
Get class hierarchy Returns the complete class hierarchy of an object or a class name. Can be used as method or function.
public function getClassHierarchy($obj){
if(is_object($obj)){
$class = get_class($obj);
}
elseif(!class_exists($obj)){
throw new InvalidArgumentException("class $obj is not defined" );
}
$hierarchy = array();
while($class){
$hierarchy[] = $class;
@ken-muturi
ken-muturi / new_gist_file.php
Created November 17, 2013 06:19
search & replace text inside pdf files in php applications
<?php
$filePath = getcwd() . "\\Input\\MyFile.pdf";
$fileName = basename($filePath);
$oldText = "old text here";
$newText = "new text here";
//set application information
$AppSID = "77**************";
$AppKey = "89***********";
@ken-muturi
ken-muturi / new_gist_file.php
Created November 17, 2013 06:21
Display Facebook fans count in full text
function fb_fan_count($facebook_name){
// Example: https://graph.facebook.com/digimantra
$data = json_decode(file_get_contents("https://graph.facebook.com/".$facebook_name));
echo $data->likes;
}
@ken-muturi
ken-muturi / new_gist_file.sql
Created November 17, 2013 06:27
Natural Language Full-Text Searches
SELECT * FROM articles
WHERE MATCH (title,body) AGAINST ('database');
@ken-muturi
ken-muturi / new_gist_file.sql
Created November 17, 2013 06:30
Boolean Full-Text Searches - http://viralpatel.net/blogs/full-text-search-using-mysql-full-text-search-capabilities/ It may happen that you want to specify certain keywords in your search criteria. Also you may want to ignore certain keywords. Boolean Full-Text Search can used to perform a full text search for such requirements. If you notice th…
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('+MySQL -YourSQL' IN BOOLEAN MODE);
@ken-muturi
ken-muturi / new_gist_file.php
Created November 17, 2013 07:03
Countries array
<?php
// https://snipt.net/public/tag/php/?page=3
$countries = array(
"AF" => array("country" => "Afghanistan", "continent" => "Asia"),
"AX" => array("country" => "Åland Islands", "continent" => "Europe"),
"AL" => array("country" => "Albania", "continent" => "Europe"),
"DZ" => array("country" => "Algeria", "continent" => "Africa"),
"AS" => array("country" => "American Samoa", "continent" => "Oceania"),