Skip to content

Instantly share code, notes, and snippets.

@psdtohtml5
psdtohtml5 / snippet.php
Created August 17, 2013 13:53
PHP : Laravel 3 Database Transactions
try {
DB::connection()->pdo->beginTransaction();
// database queries here
DB::connection()->pdo->commit();
} catch (\PDOException $e) {
// Woopsy
DB::connection()->pdo->rollBack();
}
@psdtohtml5
psdtohtml5 / snippet.html
Created August 15, 2013 12:54
CSS : Sticky footer , Footer at bottom
<!-- SINGLE COLUMN LAYOUT -->
<div id="wrap">
<header id="header"></header>
<section id="main"></section>
</div>
<footer id="footer"></footer>
<!-- MULTI COLUMN LAYOUT -->
<div id="wrap">
<header id="header"></header>
@psdtohtml5
psdtohtml5 / gist:6156480
Last active December 20, 2015 15:48
Google Maps
<script>
showMap([
{
target: "map-canvas",
locations: [
["Saved Home 1",-25.363882,131.040922],
["Saved Home 2",-25.363882,131.044922],
["Saved Home 3",-25.363882,131.048922],
["Saved Home 4",-25.363882,131.052922],
["Saved Home 5",-25.363882,131.056922],
@psdtohtml5
psdtohtml5 / gist:6114930
Created July 30, 2013 17:19
PHP : Extract image source from HTML
$doc = new DOMDocument();
$doc->loadHTML($html);
$tags = $doc->getElementsByTagName('img');
foreach ($tags as $tag) {
echo $tag->getAttribute('src');
}
@psdtohtml5
psdtohtml5 / gist:6114544
Created July 30, 2013 16:30
PHP : Get IP
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: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: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;
}