Skip to content

Instantly share code, notes, and snippets.

View intel352's full-sized avatar

Jonathan Langevin intel352

View GitHub Profile
@intel352
intel352 / example_usage.sql
Created March 23, 2013 03:11
Generic procedure to rebuild a MySQL Closure table
-- typical adjacent list table (parent/child)
CREATE TABLE `attribute` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`parent_id` bigint(20) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `parent_id_idx` (`parent_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-- typical closure structure
@intel352
intel352 / Capfile
Last active December 13, 2015 20:28
A Capistrano capfile with support for running commands locally. Additionally has a variety of helper commands for various tasks.
require 'open3'
$CR = "\033[0m" # color reset
$red = "\033[1m\033[31m"
$green = "\033[1m\033[32m"
$yellow = "\033[1m\033[33m"
$blue = "\033[1m\033[34m"
ssh_options[:forward_agent] = true
ssh_options[:paranoid] = false
@intel352
intel352 / WidgetFactory.php
Last active September 20, 2019 02:18
Yii => custom WidgetFactory, adds onBeforeCreateWidget, onAfterCreateWidget events. An example of how the custom class can be used has been provided as well, in the process solving a typical Yii issue, regarding how to set the default pagesize for widgets that use dataproviders (due to dataproviders initializing pagination, by which widget pager…
<?php
// components/WidgetFactory.php
/**
* Custom WidgetFactory class
* Provides two new events:
* - onBeforeCreateWidget
* - onAfterCreateWidget
*
@intel352
intel352 / answer_pic.go
Created September 17, 2012 14:45 — forked from tetsuok/answer_pic.go
An answer of the exercise: Slices on a tour of Go
package main
import "code.google.com/p/go-tour/pic"
func Pic(dx, dy int) [][]uint8 {
x := make([]uint8, dx)
y := make([][]uint8, dy)
for n := range y {
y[n] = x
@intel352
intel352 / gist:3223862
Created August 1, 2012 05:04
Some Yii-based code to group contiguous array entries
<?php
class Available extends CQueue {
}
class Booked extends CQueue {
}
class Unavailable extends CQueue {
}
@intel352
intel352 / find.php
Created April 2, 2012 14:56
Remove from relation range and search
<?php
$criteria = new \ext\activedocument\Criteria;
$criteria->addMapPhase('
function(value, keyData, arg) {
if(!value["not_found"]) {
var object = Riak.mapValuesJson(value)[0];
if(object.hasOwnProperty(arg.col) && object[arg.col] instanceof Array) {
if(object[arg.col].indexOf(arg.val) != -1)
return [[value.bucket,value.key]];
}
@intel352
intel352 / TestController.php
Created March 14, 2012 01:06
Example usage of ActiveDocument
<?php
class TestController extends Controller {
public function actionIndex() {
$person = TestPerson::model()->findByAttributes(array('name' => 'Parent'));
if ($person) {
CVarDumper::dump(array('person FROM ACTIVEDOCUMENT' => $person->object->data), 10, true);
CVarDumper::dump(array('person stepchildren LASTNAME ASC (relation criteria)' => array_map(function($c) {
/**
@intel352
intel352 / gist:2029327
Created March 13, 2012 15:07
Suggest solution to search an object's array in Riak, using ActiveDocument + js map function
<?php
use \ext\activedocument\Criteria;
$criteria = new Criteria;
$criteria->addColumnCondition(array('slug'=>$slug));
$category = Category::model()->find($criteria);
$criteria = new Criteria;
$criteria->order='updated ASC';
@intel352
intel352 / gist:1995082
Created March 7, 2012 18:49
Suggest solution to search an object's array in Riak, using ActiveDocument + js map function
<?php
use \ext\activedocument\Criteria;
$criteria = new Criteria;
$criteria->addColumnCondition(array('slug'=>$slug));
$category = Category::model()->find($criteria);
$criteria = new Criteria;
$criteria->order='updated ASC';
@intel352
intel352 / gist:1696924
Created January 29, 2012 03:00
CHtml::hiddenFields
<?php
# In response to: https://www.facebook.com/groups/61355672149/10150626399467150/
$hiddenFields = array('field1'=>'value1', 'field2'=>'value2');
array_map('echo', array_map(array('CHtml', 'hiddenField'), array_keys($hiddenFields), $hiddenFields));
# OR same solution as previous, but with the addition of common html options
$hiddenFields = array('field1'=>'value1', 'field2'=>'value2');