Skip to content

Instantly share code, notes, and snippets.

View saleemkce's full-sized avatar

Saleem Khan saleemkce

  • formerly at Pearson PLC & Ranbas Software
  • Chennai, India
View GitHub Profile
@saleemkce
saleemkce / pthreads.md
Last active March 10, 2023 00:07 — forked from krakjoe/pthreads.md

Multi-Threading in PHP with pthreads

A Brief Introduction to Multi-Threading in PHP

  • Foreword
  • Execution
  • Sharing
  • Synchronization
  • Pitfalls
@saleemkce
saleemkce / download_file.php
Created January 24, 2014 18:30
PHP File Download Script - Download large file in chunks.
<?php
/*ini settings*/
set_time_limit(0);
ini_set('memory_limit', '512M');
//DOWNLOAD SCRIPT
$filePath = "G:/Software/versions/..PATH TO DOWNLOAD FILE...zip"; // set your download file path here.
download($filePath); // calls download function
function download($filePath)
{
@saleemkce
saleemkce / multi-execute-PHP.php
Last active January 3, 2016 05:50
Execute multiple SQL statements in PHP for Mysql database.
<?php
/*
Execute multiple SQL statements in PHP or directly execute .SQL files in MySql using PHP
*/
ini_set('display_errors', 0);
error_reporting(0);
// SET MYSQL CONFIGURATION
$serverName = 'localhost';
$username = 'root';
$password = '';
@saleemkce
saleemkce / shortest sub-segment finding.php
Last active January 2, 2016 09:29
Given a paragraph of text, write a program to find the first shortest sub-segment that contains each of the given k words at least once. A segment is said to be shorter than other if it contains less number of words.
<?php
/*
Given a paragraph of text, write a program to find the first shortest sub-segment that contains each of the given k words at least once. A segment is said to be shorter than other if it contains less number of words.
Ignore characters other than [a-z][A-Z] in the text. Comparison between the strings should be case-insensitive.
If no sub-segment is found then the program should output “NO SUBSEGMENT FOUND”.
Input format :
First line of the input contains the text.
Next line contains k , the number of words given to be searched.
@saleemkce
saleemkce / time-slots computing.php
Last active January 2, 2016 09:29
Given M busy-time slots of N people, You need to print all the available time slots when all the N people can schedule a meeting for a duration of K minutes.Event time will be of form HH MM ( where 0 <= HH <= 23 and 0 <= MM <= 59 ), K will be in the form minutes.
<?php
/*
Given M busy-time slots of N people, You need to print all the available time slots when all the N people can schedule a meeting for a duration of K minutes.
Event time will be of form HH MM ( where 0 <= HH <= 23 and 0 <= MM <= 59 ), K will be in the form minutes.
Input Format:
M K [ M number of busy time slots , K is the duration in minutes ]
Followed by M lines with 4 numbers on each line.
Each line will be of form StartHH StartMM EndHH EndMM [ Example 9Am-11Am time slot will be given as 9 00 11 00 ]
@saleemkce
saleemkce / connected-cli
Created January 6, 2014 14:34
Given a 2–d matrix , which has only 1’s and 0’s in it. Find the total number of connected sets in that matrix.
<?php
/*
Given a 2–d matrix , which has only 1’s and 0’s in it. Find the total number of connected sets in that matrix.
Explanation:
Connected set can be defined as group of cell(s) which has 1 mentioned on it and have at least one other cell in that set with which they share the neighbor relationship. A cell with 1 in it and no surrounding neighbor having 1 in it can be considered as a set with one cell in it. Neighbors can be defined as all the cells adjacent to the given cell in 8 possible directions ( i.e N , W , E , S , NE , NW , SE , SW direction ). A cell is not a neighbor of itself.
Input format :
@saleemkce
saleemkce / fibonacci
Last active January 2, 2016 09:29
Given a number K, find the smallest Fibonacci number that shares a common factor( other than 1 ) with it. A number is said to be a common factor of two numbers if it exactly divides both of them. Output two separate numbers, F and D, where F is the smallest fibonacci number and D is the smallest number other than 1 which divides K and F.
<?php
/*
Given a number K, find the smallest Fibonacci number that shares a common factor( other than 1 ) with it. A number is said to be a common factor of two numbers if it exactly divides both of them.
Output two separate numbers, F and D, where F is the smallest fibonacci number and D is the smallest number other than 1 which divides K and F.
Input Format
First line of the input contains an integer T, the number of testcases.
Then follows T lines, each containing an integer K.