Skip to content

Instantly share code, notes, and snippets.

View csrui's full-sized avatar
🏠
Working from home

Rui Sardinha csrui

🏠
Working from home
View GitHub Profile
@csrui
csrui / gulpfile.js
Created April 11, 2014 16:27
Generic gulpfile for CakePHP apps. Compiles and minifies sass. Minifies and lints javascript. Generates documentation with yuidoc
var gulp = require('gulp');
// Include Our Plugins
var jshint = require('gulp-jshint');
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var minifyCSS = require('gulp-minify-css');
var rename = require('gulp-rename');
var yuidoc = require("gulp-yuidoc");
@csrui
csrui / jquery.tognsort.js
Created January 22, 2014 12:31
work in progress - Grabs a <select> a replaces it by a clickable ul/li for better formatting
(function( $ ) {
var $main_select = {};
$.fn.tognsort = function( options ) {
var options = $.extend({}, $.fn.tognsort.defaults, options );
$main_select = this;
@csrui
csrui / unirest_oauth.js
Created January 14, 2014 10:42
OAuth requests with library Unirest.io
var Request = unirest.get('https://api.twitter.com/oauth/request_token');
Request.oauth({
callback: 'http://mysite.com/callback/'
, consumer_key: 'CONSUMER_KEY'
, consumer_secret: 'CONSUMER_SECRET'
}).end(function (response) {
var access_token = response.body;
Request = unirest.post('https://api.twitter.com/oauth/access_token');
@csrui
csrui / LanguageComponent.php
Created January 8, 2014 11:37
Handle language changing in CakePHP
<?php
App::uses('Component', 'Controller');
class LanguageComponent extends Component {
public function initialize(Controller $controller) {
$this->autoSelectLanguage($controller);
@csrui
csrui / BootstrapFormHelper.php
Created January 8, 2014 11:20
Formats CakePHP form elements with Bootstrap classes
<?php
/**
* Formats form elements for Bootstrap v3
*
* Add to AppController.php
*
* public $helpers = array(
* 'Form' => array('className' => 'BootstrapForm')
* );
@csrui
csrui / AppModel.php
Created December 27, 2013 18:13
Get CakePHP last model's query
public function getLastQuery() {
$dbo = $this->getDatasource();
$logs = $dbo->getLog();
$lastLog = end($logs['log']);
return $lastLog['query'];
}
@csrui
csrui / UserShell.php
Last active December 21, 2015 08:39
CakePHP - Shell to reset / create a default admin user
<?php
/**
* Shell to reset / create a default admin user
*
* @source https://gist.github.com/csrui/6279811
* @url http://book.cakephp.org/2.0/en/console-and-shells.html
**/
class UserShell extends AppShell {
public $uses = array('User');
@csrui
csrui / MetaBehavior.php
Created August 15, 2013 12:24
CakePHP - Lib to handle extra fields and store them on a json object
<?php
/**
* MetaBehavior handles a set of fields like meta information for a given model row
*
* @source https://gist.github.com/csrui/6240411
* @url http://book.cakephp.org/2.0/en/Models/behaviors.html
**/
class MetaBehavior extends ModelBehavior {
public $settings = array();
@csrui
csrui / GeoBehavior.php
Last active December 20, 2015 18:09
CakePHP - Lib to handle spatial data
<?php
/**
* GeoBehavior handles a set of operations generaly needed when working with coordinates
*
* @source https://gist.github.com/csrui/6173911
* @url http://book.cakephp.org/2.0/en/Models/behaviors.html
**/
class GeoBehavior extends ModelBehavior {
public $settings = array();
@csrui
csrui / typeahead-extended.js
Created August 7, 2013 10:46
Twitter Bootstrap customizations
/*
Extended Bootstrap Typeahead
Based on an answer on stackexchange.com
http://stackoverflow.com/a/14959406/1065537
*/
/* Enhances the autocomplete function */
$('.autocomplete').typeahead({
source: function (query, process) {
return $.ajax({