Skip to content

Instantly share code, notes, and snippets.

@wicky-andrian
wicky-andrian / regenerate_credentials.md
Created June 30, 2020 06:01 — forked from db0sch/regenerate_credentials.md
How to regenerate the master key for Rails 5.2 credentials

If your master.key has been compromised, you might want to regenerate it.

No key regeneration feature at the moment. We have to do it manually.

  1. Copy content of original credentials rails credentials:show somewhere temporarily.
  2. Remove config/master.key and config/credentials.yml.enc
  3. Run EDITOR=vim rails credentials:edit in the terminal: This command will create a new master.key and credentials.yml.enc if they do not exist.
  4. Paste the original credentials you copied (step 1) in the new credentials file (and save + quit vim)
  5. Add and Commit the file config/credentials.yml.enc
@wicky-andrian
wicky-andrian / backup.rake
Created June 25, 2020 05:09 — forked from rantoniuk/backup.rake
Rake task for backing up MySQL database in Rails projects
namespace :db do desc "Backup project database. Options: DIR=backups RAILS_ENV=production MAX=7"
task :backup => [:environment] do
datestamp = Time.now.strftime("%Y-%m-%d_%H-%M-%S")
base_path = Rails.root
base_path = File.join(base_path, ENV["DIR"] || "backups")
backup_base = File.join(base_path, 'db_backups')
backup_folder = File.join(backup_base, datestamp)
backup_file = File.join(backup_folder, "#{RAILS_ENV}_dump.sql")
FileUtils.mkdir_p(backup_folder)
db_config = ActiveRecord::Base.configurations[RAILS_ENV]
@wicky-andrian
wicky-andrian / Forms.md
Created June 19, 2020 20:04 — forked from jnewman12/Forms.md
Forms, form_for, link_to lesson

Forms, form_for, and link_to


Lesson Objectives

  1. Understand forms and the ways we write them
  2. Understand the difference between form_tag and form_for
  3. Understand link_to and how we can use it to dynamically link our application together
@wicky-andrian
wicky-andrian / ftp.rb
Created November 13, 2018 11:37 — forked from SunDi3yansyah/ftp.rb
Download File on FTP Server with Ruby
# Ref: https://ruby-doc.org/stdlib-2.5.3/libdoc/net/ftp/rdoc/Net/FTP.html
require 'net/ftp'
Net::FTP.open('ftp.gnu.org') do |ftp|
ftp.login
ftp.chdir('gnu/wget')
nlst = ftp.nlst('*.tar.gz')
nlst.map {|file_name| ftp.gettextfile(file_name) }
end
@wicky-andrian
wicky-andrian / Adding 'Forgot Password' to login page.md
Created October 3, 2018 09:07 — forked from wendygwo/Adding 'Forgot Password' to login page.md
How to add 'Forgot password' to a Rails app that's using bcrypt for authentication

Credit:

All the steps below came from watching the Railscast below:

http://railscasts.com/episodes/274-remember-me-reset-password

The steps below assumes that your app already has a user and user authentication set up.

  • Add to app/views/sessions/new.html.erb file
<p><%= link_to 'Forgot password?', new_password_reset_path %></p>
@wicky-andrian
wicky-andrian / LICENCE SUBLIME TEXT
Created September 14, 2018 18:11
Sublime Text 3 Serial key build is 3176
## Sublime Text 3 Serial key build is 3176
> * Added these lines into /etc/hosts
127.0.0.1 www.sublimetext.com
127.0.0.1 license.sublimehq.com
> * Used the license key
----- BEGIN LICENSE -----
@wicky-andrian
wicky-andrian / howto-manually-add-trust-cert-to-rubygems.md
Created July 14, 2018 14:52
Workaround RubyGems' SSL errors on Ruby for Windows (RubyInstaller)

SSL upgrades on rubygems.org and RubyInstaller versions

UPDATE 2016-12-01: Please refer to the official guide instead of this process.

UPDATE 2014-12-21: RubyGems 1.8.30, 2.0.15 and 2.2.3 have been released. It requires manual installation, please see instructions below.


Hello,

  1. Add gem 'rails_12factor' to your Gemfile. This will add error logging and the ability for your app to serve static assets.
  2. bundle
  3. Run RAILS_ENV=production rake db:create db:migrate db:seed
  4. Run rake secret and copy the output
  5. From the command line: export SECRET_KEY_BASE=output-of-rake-secret
  6. To precompile your assets, run rake assets:precompile. This will create a folder public/assets that contains all of your assets.
  7. Run RAILS_ENV=production rails s and you should see your app.

Remember to clobber your assets (rake assets:clobber) and re-precompile (rake assets:precompile) if you make changes.

1xx Informational

Status Code Status Message Symbol
100 Continue :continue
101 Switching Protocols :switching_protocols
102 Processing :processing

2xx Success

Status Code Status Message Symbol