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: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: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:1033909
Created June 19, 2011 07:56
slug/permalink validation
<?php
// lower alpha
// alnum followed by alnum or hyphen between alnum
function valid_slug1($value)
{
return (bool) preg_match('/^[a-z0-9]+(-[a-z0-9]+)*$/iD', (string) $value);
}
@devi
devi / gist:1097496
Created July 21, 2011 15:53
regular path validation
<?php
// lower alpha
// alnum followed by alnum or (hyphen, dash or slash between alnum)
function valid_path($path)
{
return (bool) preg_match('/^[a-z0-9]+([-_\/][a-z0-9]+)*$/iD', $path);
}
<?php
class Pagination {
public static function factory($total, $limit = 5, $page = 1, $adjacents = 2)
{
return new Pagination($total, $limit, $page, $adjacents);
}
public $total;
@devi
devi / hierarchy.php
Last active August 16, 2024 16:49
MySQL "Closure Table" for Kohana based on Bill Karwin design.
<?php defined('SYSPATH') or die('No direct script access.');
/**
* MySQL "Closure Table" for Kohana based on Bill Karwin design.
*
* @link http://www.slideshare.net/billkarwin/models-for-hierarchical-data
* @TODO improve
*
* sql schema:
* CREATE TABLE `closures` (
* `id` int(11) NOT NULL AUTO_INCREMENT,
<?php defined('SYSPATH') or die('No direct script access.');
/**
* This mechanism provides support for PHP [One-way string hashing](http://php.net/manual/en/function.crypt.php).
*
* Currently, only support 3 hashing type: blowfish, sha256, sha512
*
* @package Bonafide
* @category Mechanisms
* @author Wouter <wouter.w@gmx.net>
* @author Devi Mandiri <devi.mandiri@gmail.com>
@devi
devi / np.py
Created July 8, 2012 06:20
banshee pidgin status
#!/usr/bin/env python
"""
np.py - NowPlaying (https://github.com/Devkill/NowPlaying/)
Copyright 2011, devkill, www.devkill.net
Licensed under the sukatoro n ycl Forum License 3.
http://sukatoro.com/
http://yogyacarderlink.web.id
#yogyacarderlink #1stlink #magelangcyber
"""
import dbus, gobject
@devi
devi / Auth.php
Created December 15, 2012 18:01
Google Oauth2 Provider for https://github.com/kemo/oauth
<?php defined('SYSPATH') or die('No direct script access.');
/**
* OAuth2 sample controller
*
*/
class Controller_Auth extends Controller {
protected $session;
protected $provider;
@devi
devi / resizer.go
Created April 7, 2013 17:19
My first learing by doing in Go
// A small utility to resize images inside folder (including subfolder).
package main
import (
"fmt"
"flag"
"math"
"os"
"io/ioutil"
"os/exec"