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 / 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
@kevinke
kevinke / pg_dump_restore.sql
Last active November 22, 2018 03:19
PG Dump and Restore
pg_dump -F c -v -O -c --if-exists -C -U 'root' -h '139.198.176.101' -p '15432' -d 'qingcloud' -f 'pr_pro_db_test.dump'
dump related param
-f [file path]: send output to the specified file
-F [format]: c is for custom format
-v: verbose
@kevinke
kevinke / zhparser.sql
Created December 26, 2018 08:17
zhparser config sql
CREATE EXTENSION zhparser;
CREATE TEXT SEARCH CONFIGURATION zhcnsearch (PARSER = zhparser);
ALTER TEXT SEARCH CONFIGURATION zhcnsearch ADD MAPPING FOR n,v,a,i,e,l,j WITH simple;
@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));

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 / 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.