Skip to content

Instantly share code, notes, and snippets.

Fabio Rehm fgrehm

Block or report user

Report or block fgrehm

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View ajax-handlers.coffee
jQuery ($) ->
$indicator = $('#ajax-indicator')
$message = $indicator.find('span')
$(document).ajaxSend (event, jqXHR, ajaxOptions) ->
msg = if ajaxOptions.type == 'GET' then 'Carregando' else 'Processando'
$message.text("#{msg}...")
$indicator.show()
$(document).ajaxStop -> $indicator.hide()
@fgrehm
fgrehm / gist:4952397
Last active Dec 13, 2015
Removing all installed gems
View gist:4952397
gem list | cut -d" " -f1 | xargs gem uninstall -aIx
gem list | grep -v 'test-unit\|psych\|rdoc\|minitest\|json\|io-console\|bigdecimal\|rake' | cut -d" " -f1 | xargs gem uninstall -aIx
@fgrehm
fgrehm / gist:4489503
Last active Dec 10, 2015
knockout.js + handlebars
View gist:4489503
class HandlebarsTemplateEngine extends ko.templateEngine
renderTemplateSource: (compiledTemplate, bindingContext, options) ->
data = bindingContext.$data
htmlResult = compiledTemplate(data)
ko.utils.parseHtmlFragment(htmlResult)
makeTemplateSource: (template, templateDocument) ->
throw "Could not find a template named: '#{template}'" unless JST[template]
JST[template]
@fgrehm
fgrehm / deploy.rake
Last active Jul 27, 2018 — forked from njvitto/deploy.rake
Rakefile to deploy and rollback to Heroku in two different environments (staging and production) for the same app
View deploy.rake
# Deploy and rollback on Heroku in staging and production
namespace :deploy do
PRODUCTION_APP = 'YOUR_PRODUCTION_APP'
STAGING_APP = 'YOUR_STAGING_APP'
REMOTE = ENV["REMOTE_HOST"] || "git@heroku.com"
def heroku_cmd(cmd)
Bundler.with_clean_env do
sh "heroku #{cmd}"
@fgrehm
fgrehm / gist:4253540
Created Dec 10, 2012
Delete multiple git tags
View gist:4253540
for tag in $(git tag | grep -E 'v0\.([0-5])'); do git tag -d $tag && git push origin :refs/tags/$tag; done
@fgrehm
fgrehm / gist:4251894
Created Dec 10, 2012
Inserts a new element in order
View gist:4251894
$.fn.insertInOrder = (newElement, iterator) ->
$container = $(this)
$siblings = $container.children()
$newElement = $(newElement)
if $siblings.length == 0
$container.append($newElement)
return this
index = _.sortedIndex $siblings, newElement, iterator
@fgrehm
fgrehm / gist:4127812
Created Nov 21, 2012
Backbone.Events.once
View gist:4127812
// Based on
// https://github.com/tbranyen/backbone/blob/70eed5bc9e5d3587bd85e9ff56f8ea99a7f8501d/backbone.js#L130-141
// Bind an event like `on`, but unbind the event following the first trigger.
window.Backbone.Model.prototype.once =
window.Backbone.View.prototype.once =
window.Backbone.Events.once = function (events, callback, context) {
  // Bind the original events.
  this.on(events, callback, context);
@fgrehm
fgrehm / gist:4017563
Created Nov 5, 2012
AJAX helpers for JS specs
View gist:4017563
exports = {}
trueAjax = $.ajax
registry = {}
exports.registerSuccess = (url, result) ->
registry[url] = {success: result}
exports.registerFailure = (url, result) ->
registry[url] = {failure: result}
@fgrehm
fgrehm / gist:3841631
Created Oct 5, 2012
guard-rspec with acceptance and unit tests split up
View gist:3841631
guard 'rspec', :version => 2, :spec_paths => ["spec/models", 'spec/controllers'] do
watch(%r{^spec/(models|controllers).+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { ["spec/controllers", 'spec/models'] }
watch('spec/factories/*.rb') { ["spec/controllers", 'spec/models'] }
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
View gist:3744111
window.validarCnpj = (cnpj) ->
cnpj = cnpj.replace(/\/|\.|-/g,"")
allEqual = /^(.)\1+$/
return if (cnpj.length < 14) || allEqual.test(cnpj)
a = []
b = 0
c = [6,5,4,3,2,9,8,7,6,5,4,3,2]
You can’t perform that action at this time.