Skip to content

Instantly share code, notes, and snippets.

View nadeem-khan's full-sized avatar

Nadeem Khan nadeem-khan

View GitHub Profile
FROM php:7.0.4-fpm
RUN apt-get update && apt-get install -y libmcrypt-dev \
mysql-client libmagickwand-dev --no-install-recommends \
&& pecl install imagick \
&& docker-php-ext-enable imagick \
&& docker-php-ext-install mcrypt pdo_mysql
@nadeem-khan
nadeem-khan / Detect a palindrome.md
Last active May 3, 2017 17:41
Detect a palindrome.md

Detect a Palindrome



/**
 * A palindrome is a word which reads the same backward or forward, 
 * such as madam or kayak
 *
 * Implement a function that returns true if a word is a palindrome 
 * and false otherwise
 *
@nadeem-khan
nadeem-khan / Generate Strong Password with PHP.md
Last active August 29, 2015 14:18
Generate Strong Password with PHP

Generate Strong Password with PHP

    $length = 8;
    $characters_pool = 'luds';
    $sets = array();
    if (strpos($characters_pool, 'l') !== false) {
        $sets[] = 'abcdefghjkmnpqrstuvwxyz';
    }
    if (strpos($characters_pool, 'u') !== false) {

$sets[] = 'ABCDEFGHJKMNPQRSTUVWXYZ';

@nadeem-khan
nadeem-khan / When to 'git rebase' instead of 'git merge'.md
Last active February 25, 2018 04:47
When to 'git rebase' instead of 'git merge'?

git tree at default when we have not merged nor rebased:

git tree at default when we have not merged nor rebased

we get by rebasing:

we get by rebasing

@nadeem-khan
nadeem-khan / URL Signing for HighWinds CDN in PHP.md
Last active August 29, 2015 14:14
URL Signing for HighWinds CDN in PHP

How to Implement URL Signing for HighWinds CDN in PHP:

   //the input URL example taken from https://support.highwinds.com/display/DOCS/Content+Protection 
   $URL = parse_url("http://aaa.wdd3.cdn.net/secure123/content.mp4");
   
   // parse URL to separate the host and the rest of the url string
   $uri= $URL['path'];

   // set a secret pass  

$secret = 'abcdef123';

@nadeem-khan
nadeem-khan / Git Tagging and Branching 101.md
Last active June 22, 2022 04:41
Git Tagging and Branching 101

Git Tagging and Branching 101

Here are the best practices for using Git Branches and Git Tags:

Git Tags

A ref pointing to a tag or commit object. To put simply, a tag is a way to mark a point in time in your repository. Here are some things that you should keep in mind when working with tags:

-You should add a tag to mark a released version. If you then need to make bug fixes to that release you would create a branch at the tag
@nadeem-khan
nadeem-khan / Select similar (autofill) city names from maxmind cities list as compared to the input string in CodeIgniter.md
Last active January 25, 2016 15:14
Select similar (autofill) city names from maxmind cities list as compared to the input string in CodeIgniter

Select similar (autofill) city names from maxmind cities list as compared to the input string in CodeIgniter

Model

     class Maxmind_model extends CI_Model {

     private $table = "maxmind";

public function __construct() {

@nadeem-khan
nadeem-khan / Extract table names from a SQL query with multiple tables using PHP.md
Last active February 26, 2021 10:18
Extract table names from a SQL query with multiple tables using PHP

PHP API to return table names from a given SQL statement with multiple tables

Input

 $query = "SELECT `main_categories`.*, `categories_views`.`view` AS view_ctg, (SELECT COUNT(id_geo) FROM main_geo WHERE id_geo=geo_filter_ctg AND FIND_IN_SET('PK', `countries_geo` )) as countryCount
 FROM (`main_categories`)
 JOIN `categories_parents` ON `main_categories`.`id_ctg` = `categories_parents`.`id_ctg`
 JOIN `categories_views` ON `main_categories`.`id_ctg` = `categories_views`.`id_ctg`

WHERE categories_parents.parent_ctg = '8701'

@nadeem-khan
nadeem-khan / Coding Tips for Speeding up Codeignitor Performance.md
Last active August 29, 2015 14:10
Coding Tips for Speeding up Codeignitor Performance

Best way to use data fetched from DB with result_array()

$result = $this->db->get()->result_array(); // result_array() itself uses a for loop so we actually end up looping twice in the next line
foreach ($result as $row)
{
  ...
} 

Instead use:

@nadeem-khan
nadeem-khan / SQL Query Optimizations Tips.md
Last active March 2, 2020 09:37
SQL Query Optimizations Tips

1. Use EXPLAIN keyword in your SELECT queries and then add index to all the search fields in the query:

  ALTER TABLE TABLE_NAME ADD INDEX (COLUMN_NAME);

//before using index

Image Before Adding Index to Columns

//after using index (not the dramatic decrease in the number of rows scanned)