Skip to content

Instantly share code, notes, and snippets.

@eduardordm
eduardordm / gist:4691440
Created February 1, 2013 13:56
zurb form helper errors
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
unless html_tag =~ /^<label/
errors = Array(instance.error_message).join(',')
%(<div class="error">#{html_tag}<small class="error">&nbsp;#{errors}</small></div>).html_safe
else
%(<div class="error">#{html_tag}</div>).html_safe
end
end
@eduardordm
eduardordm / cached.js
Created February 22, 2013 19:23
AngularJS ephemeral caching. Consider a list of links containing which represent folders. Just like an email client, the user will browser between folders. ng-clicks will trigger switchFolder
$scope.switchFolder = function(attrs) {
// Results found on the last query will be available instantly (if any)
// you could also add a Message.is_query_cached to check if there are cached results
$scope.messages = Message.query_cached({ id: attr.some_id});
// Lets find the actual results, which can take longer
var messages = Message.query({ id: attr.some_id}, function () {
$scope.messages = message;
});
$scope.doStuff = function(attrs) {
if($rootScope.stuffLocked) {
return;
}
$rootScope.stuffLocked = true;
// load stuff, etc
$rootScope.stuffLocked = false;
@eduardordm
eduardordm / currentquery.txt
Created March 15, 2013 19:37
Traces for Arel (oracle.rb)
SELECT * FROM (
SELECT raw_sql_.*, rownum raw_rnum_
FROM (SELECT "LANCAMENTOS".* FROM "LANCAMENTOS" ) raw_sql_
)
WHERE raw_rnum_ between 1 and 30
----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------
'use strict';
portalServidorApp.controller('UnidadeController', ['$scope', 'resolvedUnidade', 'Unidade',
function ($scope, resolvedUnidade, Unidade) {
$scope.unidades = resolvedUnidade;
$scope.create = function () {
Unidade.save($scope.unidade,
function () {
@eduardordm
eduardordm / gist:291cd48e677beb1ded29
Created September 19, 2014 04:18
Lines of code between two commits
Replace the SHAs and author with your own.
git log --numstat --pretty="%H" --author="eduardo.a20" 8e03890e494a25e7706c80c38e89858c887d436d..052ff1202e0326c9588531d234b30269bd8056f8 | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d, -%d\n", plus, minus)}'