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:1021338
Created June 12, 2011 08:06
Kohana Valid::timestamp()
<?php defined('SYSPATH') or die('No direct script access.');
class Valid extends Kohana_Valid {
/**
* TODO: test
* http://stackoverflow.com/questions/3377537/checking-if-a-string-holds-an-integer/3377612
*
*/
public static function timestamp($timestamp)
@devi
devi / gist:1004075
Created June 2, 2011 07:35
Don't expect an empty post
public function extract_post()
{
$required_fields = array(
'post-title',
'post-slug',
'post-status',
'post-layout',
'post-content',
'post-publish',
'post-expire'
@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
*/
@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`
<?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], '-')));
.pagination {
margin-top:1.5em;
text-align:center;
padding:2px 2px 1.5em;
}
.pagination a {
text-shadow:none;
}
@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
// ============================================================
// 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 / 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
*/
@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>