Skip to content

Instantly share code, notes, and snippets.

@smgladkovskiy
smgladkovskiy / kohana_exception.php
Created February 17, 2011 11:59
Kohana Exception extention
<?php defined('SYSPATH') or die('No direct access allowed.');
class Kohana_Exception extends Kohana_Kohana_Exception {
public static function handler(Exception $e)
{
if (Kohana::$environment > Kohana::PRODUCTION)
{
parent::handler($e);
}
@lukemorton
lukemorton / jquery.shiftcheck.html
Created February 22, 2011 00:03
jquery.shift.js
<!doctype html>
<html>
<head>
<title>Shift Check</title>
<meta charset="utf-8" />
</head>
<body>
<h1>Shift Check</h1>
<p>Try the following combos:</p>
<ul>
@zombor
zombor / deploy.rb
Created March 21, 2011 18:05
zombor's capistrano deploy scripts
set :stages, %w(production staging)
set :default_stage, "staging"
require 'capistrano/ext/multistage'
# --------------------------------------------
# Repository
# --------------------------------------------
set :scm, :git # I am using git, so I specify it here
set :repository, "<repo>" # This is the path to the repository on the server, we pushed the code here earlier.
@kanema
kanema / orm.php
Created April 27, 2011 03:41
kohana orm dynamic finder
class ORM extends Kohana_ORM {
/**
* Dynamic Finder:
* $orm->find_by_name('eduardo');
* $orm->find_all_by_name('eduardo');
* $orm->count_by_name('eduardo');
* $orm->find_all_by_name_or_email('eduardo');
* $orm->find_all_by_name_and_email('eduardo', 'du@kanema.com.br');
* $orm->find_all_by_name_and_email_and_is_active('eduardo', 'du@kanema.com.br', TRUE);
@alkavan
alkavan / json.php
Created June 12, 2011 19:59
JSON Helper for Kohana v3
<?php defined('SYSPATH') or die('No direct script access.');
/**
* JSON helper class
*
* Examples:
* $j = JSON::decode('{"Organization": "Kohana"}'); // Good
* $j = JSON::decode("{'Organization': 'Kohana'}"); // Invalid
* $j = JSON::decode('{"Organization": "Kohana"}', NULL, 1); // depth stack exceeded
*
* @package Kohana
@xwero
xwero / gist:1022345
Created June 13, 2011 05:23
Throw Kohana exception if json function returns nothing
<?php
/**
* Throw Kohana exception if json function returns nothing
*
* @example
* $en = json_encode("\xB1\x31");
*
* check_json_error($en);
*
* $de = json_decode("{'Organization': 'Kohana'}");
@kiall
kiall / bla.php
Created August 20, 2011 16:02
Valid::at_least()
<?php defined('SYSPATH') or die('No direct script access.');
class Model_Bla extends ORM {
public function rules()
{
return array(
'phone_one' => array(
array('at_least', array($this, 1, array('phone_one', 'phone_two', 'phone_three'))),
),
@isaiahdw
isaiahdw / applicationclasseslogemail.php
Created September 3, 2011 20:58
Email Log writer
<?php defined('SYSPATH') or die('No direct script access.');
class Log_email extends Log_Writer {
/**
* Email the log message to the website administrator.
*
* @param array messages
* @return void
*/
@lukemorton
lukemorton / Controller_News.php
Created September 19, 2011 09:47
Dealing with pagination in MVVM
<?php
class Controller_News {
public function action_category()
{
$category = ORM::factory('news_category', array('url' => $this->request->param('category')));
if ( ! $category->loaded())
{
<?php
class Pagination {
public static function factory($total, $limit = 5, $page = 1, $adjacents = 2)
{
return new Pagination($total, $limit, $page, $adjacents);
}
public $total;