Skip to content

Instantly share code, notes, and snippets.

@321zeno
321zeno / read-image-file-for-output-as-base64-src
Last active October 6, 2015 22:07
read image file for output as base64 in img tag
public function getImage($name){
$folder_path = '/physical/path/to/file/';
$image_path = $folder_path.$name;
$filetype = pathinfo($image_path, PATHINFO_EXTENSION);
if (file_exists($image_path)) {
$file_data = file_get_contents($image_path);
return 'data:image/' . $filetype . ';base64,' . base64_encode($file_data);
}
}
@321zeno
321zeno / get-height-of-hidden-element-using-jquery
Last active December 16, 2015 13:29
Get height of hidden element using jQuery. Credits go to http://stackoverflow.com/users/414385/hitautodestruct
jQuery(function( $ ){
$.fn.actualHeight = function(){
// find the closest visible parent and get it's hidden children
var visibleParent = this.closest(':visible').children(),
thisHeight;
// set a temporary class on the hidden parent of the element
visibleParent.addClass('temp-show');
@321zeno
321zeno / bottom-footer
Created April 25, 2013 12:26
push the footer to the bottom of the browser
@321zeno
321zeno / gist:5495395
Created May 1, 2013 13:55
Basic gruntfile to use for Foundation projects
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
files: {
grunt: ['Gruntfile.js'],
js: ['javascripts/foundation/jquery.js',
'javascripts/**/*.js',
'javascripts/*.js',
@321zeno
321zeno / php-explore-recursive.php
Last active December 17, 2015 04:28
A recursive PHP function that returns all the contents of a folder
function explore_recursive($path) {
$contents = glob($path .'*', GLOB_BRACE);
if (count($contents) > 0) {
foreach ($contents as $item) {
$file['name'] = basename($item);
// $file['location'] = $item;
$found = explore_recursive($item . '/');
if ($found) { $file['contents'] = $found; }
$branch[] = $file;
}
@321zeno
321zeno / mustache-object-php.php
Last active December 17, 2015 08:49
A simple class to initialize objects to use with Mustache.php
<?php
class Core_Base
{
/**
* the constructor will assign
* - the values specified in the constructor's arguments, in that specific order as the object's properties
* - if an array is passed as argument, the values from that array will be passed as the object's properties
* - the object's properties which have no value assigned will be set to false to prevent name collisions in the mustache templates
*/
@321zeno
321zeno / AdminRedactorController.php
Last active August 29, 2015 14:21
Using Redactor WYSIWYG with Laravel 4.x
<?php
class AdminRedactorController extends AdminController {
private $publicFolder = 'redactor_uploads';
private $uploadFolder = 'public/' . $publicFolder;
public function fileUpload(){
@321zeno
321zeno / DropzoneController.php
Created May 24, 2015 16:36
Replace a file input with a dropzone (for an image) in Laravel 4.x
<?php
class DropzoneController extends BaseController {
public function upload() {
$r = Util::uploadUnique('file', Config::get('website.dropzone_uploads'));
extract($r);
//return response
@321zeno
321zeno / ImageResizeController.php
Last active August 29, 2015 14:22
Resize images on the fly
<?php
class ImageResizeController extends BaseController {
/**
* This method catches urls like /imagecache/width/height/path/to/original_image.jpg and
* creates the image if public/imagecache/width/height/path/to/original_image.jpg doesn't exist.
*
* Urls like this are used for returning a resized version of /path/to/original_image.jpg
@321zeno
321zeno / remove_hover_rule.js
Last active September 10, 2015 09:19 — forked from rcmachado/remove_hover_rule.js
Remove CSS :hover rules for touch devices to avoid iOS double-tap behavior. Copied and adapted from http://retrogamecrunch.com/tmp/hover (just a fix for sheet.cssRules)
// disable :hover on touch devices
// based on https://gist.github.com/4404503
// via https://twitter.com/javan/status/284873379062890496
// + https://twitter.com/pennig/status/285790598642946048
// re http://retrogamecrunch.com/tmp/hover
// NOTE: we should use .no-touch class on CSS
// instead of relying on this JS code
function removeHoverCSSRule() {
if ('createTouch' in document) {
try {