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 / flatten_fql.php
Created December 19, 2012 21:49
PHP: Flatten FQL results array
/*-------------------------------------------------+
| Flattens FQL (Facebook Query Language) results in
| a good format
+-------------------------------------------------*/
function flattenFQL($array) {
if (!is_array($array)) {
return $array;
}
$result = array();
foreach ($array as $data) {
@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);
@irazasyed
irazasyed / cf-ip-ranges-updater.sh
Created September 14, 2014 14:27
CloudFlare IP Ranges Autoupdater - Via: http://git.io/RsbwaQ
#!/bin/sh
# (The MIT License)
#
# Copyright (c) 2013 M.S. Babaei
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@irazasyed
irazasyed / gist:5382523
Created April 14, 2013 12:27
PHP: Check if content contains string
function contains($str, $content, $ignorecase=true) {
if ($ignorecase){
$str = strtolower($str);
$content = strtolower($content);
}
return strpos($content,$str) ? true : false;
}
@irazasyed
irazasyed / stop_wrefresh.js
Created April 14, 2013 12:16
JavaScript: Stop Window Refresh
/* ============================================================
| :=Stop Window Refresh
=============================================================== */
function stopRefresh() {
if (window.myRefresh && window.clearTimeout) window.clearTimeout(myRefresh);
}
@irazasyed
irazasyed / check_email.php
Created April 14, 2013 12:56
PHP: Email validation function
/* Function: check for valid email input */
function checkEmail($string) {
$string = preg_match('/^[.\w-]+@([\w-]+\.)+[a-zA-Z]{2,6}$/', $string);
if(!$string){
echo "Email Address is Invalid,please check and enter your email address again eg: email@domain.com.";
}
return $string;
}
var getGooglAuthToken = function(b){
var c = function(){
for (var l=0, m=0, ml=arguments.length; m<ml; m++) l = l + arguments[m] & 4294967295;
return l;
}
var d = function(l){
l = String(l > 0 ? l : l + 4294967296);
var m = l;
for (var o=0, n=false, p=m.length-1; p>=0; --p){
var q = Number(m.charAt(p));
@irazasyed
irazasyed / browser_detect.js
Created April 14, 2013 12:20
JavaScript: Detect Browser
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
var is_firefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
var is_opera = navigator.userAgent.toLowerCase().indexOf('opera') > -1;
if(is_chrome) {
alert("This message is for Chrome Users!");
} else if(is_firefox) {
alert("This message is for Firefox Users!");
} else if(is_opera) {
alert("This message is for Opera Users!");
@irazasyed
irazasyed / server_status.php
Created April 14, 2013 12:33
PHP: Check server status
/*-------------------------------------------------+
| Get server status based on URL or IP
+-------------------------------------------------*/
function getServerStatus($serverUrl) {
$ping = @fsockopen ($serverUrl, 80, $errno, $errstr, 10);
if (!$ping) {
return 'Server is DOWN :(';
} else {
@fclose($ping);
return 'Server is UP :)';
##
# Command to empty Trash with 35-pass security method. This is the most secure deletion,
# so you will not be able to recover any file deleted with this method.
# Replace <MAC_USER> with your Mac username.
##
srm -rfv /Users/<MAC_USER>/.Trash/*
##
# Command to empty Trash with 7-pass security method that meets the