Skip to content

Instantly share code, notes, and snippets.

@psdtohtml5
psdtohtml5 / gist:5908031
Created July 2, 2013 09:46
jQuery: Drag and scroll horizontal div
<script type="text/javascript">
$(document).ready(function() {
$('.dragger').mousedown(function (event) {
$(this)
.data('down', true)
.data('x', event.clientX)
.data('scrollLeft', this.scrollLeft)
.addClass("dragging");
return false;
@psdtohtml5
psdtohtml5 / snippet.js
Created October 15, 2013 23:58
JavaScript : Add Business days to a date
// https://github.com/lsmith/addBusinessDays/blob/master/addBusinessDays.js
// var d = new Date();
// addBusinessDays(d, numberOfDays);
function addBusinessDays(d,n) {
d = new Date(d.getTime());
var day = d.getDay();
d.setDate(d.getDate() + n + (day === 6 ? 2 : +!day) + (Math.floor((n - 1 + (day % 6 || 1)) / 5) * 2));
return d;
}
@psdtohtml5
psdtohtml5 / gist:6071607
Created July 24, 2013 15:26
PHP : Check if array has duplicate values
function array_has_dupes($array) {
return count($array) !== count(array_unique($array));
}
@psdtohtml5
psdtohtml5 / gist:5646810
Created May 24, 2013 22:03
PHP: Secure File Download
<?php
// PHP SECURE FILE DOWNLOAD
// Put the Files in a directory that is not publically accessible.. maybe outside document root or set correct permissions
if (!$_SESSION["authenticated"]) {
// If not authenticated then send back to the login page
$host = $_SERVER["HTTP_HOST"];
$path = rtrim(dirname($_SERVER["PHP_SELF"]), "/\\");
header("Location: http://$host$path/login.php?err=true");
exit;
@psdtohtml5
psdtohtml5 / gist:6090113
Last active September 5, 2021 16:09
PHP : Auto expire session / Auto logout after specific time
<?php
//on pageload
session_start();
$idletime=60;//after 60 seconds the user gets logged out
if (time()-$_SESSION['timestamp']>$idletime){
session_destroy();
session_unset();
}else{
@psdtohtml5
psdtohtml5 / gist:6114534
Last active June 5, 2020 15:43
PHP : Weather Widget
function getRealIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP']))
//check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
//to check ip is pass from proxy
{
@psdtohtml5
psdtohtml5 / snippet.js
Created August 12, 2013 21:39
JavaScript : Scroll and Focus to Element (input)
var cursorFocus = function(elem) {
var x = window.scrollX, y = window.scrollY;
window.scrollTo(x, y);
elem.focus();
}
cursorFocus(document.getelementbyId('search-terms'));
@psdtohtml5
psdtohtml5 / snippet.php
Created August 17, 2013 13:54
PHP : Laravel 4 Database transactions
try {
DB::connection()->getPdo()->beginTransaction();
// database queries here
DB::connection()->getPdo()->commit();
} catch (\PDOException $e) {
// Woopsy
DB::connection()->getPdo()->rollBack();
}
@psdtohtml5
psdtohtml5 / snippet.html
Created October 17, 2013 22:42
HTML : Wai-Aria template
<!doctype html>
<html>
<head>
<title>Title of your document</title>
<meta charset="utf-8">
<meta name="description" content="">
</head>
<body>
@psdtohtml5
psdtohtml5 / snippet.txt
Created August 21, 2013 05:55
OPENSSL : Base64 Encode
openssl base64 < path/to/file.png | tr -d '\n' | pbcopy