Skip to content

Instantly share code, notes, and snippets.

View caok's full-sized avatar

Clark caok

View GitHub Profile
@caok
caok / activejob.md
Last active August 29, 2015 14:09
ActiveJob in rails4
gem 'delayed_job_active_record'
bundle install

rails generate delayed_job:active_record
rake db:migrate

Rails 3 Mailers

@caok
caok / paperclip.md
Last active August 29, 2015 14:09
paperclip

gem "paperclip", "~> 4.2"

paperclip

class User < ActiveRecord::Base
  has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
  validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
end
@caok
caok / gist:4af4eb264c180e96e821
Last active October 30, 2015 03:31
Crontab的格式
第1列分钟1~59
第2列小时1~23(0表示子夜)
第3列日1~31
第4列月1~12
第5列星期0~6(0表示星期天)
第6列要运行的命令
下面是crontab的格式:
分 时 日 月 星期 要运行的命令
@caok
caok / votes_importer.rake
Created November 6, 2014 16:00
数据迁移/导入
namespace :chideo do
namespace :votes do
desc "Import votes via the existing API and import into the database"
task import: :environment do
Rake::Task["chideo:votes:generate_seed_file"].invoke
Rake::Task["chideo:votes:import_seed_file"].invoke
end
desc "Generate votes seed file"
@caok
caok / gist:64acd97d224565ed3d7d
Created November 2, 2014 16:20
puma for mina
# Puma
# ==============================================================================
namespace :puma do
set :puma_pid, "#{app_path}/tmp/pids/puma.pid"
set :start_puma, %{
cd #{app_path}
bundle exec puma --config #{app_path}/config/puma.rb --environment #{rails_env}
}
# Start task
@caok
caok / gist:3ce58bd0ba3b715c3959
Last active August 29, 2015 14:08
linux 文件数量统计
统计某文件夹下文件的个数
ls -l |grep "^-"|wc -l
统计某文件夹下目录的个数
ls -l |grep "^d"|wc -l
统计文件夹下文件的个数,包括子文件夹里的
ls -lR|grep "^-"|wc -l
假如在一个目录中保留最近30天的文件,30天前的文件自动删除
@caok
caok / gist:f8df7e1a9aa5b402cc21
Created November 1, 2014 08:56
加密、解密字段
before_save :encrypt_note
def encrypt_note
salt = SecureRandom.random_bytes(64)
key = encrypt_key || ActiveSupport::KeyGenerator.new(ENV["SECRET_KEY"]).generate_key(salt)
crypt = ActiveSupport::MessageEncryptor.new(key)
%w(client_note food medicines hydration md_appointments activity mood positive_thinking positive_action listener_note).each_with_index do |att|
val = if !new_record? and send("#{att}_changed?")
read_attribute(att.to_sym)
@caok
caok / devise.md
Last active August 29, 2015 14:08
  • rails generate devise:install

  • rails rails generate devise MODEL

  • rake db:migrate

  • rails generate devise:views

  • rails generate devise:controllers [scope]

you need to set up the default URL options for the Devise mailer in each environment. Here is a possible configuration for config/environments/development.rb:

config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
@caok
caok / PostgreSQL.md
Last active October 31, 2020 01:10
PostgreSQL

安装

sudo apt-get install postgresql
sudo apt-get install libpq-dev
# for hstore
sudo apt-get install postgresql-contrib

安装9.5

@caok
caok / gist:9c78656dab290da40902
Last active August 29, 2015 14:03
应用环境构筑

更新源

sudo apt-get update

安装系统包

sudo apt-get -y install git-core curl exuberant-ctags vim autoconf automake openssl \
  build-essential libc6-dev libreadline6 libreadline6-dev zlib1g zlib1g-dev libssl-dev libyaml-dev \
  mysql-server libmysqlclient-dev libsqlite3-0 libsqlite3-dev sqlite3 \