Skip to content

Instantly share code, notes, and snippets.

View frankyston's full-sized avatar
🎯
Ruby on Rails is Fun

Frankyston Lins frankyston

🎯
Ruby on Rails is Fun
View GitHub Profile
@frankyston
frankyston / sum_range.rb
Created December 22, 2021 14:56 — forked from leandronsp/sum_range.rb
Sum all numbers in a consecutive range
require 'benchmark'
def sum_range_using_for_loop(min, max)
range = (min..max)
sum = 0
for n in range
sum = sum + n
end
1. Crie duas variáveis com algum texto e imprima elas fazendo concatenação
2. Crie duas variáveis com algum texto e imprima elas fazendo interpolação
3. Crie uma variável e com essa variável faça uma tabula do valor da variável.
4. Cria as variáveis nome, cidade, estado, rua, número da casa e cep. Imprima essas variáveis como se fosse um endereço completo.
# frozen_string_literal: true
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins ENV['CORS_ORIGINS'].split(',').map { |origin| origin.strip }
resource '*',
headers: :any,
methods: [:get, :post, :put, :patch, :delete, :options, :head]
end
@frankyston
frankyston / rails-jsonb-queries
Created August 16, 2021 01:44 — forked from mankind/rails-jsonb-queries
Ruby on Rails-5 postgresql-9.6 jsonb queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")
# backup
docker run -v [volume]:/volume --rm loomchild/volume-backup backup - > [backupfile.tar.bz2]
# restore
cat [backupfile.tar.bz2] | docker run -i -v [volume2]:/volume --rm loomchild/volume-backup restore -
@frankyston
frankyston / truncate_rails_tables.rb
Created May 27, 2021 17:00 — forked from romanblick/truncate_rails_tables.rb
Truncate all tables in rails
ActiveRecord::Base.establish_connection
ActiveRecord::Base.connection.tables.each do |table|
next if table == 'schema_migrations'
case ActiveRecord::Base.connection.adapter_name.downcase.to_sym
when :mysql2 || :postgresql
ActiveRecord::Base.connection.execute("TRUNCATE #{table}")
when :sqlite
ActiveRecord::Base.connection.execute("DELETE FROM #{table}")
end
@frankyston
frankyston / .a-dotfiles
Created March 27, 2021 19:32 — forked from rachidcalazans/.a-dotfiles
My Dotfiles
My Dotfiles
brew install fzf
brew install xclip
brew install autojump
@frankyston
frankyston / import.js
Created March 22, 2021 11:03
Token Tooltip Alt for FoundryVTT
{
"gmSettings": {
"default": {
"items": [
{
"disposition": "FRIENDLY",
"items": []
},
{
"disposition": "NEUTRAL",
@frankyston
frankyston / rails http status codes
Created December 10, 2020 13:23 — 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
@frankyston
frankyston / pin_animated.js
Created October 30, 2020 20:25
Pin Animated for FoundryVTT
let params =
[{
filterType: "transform",
filterId: "myTransform",
padding: 30,
animated:
{
translationY:
{
animType: "sinOscillation",