Skip to content

Instantly share code, notes, and snippets.

var Body = Item.extend({
// Set background pattern
constructor: function() {
// Set default image
this.set('pattern',1);
},
changeCollarColour: function(colour) {
this.set('collarColour', colour);
}
});
<?php
function sanitize ( $key ) {
$raw_key = $key;
$key = preg_replace( '/[^a-z0-9_\-]/', '', $raw_key );
return $key;
}
$my_var = ‘My_String_here’;
<?php
/**
* What is this function doing?
*/
function output_data(Array $data, $type = 'json')
{
if ( is_array($data) ) {
switch($type) {
<?php
$test = new Shop_Product();
$test->join('shop_products_categories', 'shop_products.id = shop_products_categories.shop_product_id');
$test->join('shop_order_items', 'shop_products.id = shop_order_items.shop_product_id');
$test = $test->where('shop_products_categories.shop_category_id=? ) GROUP BY (shop_products.id',1)->order('count(shop_order_items.id) DESC')->limit(3)->find_all();
foreach ( $test as $t ) {
echo "<br/>".$t->name."</br>";
}
?>
<div class="entry">
<h3>&#9658; Upcoming events</h3>
<?php
$upcoming = new WP_Query(array(
'post_type' => 'event',
'posts_per_page' => -1
));
while( $upcoming->have_posts() ):
$upcoming->the_post();
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'customer-address',
'enableAjaxValidation' => true,
'enableClientValidation' => true,
'focus' => array($model, 'description'),
'method' => 'post',
'action' => $this->createUrl('CustomerApi/Addresses',array('id'=>$customerId)),
'htmlOptions' => array(
'class'=>'form uniformForm',
SELECT
id, name, longitude, latitude
(
3959 * acos(
cos(radians(1.382679))
* cos(radians(latitude))
* cos(radians(longitude) - radians(16.523438))
+ sin( radians(1.382679) )
* sin( radians(latitude))
)
@caddoo
caddoo / gist:4566113
Created January 18, 2013 17:02
Sample code for RMA request form
<form action="#">
<input type="hidden" name="complete_url" value="<?= site_url('rma-complete') ?>" />
<div class="checkout-block">
<div class="fieldset">
<div class="field-group">
<div class="field">
<label for="tdrma_rma_first_name">First name <span class="req">*</span></label>
<input name="tdrma_rma_first_name" id="tdrma_rma_first_name" type="text">
</div>
@caddoo
caddoo / gist:3987996
Created October 31, 2012 16:18
Soft Delete
<?php
/**
* Modify normal delete behaviour so that deletes are handled depending
* on if they have a column called 'deleted' or not
* Cascade deletes all HAS_MANY relations as well
*
* @access public
* @return boolean
*/
public function beforeDelete()
window.MenuSections = Backbone.Collection.extend({
model: MenuSection,
url: 'index.php?r=MenuApi/Get',
// Search used for live searching
search: function(letters) {
var pattern = new RegExp(letters,"gi");
var that = this;
this.each(function(data,i){
// Loop all the items looking for the match
// If there isn't a match we don't want the section displayed