Skip to content

Instantly share code, notes, and snippets.

@ismarsantos
ismarsantos / cpf.rb
Created October 26, 2020 18:31
gerador de cpf em ruby
# Gerador de CPF em ruby
# Henrique Breim 27/01/2015
# Total de cpfs que podem existir e passando em um while
inicio = Time.now
999999999.times do |ar|
# Criando o valor para somatoria
valor = 0
total = 0
@ismarsantos
ismarsantos / Gemfile
Created March 10, 2021 16:41 — forked from brianpattison/Gemfile
Rails Livereload
source "https://rubygems.org"
ruby "2.2.2"
gem "rails", "4.2.0"
group :development do
gem "foreman"
gem "guard-livereload", require: false
gem "rack-livereload"
end
@ismarsantos
ismarsantos / customize_error.rb
Created April 12, 2021 13:44 — forked from telwell/customize_error.rb
Customize Field Errors with Rails 5 and Bootstrap
# Adapted from https://rubyplus.com/articles/3401-Customize-Field-Error-in-Rails-5
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
html = ''
form_fields = [
'textarea',
'input',
'select'
]
@ismarsantos
ismarsantos / rails http status codes
Created May 12, 2021 12:29 — forked from mlanett/rails http status codes
HTTP status code symbols for Rails
HTTP status code symbols for Rails
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings.
Status Code Symbol
1xx Informational
100 :continue
101 :switching_protocols
102 :processing
@ismarsantos
ismarsantos / 20190626011110_add_jti_to_users.rb
Last active May 21, 2021 00:25
Rails: example how to user change_column_null
# db/migrations/20190626011110_add_jti_to_users
class AddJtiToUsers < ActiveRecord::Migration[6.1]
def change
add_column :users, :jti, :string
# populate jti so we can make it not nullable
User.all.each do |user|
user.update_column(:jti, SecureRandom.uuid)
end
@ismarsantos
ismarsantos / curl.sh
Created May 25, 2021 00:28 — forked from vishalzambre/curl.sh
Using devise gem sign_in & sign_out API's with sessions
#login
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d ' {"user":{"email":"<email>","password":"<passwd>"}}' http://localhost:3000/api/v1/sign_in.json
#logout
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X DELETE http://localhost:3000/api/v1/sign_out.json?auth_token=<token>
@ismarsantos
ismarsantos / estimate.rb
Created June 21, 2021 02:11 — forked from micahroberson/estimate.rb
Generate and save a pdf to S3 with wicked_pdf and paperclip
# Main reference was lascarides' post at http://stackoverflow.com/questions/14743447/getting-pdf-from-wickedpdf-for-attachment-via-carrierwave
# estimate.rb
# ...
has_attached_file :pdf,
storage: :s3,
s3_credentials: {
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
bucket: ENV['AWS_BUCKET']
@ismarsantos
ismarsantos / _flash.html.erb
Created August 9, 2021 02:16 — forked from pawelztef/_flash.html.erb
rails flash messages with bootstrap 4
<div class="container">
<% flash.each do |type, msg| %>
<div class="alert <%= bootstrap_class_for_flash(type) %> alert-dismissable fade show">
<%= msg %>
<button class="close" data-dismiss="alert">x</button>
</div>
<% end %>
</div>
@ismarsantos
ismarsantos / launch.json
Created August 9, 2021 23:12 — forked from drejohnson/launch.json
webpack-dev-server integration with vscode and typescript for react
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Debug",
@ismarsantos
ismarsantos / launch.json
Created August 9, 2021 23:14 — forked from mohamedmansour/launch.json
webpack-dev-server integration with vscode and typescript for react
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Debug",