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
@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 / 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 / controller_macros.rb
Created September 16, 2020 19:12 — forked from saboyutaka/controller_macros.rb
Rspec spec/support files.
module ControllerMacros
def login_user
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:user]
user = FactoryGirl.create(:user)
user.confirm!
sign_in user
end
end
end
@frankyston
frankyston / smtp_login_auth.go
Created September 13, 2020 14:49 — forked from andelf/smtp_login_auth.go
golang net/smtp SMTP AUTH LOGIN Auth Handler
// MIT license (c) andelf 2013
import (
"net/smtp"
"errors"
)
type loginAuth struct {
username, password string
@frankyston
frankyston / README.md
Created July 2, 2020 21:08 — forked from roachhd/README.md
EMOJI cheatsheet ๐Ÿ˜›๐Ÿ˜ณ๐Ÿ˜—๐Ÿ˜“๐Ÿ™‰๐Ÿ˜ธ๐Ÿ™ˆ๐Ÿ™Š๐Ÿ˜ฝ๐Ÿ’€๐Ÿ’ข๐Ÿ’ฅโœจ๐Ÿ’๐Ÿ‘ซ๐Ÿ‘„๐Ÿ‘ƒ๐Ÿ‘€๐Ÿ‘›๐Ÿ‘›๐Ÿ—ผ๐Ÿ”ฎ๐Ÿ”ฎ๐ŸŽ„๐ŸŽ…๐Ÿ‘ป

EMOJI CHEAT SHEET

Emoji emoticons listed on this page are supported on Campfire, GitHub, Basecamp, Redbooth, Trac, Flowdock, Sprint.ly, Kandan, Textbox.io, Kippt, Redmine, JabbR, Trello, Hall, plug.dj, Qiita, Zendesk, Ruby China, Grove, Idobata, NodeBB Forums, Slack, Streamup, OrganisedMinds, Hackpad, Cryptbin, Kato, Reportedly, Cheerful Ghost, IRCCloud, Dashcube, MyVideoGameList, Subrosa, Sococo, Quip, And Bang, Bonusly, Discourse, Ello, and Twemoji Awesome. However some of the emoji codes are not super easy to remember, so here is a little cheat sheet. โœˆ Got flash enabled? Click the emoji code and it will be copied to your clipboard.

People

:bowtie: ๐Ÿ˜„