Skip to content

Instantly share code, notes, and snippets.

<?php
class Controller_Admin extends \Controller {
protected $current_user = null;
protected $sortable = array(); // Used in action_sort for vars.
protected $filterable = array();
public function action_index()
{
@nerdsrescueme
nerdsrescueme / grid.less.css
Created June 8, 2011 16:10
CSS Less Library
@columns: 12;
@column: 60px;
@gutter: 10px;
@page: (@column * @columns) + ((@gutter * @columns) * 2);
.row {
width: @page;
margin: 0 auto;
overflow: hidden;
}
<?php
public static function data_uri($data, $mime)
{
return 'data:'.$mime.';base64,'.base64_encode($data);
}
public static function data_img($filename)
{
if ( ! static::find_file($filename, static::$_folders['img']))
<?php
return array(
'provinces' => array(
'AB' => 'Alberta',
'BC' => 'British Columbia',
'MB' => 'Manitoba',
'NB' => 'New Burnswick',
'NL' => 'Newfoundland and Labrador',
@nerdsrescueme
nerdsrescueme / generate.php
Created September 7, 2011 20:33
fuelmod-blog migration
<?php
$glob = glob(APPPATH .'migrations/*_*.php');
list($last) = explode('_', basename(end($glob)));
$file = APPPATH.'migrations/'.str_pad($last + 1, 3, '0', STR_PAD_LEFT).'_create_blog_tables.php';
if ( ! file_put_contents($file, $content)
{
throw new Exception('Cannot write migration.');
}
@nerdsrescueme
nerdsrescueme / elements.php
Created September 23, 2011 14:30
HTML elements
<?php
// Block elements
$block = 'article,aside,blockquote,body,br,button,canvas,caption,col,colgroup,dd,div,dl,dt,embed,fieldset,figcaption,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,li,map,object,ol,output,p,pre,progress,section,table,tbody,textarea,tfoot,th,thead,tr,ul,video';
// Inline elements
$inline = 'a,abbr,address,area,audio,b,cite,code,del,details,dfn,command,datalist,em,font,i,iframe,img,input,ins,kbd,label,legend,link,mark,meter,nav,optgroup,option,q,samp,small,small,select,source,span,strong,sub,summary,sup,tbody,td,time,var';
// Children can only be text nodes and should hold their format completely
@nerdsrescueme
nerdsrescueme / html_examples.html
Created September 23, 2011 14:42 — forked from dallas/html_examples.html
HTML elements—like, all of 'em
<!-- Got this from inside the gridz_app files
http://github.com/tschmidt/gridz_app
Other than that, I don't know where it's from, but I like it! -->
<h1>This document shows various HTML elements</h1>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit Lorem ipsum dolor sit amet, volutpat. </p>
<h2>This is 2nd level heading bh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi luptatum zzril delenit Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam no</h2>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. </p>
@nerdsrescueme
nerdsrescueme / regex.txt
Created September 23, 2011 16:08
Common Regex
Perl and PHP Regular Expressions
PHP regexes are based on the PCRE (Perl-Compatible Regular Expressions), so any regexp that works for one should be compatible with the other or any other language that makes use of the PCRE format. Here are some commonly needed regular expressions for both PHP and Perl. Each regex will be in string format and will include delimiters.
All Major Credit Cards
This regular expression will validate all major credit cards: American Express (Amex), Discover, Mastercard, and Visa.
//All major credit cards regex
'/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{12}|622((12[6-9]|1[3-9][0-9])|([2-8][0-9][0-9])|(9(([0-1][0-9])|(2[0-5]))))[0-9]{10}|64[4-9][0-9]{13}|65[0-9]{14}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})*$/'
@nerdsrescueme
nerdsrescueme / base64.php
Created October 3, 2011 19:16
Storage and Encoding
<?php
namespace Atom\Encoder;
use Atom\Encodable;
class Base64 implements Encodable {
public function decode($data)
{
<?php
use \Atom\DB\Connection as Conn;
class DB {
protected $connections = array();
public static function connection($id = 'default', $config = null)
{