Skip to content

Instantly share code, notes, and snippets.

View FrankFang's full-sized avatar
🎯
Focusing

Frank Fang FrankFang

🎯
Focusing
View GitHub Profile
@FrankFang
FrankFang / Docker
Created June 22, 2020 08:52 — forked from AhianZhang/Docker
Windows Docker ToolBox使用阿里云加速
对于已创建的Docker Machine实例,更换镜像源的方法如下
在windows命令行执行docker-machine ssh [machine-name]进入VM bash
sudo vi /var/lib/boot2docker/profile
在--label provider=virtualbox的下一行添加--registry-mirror https://xxxxxxxx.mirror.aliyuncs.com
重启docker服务:
sudo /etc/init.d/docker restart
或者重启VM:exit退出VM bash,在windows命令行中执行docker-machine restart
## 如果是新建Docker Machine实例,参考阿里云的操作文档https://cr.console.aliyun.com/#/accelerator
@FrankFang
FrankFang / npm.taobao.sh
Created April 26, 2020 16:38 — forked from nyaapass/npm.taobao.sh
npm 淘宝镜像配置
npm set registry https://registry.npm.taobao.org # 注册模块镜像
npm set disturl https://npm.taobao.org/dist # node-gyp 编译依赖的 node 源码镜像
## 以下选择添加
npm set chromedriver_cdnurl http://cdn.npm.taobao.org/dist/chromedriver # chromedriver 二进制包镜像
npm set operadriver_cdnurl http://cdn.npm.taobao.org/dist/operadriver # operadriver 二进制包镜像
npm set phantomjs_cdnurl http://cdn.npm.taobao.org/dist/phantomjs # phantomjs 二进制包镜像
npm set sass_binary_site http://cdn.npm.taobao.org/dist/node-sass # node-sass 二进制包镜像
npm set electron_mirror http://cdn.npm.taobao.org/dist/electron/ # electron 二进制包镜像
@FrankFang
FrankFang / sidekiq_delete_jobs.md
Created August 31, 2018 02:13 — forked from eparreno/sidekiq_delete_jobs.md
How to delete Sidekiq jobs in a Rails app using ActiveJobs

How to delete Sidekiq jobs in a Rails app using ActiveJobs

Sidekiq jobs can be enqueued or scheduled. Enqueued means that they are gonna be picked up as soon as possible, scheduled jobs will be enqueued at some specific time.

job_id and jid

When using ActiveJobs, Rails will return a job_id after sending the job to ActiveJobs

job = UserMailer.send_invite(params).deliver_later
@FrankFang
FrankFang / find_dups.rb
Created November 9, 2017 15:35 — forked from rob-murray/find_dups.rb
Rails find duplicate records
columns_that_make_record_distinct = [:some_id, :another_name]
distinct_ids = Model.select("MIN(id) as id").group(columns_that_make_record_distinct).map(&:id)
duplicate_records = Model.where.not(id: distinct_ids)
@FrankFang
FrankFang / nginx-403-forbidden-error-hosting-in-user-home-directory.md
Created August 13, 2017 20:09 — forked from jhjguxin/nginx-403-forbidden-error-hosting-in-user-home-directory.md
nginx 403 forbidden error when server static file under user home directory
@FrankFang
FrankFang / application.html.erb
Created July 17, 2017 08:56 — forked from Dagnan/application.html.erb
Inline CSS or JS in Rails 5
<!DOCTYPE html>
<html>
<head>
<%= inline_js 'application.js' %>
<%= inline_css 'application.css' %>
</head>
<body>
</body>
</html>
@FrankFang
FrankFang / registrations_controller.rb
Created June 14, 2017 07:02 — forked from jwo/registrations_controller.rb
API JSON authentication with Devise
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
@FrankFang
FrankFang / nginx.conf
Created May 17, 2017 13:22 — forked from plentz/nginx.conf
Best nginx configuration for improved security(and performance). Complete blog post here http://tautt.com/best-nginx-configuration-for-security/
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@FrankFang
FrankFang / encryption-decryption.rb
Created May 7, 2017 23:27 — forked from gevans/encryption-decryption.rb
A couple examples of using asymmetric RSA signing and encryption using Ruby's OpenSSL libraries.
require 'openssl'
key = OpenSSL::PKey::RSA.new(2048)
p encrypted_string = key.public_encrypt('my plaintext string', OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
p decrypted_string = key.private_decrypt(encrypted_string, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)

React lifecycle cheatsheet

Method Side effects1 State updates2 Example uses
Mounting
componentWillMount Constructor equivalent for createClass
render Create and return element(s)
componentDidMount DOM manipulations, network requests, etc.
Updating
componentWillReceiveProps Update state based on changed props