Skip to content

Instantly share code, notes, and snippets.

View kemo's full-sized avatar
💭
killing it

kemo

💭
killing it
View GitHub Profile
@kemo
kemo / route.php
Created November 28, 2011 22:43
Kohana 3 Route cache append
<?php defined('SYSPATH') or die('No direct script access.');
class Route extends Kohana_Route {
/**
* Changed:
* - use Cache module instead of Kohana::cache()
* - append cached routes instead of assigning them directly
*/
public static function cache($save = FALSE)
@kemo
kemo / style.less
Created December 6, 2011 16:06
Pay LESS
// Border Radius
.border-radius(@radius: 5px) {
-webkit-border-radius: @radius;
-moz-border-radius: @radius;
border-radius: @radius;
}
// Drop shadows
.box-shadow(@shadow: 0 1px 3px rgba(0,0,0,.25)) {
-webkit-box-shadow: @shadow;
@kemo
kemo / gist:1506275
Created December 21, 2011 14:46
Kohanas' new view action return handling
<?php
public function action_index()
{
$causes_count = ORM::factory('cause')->count_all();
$causes = ORM::factory('cause')->paginate($causes_count)->find_all();
return compact('causes','causes_count');
}
@kemo
kemo / routes.php
Created December 22, 2011 16:01
Kohana routing proposal
<?php
Route::set('help::index', 'pomoc');
Route::set('help::read','pomoc/<id>');
Route::set('cause::view','svrha/<id>(/<seo>)', array('id' => '[0-9]+','seo' => '.+');
Route::set('cause::add', 'dodaj_svrhu');
Route::set('user::login','login');
Route::set('user::signup','registracija');
@kemo
kemo / gist:2011193
Created March 10, 2012 11:27
example JSend action
<?php
public function action_feedback()
{
// Only AJAX requests!
if ( ! $this->request->is_ajax())
return $this->redirect();
$feedback = new Model_Testimonial;
$view = new View_Page_Feedback;
$json = JSend::factory(array('html' => $view));
@kemo
kemo / file.php
Created March 23, 2012 13:19
file::delete()
<?php
class file {
/**
* Error code to signal that the file is missing
* This is always a positive value because we can
* consider files which didn't exist already as 'deleted'.
*/
const MISSING = 1;
@kemo
kemo / ORM.php
Created March 26, 2012 22:51
Speed up Kohana ORM init
<?php defined('SYSPATH') or die('No direct script access.');
class Kohana_ORM extends Model implements serializable {
/**
* Initialization storage for ORM models
* @var array
*/
protected static $_init_cache = array();
<?php
class url {
protected $_static_extensions = array('ico','jpg','gif','bmp','png','js','css');
/**
* Fetches an absolute site URL based on a URI segment.
*
* @param string site URI to convert
@kemo
kemo / .htaccess
Created March 30, 2012 14:46
Detect AJAX with .htaccess rewrite rule (mod_rewrite test)
RewriteCond %{HTTP:X-Requested-With} !=XMLHttpRequest
RewriteCond %{HTTP:X-REQUESTED-WITH} !^(XMLHttpRequest)$
@kemo
kemo / ORM.php
Created March 31, 2012 09:05
Initial ORM::delete_all() 'idea'
<?php
public function delete_all()
{
$objects = $this->find_all()
->as_array($this->_primary_key);
if (method_exists($this, '_delete_row'))
{
foreach ($objects as $object)