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 / sleep.js
Created April 14, 2013 11:57
JavaScript: Sleep Functions (Sleep in Milliseconds and Seconds)
/* ============================================================
| :=Sleep (Delay)
=============================================================== */
// Milliseconds
function sleep_ms(millisecs) {
var initiation = new Date().getTime();
while ((new Date().getTime() - initiation) < millisecs);
}
@irazasyed
irazasyed / is_ajax.php
Created April 14, 2013 12:00
PHP: isAjax request check function
<?php
/*-------------------------------------------------+
| Checks if the http request is an AJAX call.
+-------------------------------------------------*/
function is_ajax() {
return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower(getenv('HTTP_X_REQUESTED_WITH')) === 'xmlhttprequest'));
}
?>
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 / spin.js
Created April 14, 2013 12:06
JavaScript: Text Spinner Function
/* ============================================================
| :=Text Spinner
=============================================================== */
function preg_quote(str, delimiter) {
return (str + '').replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + (delimiter || '') + '-]', 'g'), '\\$&');
}
function spin(text) {
var matches = text.match(/{[^<]+/gi);
if (matches === null) {
@irazasyed
irazasyed / cookies.js
Created April 14, 2013 12:14
JavaScript: Set/Get Cookies!
/* ============================================================
| :=Set Cookie
=============================================================== */
function setCookie(name, value, expire) {
var expireDate = new Date();
expireDate.setDate(expireDate.getDate() + expire);
document.cookie = name + "=" + escape(value) + "; expires=" + expireDate.toGMTString() + "; path=/";
}
/* ============================================================
@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 / 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 / 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 / amung_stats.php
Created April 14, 2013 12:31
PHP: Get whos.amung.us visitors stats
/*-------------------------------------------------+
| Get current visitors count (whos.amung.us)
+-------------------------------------------------*/
function getAmungStats($amung) {
if(!isset($amung)) return false;
$url = 'http://whos.amung.us/sitecount/' . $amung . '/';
$result = '';
if (function_exists('curl_init')) {
$http_headers = array();