Skip to content

Instantly share code, notes, and snippets.

@ZellSnippets
ZellSnippets / gist:8763134
Created February 2, 2014 04:37
JS: Make Single Call Function
/**
* Two methods to make a single function call
*/
// Using a flag
var myFun = (function() {
var called = false;
return function() {
if (!called) {
console.log("I've been called");
@ZellSnippets
ZellSnippets / gist:8467276
Created January 17, 2014 02:05
htaccess: Redirect rules
Redirects.
http://codegarage.com/blog/2011/03/how-to-301-redirect-your-wordpress-blog-to-a-new-url/
# Test 1
RewriteEngine on
RewriteRule ^(.*)$ http://yourcodegarage.com/blog/$1 [R=301,L]
# Test 2
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/$
@ZellSnippets
ZellSnippets / gist:8429878
Created January 15, 2014 02:42
WP: wp_query args
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query
* Source: http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/query.php
*/
$args = array(
@ZellSnippets
ZellSnippets / gist:8050638
Created December 20, 2013 05:13
JS: Render Handlebars template with ajax
/**
* Requests for Handlebars Templates with jquery ajax function
*
* Usage:
* var template = Handlebars.renderTemplate('templateName', templateData);
*
* Feel free to append template anywhere else after.
*
* @author : Zell Liew
*
@ZellSnippets
ZellSnippets / gist:7866908
Created December 9, 2013 03:16
JS:Sticky Nav & other items
$(window).scroll(function(event) {
var headerArea = $header.offset().top + $header.height();
var windowTop = $(window).scrollTop();
if (windowTop > headerArea) {
// do stuff
}
});
@ZellSnippets
ZellSnippets / gist:7497915
Created November 16, 2013 09:12
JS: Getting date objects
var current = new Date(),
day = current.getDate(),
month = current.getMonth(),
year = current.getFullYear();
/**
* Converting to and from milliseconds.
*/
// Converting to:
@ZellSnippets
ZellSnippets / gist:7064528
Created October 20, 2013 03:10
SCSS: Triangle Mixin
@mixin triangle($direction, $color, $size) {
@if $direction == "left" {
border-bottom: $size solid transparent;
border-right: $size solid $color;
border-top: $size solid transparent;
}
@else if $direction == "right" {
border-bottom: $size solid transparent;
@ZellSnippets
ZellSnippets / gist:7054020
Created October 19, 2013 10:09
SCSS: Font smoothing webkit
html {
-webkit-font-smoothing: antialiased;
font-smoothing: antialiased;
}
@ZellSnippets
ZellSnippets / gist:7022014
Created October 17, 2013 09:41
JS: window resize event
// Simple debouncer.
// https://github.com/louisremi/jquery-smartresize
function on_resize(c, t) {
onresize = function() {
clearTimeout(t);
t = setTimeout(c, 100)
};
return c
};
@ZellSnippets
ZellSnippets / gist:6963219
Created October 13, 2013 14:55
SCSS: Responsive image solutions
// Responsive image with padding bottom hack
.parent {
position: relative;
padding-bottom: 75%; /* 3:4 aspect ratio */
}
.child {
position: absolute;
top: 0;
}