Skip to content

Instantly share code, notes, and snippets.

View irazasyed's full-sized avatar
🎯
WIP

Irfaq Syed irazasyed

🎯
WIP
View GitHub Profile
@irazasyed
irazasyed / GeoRedirect.md
Last active March 15, 2016 01:48
HTML: Geo Redirection Script using MaxMind's GeoIP API

Geo Redirection Script using GeoIP API JS

NOTICE: Moved to Git Repo with another version. Will keep it updated there!

@irazasyed
irazasyed / browser detect
Created November 21, 2012 17:42 — forked from sanooj/browser detect
jQuery: Browser Detect for html
$(document).ready(function()
{
if ( $.browser.msie ){
if($.browser.version == '6.0')
{ $('html').addClass('ie6');
}
else if($.browser.version == '7.0')
{ $('html').addClass('ie7');
}
else if($.browser.version == '8.0')
@irazasyed
irazasyed / gist:4178136
Created November 30, 2012 19:54
JavaScript: Get Current URL
// Get current URL but without the filename.
var currentUrl = window.location.href;
currentUrl = currentUrl.substring(0, currentUrl.lastIndexOf('/')+1);
@irazasyed
irazasyed / gist:4241706
Created December 8, 2012 20:08
JavaScript: Function - inArray Snippet.
function inArray(needle, haystack) {
var length = haystack.length;
for(var i = 0; i < length; i++) {
if(haystack[i] == needle) return true;
}
return false;
}
@irazasyed
irazasyed / reset_id_column.sql
Last active February 1, 2023 19:23
MySQL: Reset id column to auto increment from 1
-- your_table: The table to modify
-- id: The id field/column to reset
SET @num := 0;
UPDATE your_table SET id = @num := (@num+1);
ALTER TABLE your_table AUTO_INCREMENT =1;
@irazasyed
irazasyed / gist:4340653
Created December 19, 2012 21:24
PHP: Resize image and return img resource
/*------------------------------------------------------+
| Resize Image with crop or without crop and
| return resource
+------------------------------------------------------*/
function resize_image($file, $w, $h, $crop=FALSE) {
list($width, $height) = getimagesize($file);
$r = $width / $height;
if ($crop) {
if ($width > $height) {
$width = ceil($width-($width*($r-$w/$h)));
@irazasyed
irazasyed / gist:4340671
Created December 19, 2012 21:26
PHP: Draw Border to any image.
/*------------------------------------------------------+
| Provide image resource, border color and thickness to
| add border to the resource.
+------------------------------------------------------*/
function drawBorder(&$img, &$color, $thickness = 1) {
$x1 = 0;
$y1 = 0;
$x2 = ImageSX($img) - 1;
$y2 = ImageSY($img) - 1;
@irazasyed
irazasyed / gist:4340722
Created December 19, 2012 21:32
PHP: Remove directory and its contents
/**
* Remove the directory and its content (all files and subdirectories).
* @param string $dir the directory name
*/
function rmrf($dir) {
foreach (glob($dir) as $file) {
if (is_dir($file)) {
rmrf("$file/*");
rmdir($file);
} else {
@irazasyed
irazasyed / gist:4340734
Created December 19, 2012 21:34
PHP: Match wildcard in string
function match_wildcard( $wildcard_pattern, $haystack ) {
$regex = str_replace(
array("\*", "\?"), // wildcard chars
array('.*','.'), // regexp chars
preg_quote($wildcard_pattern)
);
return preg_match('/^'.$regex.'$/is', $haystack);
}
@irazasyed
irazasyed / getRandomImage.php
Last active December 9, 2015 22:58
PHP: getRandomImg from any directory! (Supports JPG/JPEG & PNG)
<?php
/**
* Picks one random jpg/jpeg/png format image from the specified directory.
* @param string $dir Images directory path.
* @param boolean $realPath True to return real path of the image.
* @return string Path to one random image.
*/
function getRandomImg ( $dir, $realPath = false ) {
$dir = rtrim($dir, '/'); // Just in case if there is any trailing slash.
$images = glob($dir . '/*.{jpg,jpeg,png}', GLOB_BRACE);