Skip to content

Instantly share code, notes, and snippets.

View Kindari's full-sized avatar

William Cahill-Manley Kindari

  • San Diego, California
View GitHub Profile
<?php
namespace Fuel\Migrations;
class Create_sessions {
public function up()
{
\DBUtil::create_table('sessions', array(
'session_id' => array('constraint' => 40, 'type' => 'varchar'),
@Kindari
Kindari / gist:1857252
Created February 18, 2012 03:42
Bind unbound methods to instances
def bind(method, instance, klass = None, setbound = True, name = None):
if klass is None:
klass = instance.__class__
bound = method.__get__(instance, klass)
if setbound:
setattr(instance, name or method.__name__, bound)
return bound
@Kindari
Kindari / gist:1857394
Created February 18, 2012 04:25
Python Abomination
class Service(object):
def __init__(self):
for method_name in dir(self):
method = getattr(self, method_name)
if callable(method) and hasattr(method, '__func__'):
for base in self.__class__.__bases__:
setattr(base, method_name, method.__func__)
class Foo(Service): pass
>>> class Foobar(object):
... CONSTANT = 'test'
... def test(self): print self.CONSTANT
...
>>> Foobar.CONSTANT
'test'
>>> f = Foobar()
>>> f.CONSTANT
'test'
>>> f.test()
@Kindari
Kindari / routes.php
Created August 19, 2012 11:56
testitoe example in #laravel
<?php
Route::get('(:bundle)', 'admin::admin@index');
Route::Controller('admin::admin');
<?php
Route::any('(:bundle)/(:any?)', function($method='index')
{
return Controller::call('admin::admin@' . $method);
});
@layout('single-column')
@section('content')
Whatever
@endsection
@Kindari
Kindari / gist:3667863
Created September 7, 2012 17:12
MySQL Backup All Databases with skip
USER="backup"
PASSWORD="****"
OUTPUTDIR="/home/dbbackup/backups"
MYSQLDUMP="/usr/bin/mysqldump"
MYSQL="/usr/bin/mysql"
SKIP=(mysql information_schema performance_schema)
# get a list of databases
databases=`$MYSQL --user=$USER --password=$PASSWORD \
-e "SHOW DATABASES;" | tr -d "| " | grep -v Database`
$patterns = array(
'#(?P<category>[^\d\/]+)?\/?(?P<year>\d{4})?\/?(?P<month>\d{1,2})?\/?(?P<day>\d{1,2})?$#', // Listing
'#(?P<year>\d{4})\/(?P<month>\d{1,2})\/(?P<day>\d{1,2})\/(?P<slug>.*)#', // Entry
);
@Kindari
Kindari / example.php
Created September 19, 2012 23:27
Locale aware Api routing in Laravel 3
<?php // bundles/api_v1/controllers/example.php
class Api_V1_Example_Controller extends Controller
{
public $restful = True;
public function get_hello($name='World')
{
return "Hello, {$name}!";
}