Skip to content

Instantly share code, notes, and snippets.

View speedmax's full-sized avatar

Taylor luk speedmax

View GitHub Profile
@speedmax
speedmax / spec.php
Created October 3, 2008 08:55
SimpleSpec - SimpleTest extension for Behavior driven development(BDD)
<?php
require_once 'spec_helper.php';
class Describe_local_variable extends SimpleSpec {
function should_retrive_variable_using_array_interface() {
$c = create_context(array(
'name' => 'peter',
'hobbies' => array('football', 'basket ball', 'swimming'),
'location' => array(
@speedmax
speedmax / application.rb
Created October 8, 2008 11:29
cname lookup
class ApplicationController < ActionController::Base
before_filter :load_site
private
def load_site
if request.host =~ Site.domain_pattern
subdomain = current_subdomain
else
subdomain = find_cname(request.host)
end
<?php
function strip_regex($regex, $delimiter = '/') {
return substr($regex, 1, strrpos($regex, $delimiter)-1);
}
class H2O_RE {
static $whitespace, $seperator, $parentheses, $pipe, $name, $filter_end,
$string, $i18n_string, $number, $operator, $named_args;
function init() {
class Profile < ActiveRecord:Base
# Controller pass request object as param
# Stat wrapper sends out async request to web services
def register_pageview(request)
api = "asdf2134asfd2134"
@stat = SimpleStat.new(api, request)
end
# pageviews most likely to be cached
<?php
class Describe_context_lookup extends SimpleSpec {
function prepare() {
$this->context = create_context(array(
'location' => (object) array(
'address' => '1st Jones St',
'city' => 'Marry hill', 'state' => 'NSW',
'postcode' => 2320
),
'document' => new Document(
<?php
/**
* Min
* ========================
* A lightweight framework to provide convient wrappers for PHP to improve
* grammers when programming
*
* @author Taylor luk
*/
// Option 1, flat tags
$page['tags'] = array('soccer', 'cricket betting', 'football');
// get keyword
<meta type="keyword" content="{{ page.tags|join }}"/>
// get list of tag links
{% for tag in page.tags %}
<a href="{{ tag|tag_url }} ">{{ tag }}</a>
{% endfor %}
<?php
h2o::addTag('load_sports_events');
class Load_sports_events_Tag extends H2o_Node {
function render($context, $stream) {
$cache = h2o_cache($context->options);
$cache_key = 'digg_xml_feed';
# try cached
if (! ($feed = $cache->read($cache_key))) {
$feed = file_get_contents('http://feeds.digg.com/digg/popular.rss');
@speedmax
speedmax / h2o works well.html
Created November 26, 2008 09:22
Beautiful template and data API
<div class="good-evans span-8 last" style="float:right">
{{ '/img/goodevans.png'|image_tag }}
<ul>
{% for article in site.articles_tagged.good-evans %}
<li>{{ article.title | links_to article.url }}</li>
{% endfor %}
</ul>
</div>
<div class="latest-buzz span-10">
>> Product.find :all, :conditions => ["title LIKE ?", "c%"]
=> [#<Product id: 339768653, title: "Canon EOS 40D 10.1MP Digital SLR Camera", description: "This is an H1\r\n=============\r\n\r\n\r\n\r\nBuilding on the...", price: 1199.0, created_at: "2008-06-05 23:50:39", updated_at: "2008-09-05 12:31:06", quantity: 70, brand_id: 528229938, product_type_id: 985430838, price_min: #<BigDecimal:2483b98,'0.1199E4',4(8)>, price_max: #<BigDecimal:2483b5c,'0.1899E4',4(8)>, handle: "canon-eos-40d-101mp-digital-slr-camera", description_html: "<h1>This is an H1</h1>\n\n<p>Building on the success ...", filter: "markdown_filter">, #<Product id: 1024741415, title: "Casio Exilim EX-S10", description: "Casio has its finger in more pies than Billy Bunter...", price: 249.0, created_at: "2008-06-05 23:50:39", updated_at: "2008-06-05 23:50:39", quantity: 50, brand_id: 528229938, product_type_id: 425291712, price_min: #<BigDecimal:2483634,'0.249E3',4(8)>, price_max: #<BigDecimal:24835f8,'0.249E3',4(8)>, handle: "casio-exilim-ex-s1