Skip to content

Instantly share code, notes, and snippets.

@cndaniel
cndaniel / gemfile.rb
Created December 10, 2016 13:50
请对照你的Gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
# Use sqlite3 as the database for Active Record
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'

@daniel: 这个问题有点麻烦哦,可能是 mac OSX 系统升级的问题呢,可以试着自己耐心按照下面步骤来哦:

  1. 终端运行rvm osx-ssl-certs status all确认没有反应 , 如果有反应吐出信息请上slack @助教。
  2. 终端运行rvm autolibs homebrew (正常情况应该回车后没有反应)
  3. 重设ssl环境变量: 依次终端输入运行:(无反应是正常情况):

export LDFLAGS=-L/usr/local/opt/openssl/lib

@cndaniel
cndaniel / Service-start.md
Created March 5, 2017 03:27
brew services start postgresql 无法开机启动资料库

出现 permission denied

往往因为电脑上有多个用户导致的

  1. 先去 system preferences 确定用户的权限是管理员

  2. 再进终端: echo ~ user/whoami , 确定用户名是whoami

  3. 终端输入 sudo chown $(whoami):admin /usr/local && sudo chown -R $(whoami):admin /usr/local赋予权限

[alias]
st = status
s = status
co = checkout
c = commit -v
ci = commit -a -v
b = branch
d = diff
p = pull
a = add -A .
@cndaniel
cndaniel / index.md
Created April 7, 2017 13:32 — forked from rstacruz/index.md
Rails models cheatsheet

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one

class Module
def subclasses
classes = []
ObjectSpace.each_object do |klass|
next unless Module === klass
classes << klass if self > klass
end
classes
end
end

一路过来也部署过3、4个Rails App了,其中也使用过mina等远程部署项目,但每次去部署新的App还是会遇到一些大大小小问题。最近和几个朋友正在做一个应用,在部署的过程中又被自己坑了~所以今天准备总结一下,方便自己未来的部署之路,也方便Rails新手学习使用。

#####环境说明 因为Linux的发型版太多,所以不能一一举例,经过自己的实践体验,发现Ubuntu可以更轻松的部署您的Rails App(个人看法,曾经在Centos下部署,遇到了好多坑)。所以该博文将基于以下的部署环境。

  1. 操作系统:Ubuntu14.04
  2. Rails:4.2.0
  3. Ruby:2.2.1
  4. Mysql: 5.6.22
  5. Nginx: 1.8.0
  6. Puma: 2.11.0
@cndaniel
cndaniel / sort.rb
Last active June 7, 2017 07:25
binary_search and find_index
require 'benchmark'
arr = [0, 5, 13, 13, 30, 42, 52, 70, 85, 96, 103, 111, 116, 127, 130, 143, 150, 150, 161, 175, 207, 210, 218, 246, 257, 257, 263, 280, 304, 310, 326, 327, 332, 346, 360, 371, 374, 378, 406, 407, 407, 408, 428, 431, 437, 442, 445, 479, 489, 491, 505, 517, 520, 536, 548, 598, 602, 605, 618, 642, 649, 654, 659, 662, 677, 678, 682, 689, 695, 696, 697, 701, 711, 717, 727, 737, 745, 749, 754, 757, 770, 786, 802, 805, 814, 832, 840, 850, 853, 854, 888, 894, 904, 913, 913, 945, 962, 964, 972, 998]
def binary_search(arr, element)
l = 0
r = arr.length - 1
while l <= r
mid = l + ((r - l) / 2)
### Keybase proof
I hereby claim:
* I am cndaniel on github.
* I am cndaniel (https://keybase.io/cndaniel) on keybase.
* I have a public key ASDlRhMGDvyMlv3XtsL7mpwFRlqhMfq-VWboxBXOFNJKEQo
To claim this, I am signing this object:

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name: