Skip to content

Instantly share code, notes, and snippets.

View huacnlee's full-sized avatar

Jason Lee huacnlee

View GitHub Profile
@huacnlee
huacnlee / rails-docker-build-speed-up.md
Last active September 8, 2020 05:15
给 Rails 应用 Docker Image 打包过程增加 cache,依靠 GitLab CI 的 cache 来加速

.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 07:34
PostgreSQL create readonly user for all database(创建一个 readonly 的用户,并给予对所有表的只读权限)
-- 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 December 6, 2018 06:07
CircleCI with Ruby 2.5, Rails 5.2, Yarn, Webpacker, Sass, PostgreSQL, Redis, ElasticSearch full example.
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 December 21, 2016 06:55
WordPress Page Template for SSO with Homeland
<?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
<gpx creator="Xcode" version="1.1">
<wpt lat="37.799" lon="-122.4715">
<name>PokemonLocation</name>
</wpt>
</gpx>
@huacnlee
huacnlee / ruby-thread-pool.rb
Created May 16, 2016 09:54
Ruby parallel run slow commands with Thread pool
# gem 'thread'
require 'thread/pool'
pool = Thread.pool(20)
total = 10000
total.times do |i|
pool.process do
stdout = ""
stdout << "\n"
stdout << "Queue #{i}/#{total}"
wget http://dianjihe-files.oss-cn-beijing.aliyuncs.com/sdk-1.0.0-SNAPSHOT-jar-with-dependencies.jar
if [ `uname` = "Darwin" ]; then
sudo mv sdk-1.0.0-SNAPSHOT-jar-with-dependencies.jar /Library/Java/Extensions/
else
sudo mv sdk-1.0.0-SNAPSHOT-jar-with-dependencies.jar /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/ext
fi
@huacnlee
huacnlee / bootbox.rails.js
Last active November 13, 2018 11:37
Custom confirmation dialog in Rails
// Override jquery_ujs data-confirm
// use bootbox.confirm instead of window.confirm
// https://gist.github.com/huacnlee/84d13ea64cc8ccb2d4b0
$.rails.allowAction = function(element) {
var message = element.attr('data-confirm');
if (!message) { return true; }
var opts = {
title: "确认提交",
message: message,
nohup ssh -n -N -D 0.0.0.0:7002 -p 22 ruby@127.0.0.1 2>&1 &
@huacnlee
huacnlee / upgrade-gcc-4.9.sh
Created January 12, 2016 07:05
Upgrade GCC 4.9 on Ubuntu Server
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.9 g++-4.9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9