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 / 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({
@csrui
csrui / planamatch-widget-calendar.html
Last active December 18, 2015 10:19
Planamatch events calendar widget
<div class="pm-widget-calendar"></div>
<script>
var pm_widget_calendar = {
limit : 10,
user_id : 1,
include_location : false
};
</script>
<script src="http://cdn.planamatch.com/js/pm.calendar.widget.min.js"></script>
@csrui
csrui / post-receive
Created March 20, 2012 20:29
Git - Post receive hook
#!/bin/sh
cd ..
GIT_DIR='.git'
umask 002 && git reset --hard
# Set 'receive.denyCurrentBranch' configuration variable to 'ignore' or 'warn' in the remote repository to allow pushing into
# chmod +x .git/hooks/post-receive