Skip to content

Instantly share code, notes, and snippets.

@jtadeulopes
jtadeulopes / conditional_spec.rb
Created July 11, 2014 13:21
Conditional hooks
describe Classroom do
subject(:classroom) { Classroom.new }
context "when the children are rowdy" do
before(:each, run: true) do
classroom.throw_pizza_party
end
it "example1", run: :true
it "example2"
@jtadeulopes
jtadeulopes / slack.rb
Created August 14, 2014 01:18
Slack Bot
require 'httparty'
class SlackRuby
include HTTParty
base_uri 'slack.com/api'
def initialize(token)
@token = token
end
@jtadeulopes
jtadeulopes / 0_reuse_code.js
Last active August 29, 2015 14:07
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
# == Schema Information
#
# Table name: categories
#
# id :integer(4) not null, primary key
# name :string(255)
# description :text
# created_at :datetime
# updated_at :datetime
#
Populator.words(5) # gera 5 palavras aleatoriamente e insere um espaço entre elas
Populator.words(1..3) # gera entre uma e três palavras aleatoriamente
Populator.sentences(3) # gera 3 frases
Populator.paragraphs(2) # gera 2 paragrafos
namespace :db do
desc "Popula base de dados"
task :populate => :environment do
require 'populator'
Category.populate 30 do |category|
category.name = Populator.words(1..3).titleize
end
>> require 'populator'
=> []
>> Category.count
=> 0
>> Category.populate(10) { |category| category.name = Populator.words(1..3).titleize }
=> {}
>> Category.count
=> 10
>> Category.first
=> #<Category id: 1, name: "Fuga Debitis Temporibus", created_at: "2009-06-13 14:17:24", updated_at: "2009-06-13 14:17:24">
# Atualiza as informações do banco de dados e os arquivos no servidor de acordo com os styles definidos no model
rake paperclip:refresh CLASS=SeuModel
# Atualiza somente as informações do banco de dados
rake paperclip:refresh:metadata CLASS=SeuModel
# Atualiza somente os arquivos no servidor, seguindo os styles definidos no model
rake paperclip:refresh:thumbnails CLASS=SeuModel
module Web::AdsHelper
def add_picture(form)
link_to_function 'Adicionar outra imagem' do |page|
form.fields_for :pictures, Picture.new, :child_index => 'NEW_RECORD' do |f|
html = render(:partial => 'fields_pictures', :locals => {:f => f})
# caso use prototype, inserir a linha abaixo
# $('pictures').insert({ bottom: "#{ escape_javascript html }".replace(/NEW_RECORD/g, new_picture_id) });
page << %{
var new_picture_id = new Date().getTime()
$('#pictures').after("#{escape_javascript html}".replace(/NEW_RECORD/g, new_picture_id));
# app/models/quina.rb
class Quina
def self.gerar_numeros
resultado = (1..8).map { (1..10).map }
end
end
# app/controllers/quina_controller.rb
class QuinaController < ApplicationController
def index