Skip to content

Instantly share code, notes, and snippets.

View recidive's full-sized avatar

Henrique Recidive recidive

View GitHub Profile
<?php
/**
* Implements hook_ctools_plugin_post_alter().
*/
function deploy_plan_ctools_plugin_post_alter(&$plugin, &$info) {
if (!empty($plugin['schema']) && $plugin['schema'] == 'deploy_plans') {
$plugin['export']['save callback'] = 'deploy_plan_save_plan_entity';
}
}
@recidive
recidive / util.scan.js
Created April 2, 2013 14:15
A JavaScript/Node.js utility function to recurse a directory returning all files that ends with a suffix as a single dimensional array. Uses async library.
util.scan = function(dir, suffix, callback) {
fs.readdir(dir, function(err, files) {
var returnFiles = [];
async.each(files, function(file, next) {
var filePath = dir + '/' + file;
fs.stat(filePath, function(err, stat) {
if (err) {
return next(err);
}
if (stat.isDirectory()) {

Bring structure to Node.js applications with Prana

Prana is an innovative microframework created by Henrique Recidive that combines an ODM system with an extensions/plugins system to provide a robust and flexible base for creating applications and frameworks of any kind.

Prana has a highly dynamic unified API for interacting with resources, so you can manipulate everything in your application being it settings, application metadata or user submitted content.

By creating a new type in Prana it automatically creates and return a model object that you can use and interact with it right away.

// Create the application.
@recidive
recidive / gist:8612205
Created January 25, 2014 05:22
Random string in nodejs.
var string = require('crypto').randomBytes(32).toString('base64').replace(/[^a-z0-9]/gi, '').substr(0, 32);
@recidive
recidive / gist:8742027
Created January 31, 2014 20:10
Generate JSON files for pages in page() hook.
var objectType = 'page';
for (var i in newPages) {
var newObject = newPages[i];
if (!newObject.callback) {
require('fs').writeFileSync(require('path').join(__dirname, '/' + i + '.' + objectType + '.json'), JSON.stringify(newObject, null, ' '), {flag: 'w'});
}
}
@recidive
recidive / gist:8793283
Created February 3, 2014 21:58
Exporting hook resources to JSON files in Choko.
var objectType = 'navigation';
var newObjects = newNavigations;
for (var i in newObjects) {
var newObject = newObjects[i];
require('fs').writeFileSync(require('path').join(__dirname, '/' + i + '.' + objectType + '.json'), JSON.stringify(newObject, null, ' '), {flag: 'w'});
}
@recidive
recidive / gist:8849235
Created February 6, 2014 17:54
Button group with multiple dropdowns.
<div class="btn-group">
<button type="button" class="btn btn-default">First Normal</button>
<button type="button" class="btn btn-default">Second Normal</button>
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
Third Dropdown
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
@recidive
recidive / gist:8849303
Created February 6, 2014 17:57
Button group with multiple dropdowns model.
$scope.buttons = [
{
"type": "normal",
"title": "First normal"
},
{
"type": "normal",
"title": "Second normal"
},
{
myApp.controller('ListController', function($scope, $route, $location, $http, Categories){
$scope.category = 'categoria-1';
$scope.subCategory = 'sub-categoria-1';
$scope.setCategory = function(category) {
$scope.category = category.name;
};
$scope.setSubCategory = function(category) {
$scope.subCategory = subCategory.name;
<?php
function custom_delete_all_orders() {
// Delete orders.
$order_ids = db_query('SELECT order_id FROM {commerce_order}')->fetchCol();
commerce_order_delete_multiple($order_ids);
unset($order_ids);
// Delete line items.
$line_item_ids = db_query('SELECT line_item_id FROM {commerce_line_item}')->fetchCol();