Skip to content

Instantly share code, notes, and snippets.

View hanigamal's full-sized avatar
🎯
Focusing at office

Hani Gamal hanigamal

🎯
Focusing at office
View GitHub Profile
<?php
$path = '/home/someuser/products/data.tar.gz'; // the file made available for download via this PHP file
$mm_type="application/octet-stream"; // modify accordingly to the file type of $path, but in most cases no need to do so
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: " . $mm_type);
function get_day_name($timestamp) {
$date = date('d/m/Y', $timestamp);
if($date == date('d/m/Y')) {
$day_name = 'Today';
} else if($date == date('d/m/Y',now() - (24 * 60 * 60))) {
$day_name = 'Yesterday';
}
return $date;
}
print date('G:i:s', $last_access).' '.get_day_name($last_access);
<?php
//Basic True / False Declaration
$is_admin = ($user['permissions'] == 'admin' ? true : false);
//Conditional Welcome Message
echo 'Welcome '.($user['is_logged_in'] ? $user['first_name'] : 'Guest').'!';
//Conditional Items Message
echo 'Your cart contains '.$num_items.' item'.($num_items != 1 ? 's' : '').'.';
//Conditional Error Reporting Level
error_reporting($WEBSITE_IS_LIVE ? 0 : E_STRICT);
//Conditional Basepath
@hanigamal
hanigamal / rmDuplicates.func.js
Created June 15, 2013 12:54
// Remove duplicates from DOM (not done yet)
// Remove duplicates from DOM (not done yet)
function remDuplicates() {
var seen = {};
$('td.group').each(function() {
var txt = $(this).text();
if (seen[txt])
$(this).empty();
else
seen[txt] = true;
});
@hanigamal
hanigamal / gist:5788033
Created June 15, 2013 12:52
Pure JS undo
/*
/**
* @constructor
*/
Commands = function() {
this.undoStack = [];
this.redoStack = [];
};
/**
@hanigamal
hanigamal / gist:5788020
Last active December 18, 2015 13:09
jquery functions for record
function load(_this, init){
var name = generateName(_this);
var type = _this.attr('type');
if(!type)
type = _this.prop("tagName");
if(!init && type != 'radio' && type != 'checkbox')
localStorage.setItem(name, _this.val())
@hanigamal
hanigamal / gist:5788011
Created June 15, 2013 12:45
jquery record
if (jQuery)
(function(jQuery){
jQuery.extend(jQuery.fn, {
record: function(options){
jQuery(this).each(function(){
var settings = jQuery.extend({
}, options);
var _this = $(this);
load(_this, true);
_this.on('blur change', function() {
@hanigamal
hanigamal / gist:5787987
Created June 15, 2013 12:37
jquery simple math
(function ($) {
'use strict';
$.fn.math = function (operation, a, b) {
return this.each(function () {
var result = 0;
switch(operation){
case '+':
result = a + b;
break;
@hanigamal
hanigamal / gist:5786872
Created June 15, 2013 04:15
jQuery match a text attribute that does not exist
//You're trying to match a text attribute that does not exist. You cannot write:
$("#Select0 option[text='" + myText + "']").get(0).selected = true;
You can use filter() instead:
$("#Select0 option").filter(function() {
return $(this).text() == myText;
}).get(0).selected = true;
//Or, taking more advantage of the library:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
// Generated on: 2012-04-13 23:44:46 GMT+00:00
// ************** Tweet 1 of 47455 **************
{
"in_reply_to_screen_name": null,