Skip to content

Instantly share code, notes, and snippets.

View kemo's full-sized avatar
💭
killing it

kemo

💭
killing it
  • Sarajevo, Bosnia and Herzegovina
  • X @delalick
View GitHub Profile
@kemo
kemo / index.php
Created April 2, 2012 09:20
View Model for on-the-fly MySQL profiling
<?php defined('SYSPATH') or die('No direct script access.');
/**
* @author Kemal Delalic <kemal.delalic@gmail.com>
*/
class View_Admin_System_Index extends View_Admin_Layout {
/**
* @var cache for self::mysql_processes()
*/
protected $_mysql_processes;
@kemo
kemo / hack.sh
Created March 31, 2012 10:25 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@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)
@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)$
<?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 / 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();
@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 / 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 / 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: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');
}