Skip to content

Instantly share code, notes, and snippets.

View kevinke's full-sized avatar

Kevin Ke kevinke

  • Shanghai, China
View GitHub Profile
@kevinke
kevinke / readme.md
Created January 7, 2021 08:16 — forked from HendrikPetertje/readme.md
How to Make your own delivery methods in rails 4.+

Writing your own delivery method in Rails (4.+)

Imagine, you got your rails server and you need to send out a bunch of mails to your recipients. no big deal, but SMTP is just very slow when compared with things like simple HTTP API calls.

I set out a few days to write my own delivery method, but found online sources somewhat lacking, outdated or completely skipping this part of sending mails in rails. So lets start making a simple mail_delivery method that outputs the mail to a file in your project home.

You can change the postman step in this tutorial to match your API, etc. instead.

Cheat Sheet: Simple Authentication in Rails 5 with has_secure_password

The goal of this cheatsheet is to make it easy to add hand-rolled authentication to any rails app in a series of layers.

First the simplest/core layers, then optional layers depending on which features/functionality you want.

Specs
AUTHOR Ira Herman
LANGUAGE/STACK Ruby on Rails Version 4 or 5
@kevinke
kevinke / postgresql-set-id-seq.sql
Created May 30, 2019 07:50 — forked from henriquemenezes/postgresql-set-id-seq.sql
PostgreSQL set Next ID Sequence Value to MAX(id) from Table
-- Get Max ID from table
SELECT MAX(id) FROM table;
-- Get Next ID from table
SELECT nextval('table_id_seq');
-- Set Next ID Value to MAX ID
SELECT setval('table_id_seq', (SELECT MAX(id) FROM table));
@kevinke
kevinke / db.rake
Created September 14, 2018 09:33 — forked from hopsoft/db.rake
Rails rake tasks for dump & restore of PostgreSQL databases
# lib/tasks/db.rake
namespace :db do
desc "Dumps the database to db/APP_NAME.dump"
task :dump => :environment do
cmd = nil
with_config do |app, host, db, user|
cmd = "pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump"
end
puts cmd