Skip to content

Instantly share code, notes, and snippets.

@fgrehm
fgrehm / en.yml
Last active December 16, 2015 10:49 — forked from leemeichin/url_validator.rb
en:
activemodel:
errors:
messages:
invalid_url: "must be a valid URL"
@fgrehm
fgrehm / cocoon-chosen.coffee
Created February 19, 2013 18:15
Cocoon + Chosen
jQuery ($) ->
$('.add_fields').each ->
$this = $(this)
insertionNode = $this.data('association-insertion-node')
insertionTraversal = $this.data('association-insertion-traversal')
if (insertionNode)
if (insertionTraversal)
insertionNode = $this[insertionTraversal](insertionNode)
else
@fgrehm
fgrehm / ajax-handlers.coffee
Created February 19, 2013 15:48
Global ajax handlers
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 December 13, 2015 17:59
Removing all installed gems
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 November 30, 2020 16:25
knockout.js + handlebars
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 July 27, 2018 23:31 — forked from njvitto/deploy.rake
Rakefile to deploy and rollback to Heroku in two different environments (staging and production) for the same app
# 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 December 10, 2012 21:23
Delete multiple git tags
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 December 10, 2012 17:11
Inserts a new element in order
$.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 November 21, 2012 21:20
Backbone.Events.once
// 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 November 5, 2012 14:55
AJAX helpers for JS specs
exports = {}
trueAjax = $.ajax
registry = {}
exports.registerSuccess = (url, result) ->
registry[url] = {success: result}
exports.registerFailure = (url, result) ->
registry[url] = {failure: result}