Skip to content

Instantly share code, notes, and snippets.

View IftiMahmud's full-sized avatar

Ifti Mahmud IftiMahmud

View GitHub Profile
<?php
//Bad Email...
$badEmail = "bad@email";
//Run the email through an email validation filter.
if( !filter_var($badEmail, FILTER_VALIDATE_EMAIL) ){
echo "Email is no good.";
}else{
echo "Nice email.";
}
<?php
// basic email validation, needs to be updated to support new longer domains
$email = '[email protected]';
$regex = "/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/i";
$valid = preg_match( $regex, $email ) ? 'yes' : 'no';
?>
<strong>Email:</strong> <?php echo $email ?><br />
<strong>Valid:</strong> <?php echo $valid ?>
<?php
#!/usr/bin/env php
//usage: php envato-screenshots-downloader.php /path/to/save/screenshots http://url/to/screenshots/page
set_time_limit(0);
$dir = $argv[1];
$source = $argv[2];
print_r($argv);
mkdir ($dir);
$src = file_get_contents($source);
$pattern = '/src="(https:\/\/0.s3[a-zA-Z0-9_\-\.\/%]+)"/i';

Originally published in June 2008

When hiring Ruby on Rails programmers, knowing the right questions to ask during an interview was a real challenge for me at first. In 30 minutes or less, it's difficult to get a solid read on a candidate's skill set without looking at code they've previously written. And in the corporate/enterprise world, I often don't have access to their previous work.

To ensure we hired competent ruby developers at my last job, I created a list of 15 ruby questions -- a ruby measuring stick if you will -- to select the cream of the crop that walked through our doors.

What to expect

Candidates will typically give you a range of responses based on their experience and personality. So it's up to you to decide the correctness of their answer.

@IftiMahmud
IftiMahmud / getFileExt
Created January 5, 2015 06:40
File Extension Finder in PHP
<?php
//Elegant Way to Find File Extension in PHP
// WAY-1:
$file_name = "ding.txt";
echo substr(strrchr($file_name,'.'),1).'<br/>'; //Shows ext. eg; txt
echo substr(strrchr($file_name,'.'),0).'<br/>'; //Shows ext followed by a dot (.); eg; .txt
@IftiMahmud
IftiMahmud / AutoImageDownloader
Created January 21, 2015 21:46
AutoImageDownloader: Download all images from a server. Works if you know the URL of the images.
<?php
//Auto download all images of an album.
//Works if the images are stored in sequential order in the server. eg: img-01, img-02, img-03 etc.
for ($i=0; $i <=10; $i++) { //capturing first 10 images. change the max value to download more
$d = 'http://example.com/album/image-0'; //first part of the image uri
$e = $i; //image number
$f = '.jpg'; //img extension
@IftiMahmud
IftiMahmud / PHPMySqlMassEmailer.php
Last active November 30, 2023 14:55
PHP Script to send mass email. This script will take subscribers emails from MySql database and send them bulk emails. Comes with Unsubscriber script.
<?php
//SOURCE: http://thedigilife.com/bulk-email-script-in-php-and-mysql-database/
$con = mysql_connect("localhost","dbuser","dbpass"); // replace dbuser, dbpass with your db user and password
mysql_select_db("dbname", $con); // replace dbname with your database name
/*
To use this script database table must have three fields named sno, email and sub_status
*/
$query = "select sno, email from dbtable where sub_status = 'SUBSCRIBED'";
$result = mysql_query($query, $con);
$emails = array();
@IftiMahmud
IftiMahmud / http_pool.php
Last active August 29, 2015 14:27 — forked from phpfour/http_pool.php
Concurrent requests using pecl_http
<?php
$endpoint = "http://api.someservice.com";
$userId = 101;
$urls = array(
$endpoint . '/profile/' . $userId,
$endpoint . '/orderHistory/' . $userId,
$endpoint . '/currentBalance/' . $userId
);
@IftiMahmud
IftiMahmud / CountryListWithCountryCode.html
Created September 11, 2015 00:15
County list with calling codes and country names in local languages. Usable in registration forms.
<ul class="country-list" style="top: -199px;"><li data-country-code="us" data-dial-code="1" class="country preferred"><div class="flag"><div class="iti-flag us"></div></div><span class="country-name">United States</span><span class="dial-code">+1</span></li><li data-country-code="gb" data-dial-code="44" class="country preferred active"><div class="flag"><div class="iti-flag gb"></div></div><span class="country-name">United Kingdom</span><span class="dial-code">+44</span></li><li class="divider"></li><li data-country-code="af" data-dial-code="93" class="country"><div class="flag"><div class="iti-flag af"></div></div><span class="country-name">Afghanistan (‫افغانستان‬&lrm;)</span><span class="dial-code">+93</span></li><li data-country-code="al" data-dial-code="355" class="country highlight"><div class="flag"><div class="iti-flag al"></div></div><span class="country-name">Albania (Shqipëri)</span><span class="dial-code">+355</span></li><li data-country-code="dz" data-dial-code="213" class="country"><div class="f