Skip to content

Instantly share code, notes, and snippets.

@zernel
zernel / routes
Created October 24, 2012 03:12
Devise disable signup
devise_for :users, :skip => [:registrations]
as :user do
get 'users/edit' => 'devise/registrations#edit', :as => 'edit_user_registration'
put 'users' => 'devise/registrations#update', :as => 'user_registration'
end
# And then modify the app/views/devise/shared/_links.erb
@zernel
zernel / phone_regex.csv
Created December 29, 2022 03:45
主要国家地区电话号码的格式
areaName checkKey countryCode phoneCode
中国大陆 ^(86){0,1}1\\d{10}$ CN 86
中国香港 ^(00){0,1}(852){1}0{0,1}[1,5,6,9,4](?:\\d{7}|\\d{8}|\\d{12})$ HK 852
中国澳门 ^(00){0,1}(853){1}6\\d{7}$ MO 853
中国台湾 ^(00){0,1}(886){1}0{0,1}[6,7,9](?:\\d{7}|\\d{8}|\\d{10})$ TW 886
韩国 ^(00){0,1}(82){1}0{0,1}[7,1](?:\\d{8}|\\d{9})$ KR 82
日本 ^(00){0,1}(81){1}0{0,1}[7,8,9](?:\\d{8}|\\d{9})$ JP 81
美国 ^(00){0,1}(1){1}\\d{10,12}$ US 1
加拿大 ^(00){0,1}(1){1}\\d{10}$ CA 1
英国 ^(00){0,1}(44){1}[347-9](\\d{8,9}|\\d{11,12})$ GB 44
# Why do we need KudeURI? Because the URI.join method doing something stupid:
#
# URI.join('http://example.com/subpath', 'hello', '?token=secret')
# => “http://example.com/hello?token=secret”
#
# But what I expected is “http://example.com/subpath/hello?token=secret", the subpath is gone.
# By using SmartURI, you can handle the case above gracefully:
#
# SmartURI.join('http://example.com/subpath', 'hello', query: { token: secret })
# => "http://example.com/subpath/hello?token=secret"
# Idea taken from https://gist.github.com/jackcarter/d86808449f0d95060a40
# This script requires python lib: requests
# You can install by: `python -m pip install requests`
import time
import codecs
import requests
reader = codecs.getreader("utf-8")
@zernel
zernel / psql-with-gzip-cheatsheet.sh
Created August 18, 2018 03:00 — forked from brock/psql-with-gzip-cheatsheet.sh
Exporting and Importing Postgres Databases using gzip
# This is just a cheat sheet:
# On production
sudo -u postgres pg_dump database | gzip -9 > database.sql.gz
# On local
scp -C production:~/database.sql.gz
dropdb database && createdb database
gunzip < database.sql.gz | psql database
@zernel
zernel / rails-puma.conf
Last active July 3, 2018 08:23
Nginx Conf
upstream my_app {
# server unix:///apps/my_app/tmp/sockets/puma.sock fail_timeout=0;
server unix:///apps/my_app/tmp/sockets/puma.sock fail_timeout=0;
}
server {
listen 80;
server_name my_appms.example.com;
root /apps/my_app/public;
@zernel
zernel / install.sh
Last active March 6, 2018 05:52 — forked from chuyik/install.sh
Bandwagon(搬瓦工) CentOS 7 安装 shadowsocks-libev 和 kcptun
######################
## shadowsocks-libev
######################
# install dependencies
yum install epel-release -y
yum install gcc gettext autoconf libtool automake make pcre-devel asciidoc xmlto udns-devel libev-devel -y
# install shadowsocks-libev
cd /etc/yum.repos.d/
@zernel
zernel / Caddyfile
Created November 18, 2017 01:35 — forked from bendo01/Caddyfile
Caddy Web Server As Service on Centos 7
#cd /etc/caddy/Caddyfile
example.com {
root /usr/share/nginx/html
gzip
log /var/log/caddy/access.log
#fastcgi / unix:/var/run/php-fpm/php-fpm.sock php # Fast CGI php interpreter
#fastcgi / fastcgi / 127.0.0.1:9000 php # Fast CGI php interpreter
#using with laravel
fastcgi / unix:/var/run/php-fpm/php-fpm.sock php {
index index.php
@zernel
zernel / Caddyfile
Created November 17, 2017 09:21
Rails Deployment (Puma + Nginx/Cathy)
https://domain {
gzip
root /apps/app/public
log dev.access.log
proxy / unix:///apps/app/tmp/sockets/puma.sock {
fail_timeout 300s
transparent
header_upstream X-Forwarded-Ssl on
except /assets /fonts /robots.txt /favicon.ico /404.html /422.html /500.html
@zernel
zernel / Gemfile
Created August 24, 2012 01:45
Devise authentication with multiple provider
gem 'devise'
gem 'omniauth'
gem 'omniauth-github'
gem "omniauth-twitter"
gem "omniauth-facebook"
gem "omniauth-google-oauth2"