Skip to content

Instantly share code, notes, and snippets.

View magnum's full-sized avatar
💭
experimenting...

Antonio Molinari magnum

💭
experimenting...
View GitHub Profile
@magnum
magnum / application_controller.rb
Last active December 17, 2015 21:39
custom error handling in rails, allows to respond with json when exeptions are thrown in api controllers and with standard error handling in all other cases
class ApplicationController < ActionController::Base
protect_from_forgery
# CUSTOM EXCEPTION HANDLING
rescue_from Exception do |e|
error(e)
end
def routing_error
@magnum
magnum / gist:6163775
Last active December 20, 2015 16:48
concatenate filters and and ordering
@categories = Categories.page params[:page]
@categories = @categories.order(params[:order_field] => params[:order_direction) unless params[:order_field].blank? || params[:order_direction].blank?
@categories = @categories.where(:attr1 => params[:p1]) unless params[:p1].blank? # (n times)
describe('fizz buzz',function(){
var self = this;
beforeEach(function(){
var threeChecker = new Checker(3, "Fizz");
var fiveChecker = new Checker(5, "Buzz");
var sevenChecker = new Checker(7, "Bang");
self.fizzBuzzer = new FizzBuzzer([threeChecker, fiveChecker, sevenChecker]);
});
it('Default is say the number',function(){
@magnum
magnum / gist:8713517
Created January 30, 2014 17:07
managing rails ajax calls' timeout /error
$.rails.ajax = (options) ->
if not options.timeout
options.timeout = 10000 # 10 secs of timeout
options.error = (jqXHR, textStatus) ->
alert("Si è verificato un errore: \n"+textStatus.toUpperCase())
community_helper.loading_hide()
return $.ajax(options)
{"order_id":"7000","uid":"53483","order_status":"ordine-spedito","order_total":85,"product_count":1,"primary_email":"dd77@hotmail.it","delivery_first_name":"Daria","delivery_last_name":"Doganieri","delivery_phone":"3393097405","delivery_company":"","delivery_street1":"via Datini 43","delivery_street2":"","delivery_city":"firenze","delivery_zone":"114","delivery_postal_code":"50126","delivery_country":"380","billing_first_name":"Daria","billing_last_name":"Doganieri","billing_phone":"3393097405","billing_company":"","billing_street1":"via Datini 43","billing_street2":"","billing_city":"firenze","billing_zone":"114","billing_postal_code":"50126","billing_country":"380","payment_method":"paypal_wps","data":{"complete_sale":"logged_in"},"created":"1386581572","modified":"1389088155","host":" 188.217.46.249","currency":"EUR","products":[{"nid":"6789","type":"product","language":"","uid":"48","status":"0","created":"1375957564","changed":"1385996049","comment":"0","promote":"0","moderate":"0","sticky":"0","tnid":"0
@magnum
magnum / bootstrap-hover-dropdown.js
Last active August 29, 2015 14:02
laba test drupal
/**
* Project: Bootstrap Hover Dropdown
* Author: Cameron Spear
* Contributors: Mattia Larentis
*
* Dependencies: Bootstrap's Dropdown plugin, jQuery
*
* A simple plugin to enable Bootstrap dropdowns to active on hover and provide a nice user experience.
*
* License: MIT
@magnum
magnum / custom.css
Created June 13, 2014 09:01
custom.css for bootstrap_laba_portfolio drupal theme
body {
}
.front h1, #block-views-works-block h2{
display: none;
}
/* VIEW-WORKS - SLIDESHOW */
#block-views-works-block {

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

AsyncProcess = require('./async-process').AsyncProcess
describe('AsyncProcess', function() {
var asyncProcess;
beforeEach(function() {
asyncProcess = new AsyncProcess();
});
it('should process 42', function() {
@magnum
magnum / gist:49fad030d1050be83d93d056925bf2de
Created May 10, 2016 09:25
qcumber libelium json packet
{
"id": "#ID#",
"id_wasp": "#ID_WASP#",
"id_secret": "#ID_SECRET#",
"sensor": "#SENSOR#",
"value": "#VALUE#",
"datetime": "#TS('c')#"
}