Skip to content

Instantly share code, notes, and snippets.

View Godoy's full-sized avatar

Adriano Godoy Godoy

View GitHub Profile
@Godoy
Godoy / Gemfile
Created January 15, 2013 15:31
Deploy rails application in heroku
group :production do
gem 'thin'
gem 'pg'
end
group :development, :test do
gem 'sqlite3'
end
@Godoy
Godoy / gist:6564097
Created September 14, 2013 17:57
"Re-salvar" todos os registros de determinado model no console do rails (para que executem algum novo before_filter, por exemplo)
News.find_each(&:save)
<script>
(function(t,r,a,c,k) { t[k]=t[k]||function(){ (t[k].q = t[k].q||[]).push(arguments) }
var ts=r.createElement(a);ts.type='text/javascript';ts.async=true;
ts.src=c; var s=r.getElementsByTagName(a)[0];s.parentNode.insertBefore(ts, s); })(window, document,
'script','//rawgit.com/Godoy/776586faf5389d2276aebc179801c0e7/raw/441601291b272a1b5bea191b54e13cce159d7dbf/my_async_plugin.js', 'my_track')
my_track('acessou página');
</script>
<a href="#" onclick="my_track('clicou no link');">Link</a>
@Godoy
Godoy / application.rb
Created September 29, 2016 19:57
ruby on rails - disable automatic generators
module MyAppRails
class Application < Rails::Application
# ...
config.generators.test_framework false
config.generators.javascripts false
config.generators.helper false
config.generators.stylesheets false
end
end
@Godoy
Godoy / image_magick_example.rb
Created July 25, 2016 20:20
Example with image magick - load font, background, caption
def image_generate
# composite compartilhar.png ab.png abc.png
# convert a.png b.png -append ab.png
# composite -font Raleway-Regular.ttf -size 380x200 -gravity east label:Joaquim abc.png abcd.png
file = Tempfile.new(['image1', '.png'])
file.binmode
fileAux = Tempfile.new(['image2', '.png'])
@Godoy
Godoy / main.js
Created May 5, 2016 16:46
jquery mask phone telefone 9 digitos
// https://github.com/igorescobar/jQuery-Mask-Plugin/tree/master/dist
$(function () {
$('.phone').mask(PhoneMaskBehavior, spOptions);
});
var PhoneMaskBehavior = function (val) {
return val.replace(/\D/g, '').length === 11 ? '(00) 00000-0000' : '(00) 0000-00009';
},
spOptions = {
onKeyPress: function (val, e, field, options) {
(function () {
// Pop the call queue...
q = window['my_function'].q;
while(a = q.pop()){
my_real_function(a);
}
//copy the complete function under old that was stacking queue
my_function = my_real_function;
})();
@Godoy
Godoy / my_function-sdk.js
Last active April 25, 2016 16:09
Test load async
function my_function(param) {
console.log("in correct function");
console.log(param);
}
@Godoy
Godoy / analytics.js
Created April 21, 2016 12:59
async load analytics javascript script tag
(function(){
window['GoogleAnalyticsObject'] = 'ga';
window['ga'] =
window['ga']
||
function(){
(window['ga'].q = window['ga'].q || [])
.push(arguments)
},
window['ga'].l = 1 * new Date();
@Godoy
Godoy / _form.html.erb
Created March 8, 2016 13:23
envia formulário ruby on rails via ajax e exibe erros automaticamente com script
<%= form_for(@model, remote: true, html: {role: :form, 'data-model' => 'MODEL_NAME', class: 'send_ajax'}) do |f| %>
<% if @model.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@model.errors.count, "error") %> prohibited this tip from being saved:</h2>
<ul>
<% @model.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>