Skip to content

Instantly share code, notes, and snippets.

@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 / gist:6098630
Created July 28, 2013 13:44
JavaScript : Count unique items in an array
$.extend({
countUnique : function(array) {
var result = [];
$.each(array, function(i,v) {
if($.inArray(v, result) == -1) {
result.push(v);
}
});
return result.length;
}
@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:6083140
Created July 25, 2013 19:51
JavaScript : Get distinct / unique values
// Get distinct values from an array
$.extend({
distinct : function(anArray) {
var result = [];
$.each(anArray, function(i,v){
if ($.inArray(v, result) == -1) result.push(v);
});
return result;
}
@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:5991935
Created July 13, 2013 19:31
JavaScript : Create CSV File
var fullList = [];
$(".list-wrapper").each(function() {
var tempStr = "";
tempStr = '"' + $(this).find(".company-list-name a").text() + '"';
tempStr += ',"' + $(this).find(".profile-update").text() + '"';
tempStr += ',"' + $(this).find(".company-focus").text() + '"';
fullList.push(tempStr);
});
var output = fullList.join('\n');
var uri = 'data:application/csv;charset=UTF-8,' + encodeURIComponent(output);
@psdtohtml5
psdtohtml5 / gist:5991280
Created July 13, 2013 16:41
PHP : Recursively delete files and folders
<?php
//define('UPLOADFILES', dirname(dirname(__FILE__)) . '/sixpoints');
function recursiveDelete($path) {
// if (strpos($path, UPLOADFILES) === false) {
// exit('Trying to remove from wrong path to uploadfiles!');
// }
if (is_file($path)) {
return unlink($path);
} elseif ( is_dir($path) ){
@psdtohtml5
psdtohtml5 / gist:5974960
Created July 11, 2013 12:18
PHP : Dynamic Image Resize
<?php
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
@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 / gist:5871540
Created June 26, 2013 20:50
SQL: Update column with random numbers
UPDATE users SET password = floor(rand() * 9999999999) WHERE role=4