Skip to content

Instantly share code, notes, and snippets.

View hxx's full-sized avatar
🎯
Focusing

hxx hxx

🎯
Focusing
View GitHub Profile
@hxx
hxx / player.rb
Created July 8, 2014 13:55
has_many :through
class Play < ActiveRecord::Base
# 先告诉model我们在体育协会有很多笔资料
has_many :sports_associations
# 这些资料是要拿来判断这个球员有参与多少球队
has_many :teams, :through => :sports_associations
end
# ~/.bash_profile
function cd {
# actually change the directory with all args passed to the function
builtin cd "$@"
auto_set_tab_chrome_background_color;
}
function auto_set_tab_chrome_background_color {
@hxx
hxx / genymotion_localhost_ip_and_rails_service.md
Created March 7, 2016 09:15
Genymotion localhost IP and rails service

使用 Genymotion 作为 Android Emulator 时,本地调用 Rails 作为 API 后台的 IP 地址,

应该使用 10.0.3.2 来代替 localhost

同时,Rails 服务启动的时候需要使用

rails s -b 0.0.0.0

使用 Android Emulator 相当于是局域网里的另一台机器来访问 Rails 服务,而在 Rails 4.2 以后修改了 Rails Server 默认的的 Host, 所以要使用上面的命令来让 Android Emulator 可以访问 Rails Service,同时需要注意使用防火墙策略来只让受信任的机器访问你的开发服务器。

@hxx
hxx / homebrew permissions in OSX 10.13 High Sierra
Created April 18, 2018 06:12
can't chown /usr/local for homebrew in OSX 10.13 High Sierra
sudo chown -R $(whoami) $(brew --prefix)/*
@hxx
hxx / tmux-cheatsheet.markdown
Created January 13, 2020 07:28 — forked from ryerh/tmux-cheatsheet.markdown
Tmux 快捷键 & 速查表 & 简明教程

注意:本文内容适用于 Tmux 2.3 及以上的版本,但是绝大部分的特性低版本也都适用,鼠标支持、VI 模式、插件管理在低版本可能会与本文不兼容。

Tmux 快捷键 & 速查表 & 简明教程

启动新会话:

tmux [new -s 会话名 -n 窗口名]

恢复会话:

@hxx
hxx / rails-docker-build-speed-up.md
Created April 28, 2020 07:59 — forked from huacnlee/rails-docker-build-speed-up.md
给 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
@hxx
hxx / Rails_Logger_Multiple_Destinations.md
Created August 1, 2021 11:54
Rails Logger 输出到多个目的地(STDOUT 和 File)

Rails Logger 输出到多个目的地(STDOUT 和 File)

背景

已有的项目日志输出在 STDOUT,方便一些日志工具汇总日志,现在想增加其他的日志分享工具却又需要从文件中读取日志,如何在保持日志输出到STDOUT的同时增加输出到文件中呢?

解决方法

https://guides.rubyonrails.org/initialization.html#rails-server-start