Skip to content

Instantly share code, notes, and snippets.

View devi's full-sized avatar
⛰️
Off-Grid

Devi Mandiri devi

⛰️
Off-Grid
View GitHub Profile
@devi
devi / gist:800524
Created January 28, 2011 16:43
hashbang
// jquery hashbang(#!)
function hasbang(){
$('a').each(function(){
var o = $(this), url = o.attr('href'), p = url.match('^https?://');
var h1 = location.hostname, h2 = h1.replace(/^www\./i,'');
if (url == '#') {
o.attr('href','javascript:void(0);');
return;
}
@devi
devi / gist:824742
Created February 13, 2011 15:02
addCss, addJs
$.fn.addCss = function(css){
var style = document.createElement('link');
style.rel = 'stylesheet';
style.type = "text/css";
style.href = css;
document.getElementById($(this).attr('id')).appendChild(style);
};
$.fn.addJs = function(js){
var script = document.createElement("script");
@devi
devi / gist:827464
Created February 15, 2011 12:32
mustache template
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>{{title}}</title>
{{#styles}}
{{#browser}}<!--[if {{logic}} ]>{{/browser}}<link rel="stylesheet" type="text/css" href="{{style}}" {{#media}}media="{{target}}"{{/media}} />{{#browser}}<![endif]-->{{/browser}}
{{/styles}}
{{#scripts}}
<script type="text/javascript" src="{{script}}"></script>
@devi
devi / gist:828977
Created February 16, 2011 07:05
Kohana HTML::style, HTML::script extended
/*
* Extend HTML::style
*
* @param string File name
* @param array Default attributes
* @param string Spesific browser logic/condition
* @param mixed Protocol to pass to URL::base()
* @param boolean Include the index page
* @return string
*/
// ============================================================
// Objects vs Primitives
// To make a long story short, use primitives wherever you can.
// ============================================================
// Primitive types: Null, Undefined, Number, Boolean, String.
var num1 = 9000,
num2 = new Number( 9000 ),
str1 = "hello world",
@devi
devi / kohana-helper.php
Created March 5, 2011 15:07
Kohana helper collection
<?php defined('SYSPATH') or die('No direct script access.');
class HELPER {
/*
* helper to load post from database
*
* @param int 4 digit ex. 2010
* @param int without leading zero
* @param string slug/permalink, if set then limit/offset will be ignore
.pagination {
margin-top:1.5em;
text-align:center;
padding:2px 2px 1.5em;
}
.pagination a {
text-shadow:none;
}
<?php defined('SYSPATH') OR die('No direct script access.');
class Valid extends Kohana_Valid {
public static function slug($str)
{
if (preg_match('/^[a-zA-Z0-9_-]+$/D', $str, $matches))
{
// Strip multiple dashes and trim an ending or starting dashes
return ($str === preg_replace('/-{2,}/', '-', trim($matches[0], '-')));
@devi
devi / gist:949366
Created April 30, 2011 03:17 — forked from paulirish/README.md
imagesLoaded() jquery plugin
// $('img.photo',this).imagesLoaded(myFunction)
// execute a callback when all images have loaded.
// needed because .load() doesn't work on cached images
// mit license. paul irish. 2010.
// webkit fix from Oren Solomianik. thx!
// callback function is passed the last image to load
// as an argument, and the collection as `this`
@devi
devi / gist:993453
Created May 26, 2011 16:17
Extend kohana sprig
<?php defined('SYSPATH') or die('No direct script access.');
abstract class Sprig extends Sprig_Core {
/**
* Returns the foreign key of the model, optionally with a table name.
*
* @param string table name, TRUE for the model table
* @return string
*/