Skip to content

Instantly share code, notes, and snippets.

Avatar

Jason Lee huacnlee

View GitHub Profile
View gist:ae71f9cbf74faf283f94b658db538824
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg style="border-radius: 0;" width="324" height="120" viewBox="0 0 324 120" version="1.1" xmlns="http://www.w3.org/2000/svg">
<g>
<defs>
<linearGradient id="avatar" x1="0" y1="0" x2="1" y2="1">
<stop offset="0%" stop-color="#ff6a00"/>
<stop offset="100%" stop-color="#ff6a00"/>
</linearGradient>
</defs>
View pg-user.sql
-- 创建名称为readonly的只读用户:
create user social with password '123456';
-- 然后把在public这个schema下现有的所有表的select权限赋给readobly,并执行下面的SQL命令:
grant select on select tables in schema public to social;
-- 上面的命令只是把现有的表的权限给了readonly用户,如果此时创建了表,readonly用户还是不能读,需要使用下面的SQL把所建表的select权限也给用户readonly:
alter default privileges in schema public grant select on tables to social;
@huacnlee
huacnlee / homeland-gobackup.yml
Created Feb 3, 2020
Gobackup for Homeland config example
View homeland-gobackup.yml
models:
homeland:
compress_with:
type: tgz
encrypt_with:
type: openssl
password: your-archive-password
store_with:
type: oss
bucket: your-backup-bucket-name
View RSpec-to-Minitest.md

RSpec to Minitest

Use Assertions method instead of RSpec expect.

expect to assert_equal

Cases

expect(response.status).to eq 400
@huacnlee
huacnlee / dingtalk-qrcode-login.rb
Last active Oct 16, 2019
实现钉钉扫描登录 Ruby
View dingtalk-qrcode-login.rb
# 实现钉钉扫描登录
#
# 从钉钉 “移动应用接入 - 扫码登录” 开通,并获得 app_id 和 app_secret
# 开通:https://open-dev.dingtalk.com/#/loginMan
#
# 这个流程只能实现简单登录,拿到用户 nick,dingId, openid, unionid
# 文档:https://ding-doc.dingtalk.com/doc#/serverapi2/etaarr
require "openssl"
require "base64"
require "faraday"
View ease-in-out.scss
.ease-in-out {
-webkit-transform: scale(0.8);
transform: scale(0.8);
-webkit-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
@huacnlee
huacnlee / rails-docker-build-speed-up.md
Last active Sep 8, 2020
给 Rails 应用 Docker Image 打包过程增加 cache,依靠 GitLab CI 的 cache 来加速
View rails-docker-build-speed-up.md

.yarnrc

我们需要在 Rails 项目根目录配置 .yarnrc 告诉 Yarn 我们需要将 npm 的包缓存到 vendor/cache/npm 目录。

registry "https://registry.npm.taobao.org"
lastUpdateCheck 1561690751463
yarn-offline-mirror "./vendor/cache/npm"     
yarn-offline-mirror-pruning true
@huacnlee
huacnlee / grant-pg-readonly-user.sql
Last active May 29, 2019
PostgreSQL create readonly user for all database(创建一个 readonly 的用户,并给予对所有表的只读权限)
View grant-pg-readonly-user.sql
-- Create a final user with password
CREATE USER "readonly-user" WITH PASSWORD '123456';
-- 选择一个数据库,后面的权限制定是对单个库有效的
-- Grant access to existing tables
GRANT USAGE ON SCHEMA public TO "readonly-user";
GRANT SELECT ON ALL TABLES IN SCHEMA public TO "readonly-user";
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO "readonly-user";
@huacnlee
huacnlee / config.yml
Created Dec 6, 2018
CircleCI with Ruby 2.5, Rails 5.2, Yarn, Webpacker, Sass, PostgreSQL, Redis, ElasticSearch full example.
View config.yml
version: 2
jobs:
build:
docker:
- image: circleci/ruby:2.5.3-node-browsers
environment:
RAILS_ENV: test
DATABASE_URL: postgres://postgres@127.0.0.1:5432/rails-test
- image: circleci/postgres:9.6
environment:
@huacnlee
huacnlee / gist:f89bbe4b8350ba75435a2160ae5884a9
Created Dec 21, 2016
WordPress Page Template for SSO with Homeland
View gist:f89bbe4b8350ba75435a2160ae5884a9
<?php
// Fork from: https://gist.github.com/adamcapriola/11300529
$sso_secret = 'meow';
$homeland_url = 'http://your-homeland-app.com'; // Note: No trailing slash!
if ( ! is_user_logged_in() ) {
// Preserve sso and sig parameters
$redirect = add_query_arg();
// Change %0A to %0B so it's not stripped out in wp_sanitize_redirect