Skip to content

Instantly share code, notes, and snippets.

View simlegate's full-sized avatar
🎯
Focusing

Devin Zhang simlegate

🎯
Focusing
View GitHub Profile
@simlegate
simlegate / rspec_example.rb
Last active December 24, 2015 04:09
Rspec Syntax
# stub class
stub_const('ResourceCategory', Class.new)
# stub class and stub it's methods
stub_const('ResourceCategory', Class.new).stub(:all).and_return([])
@simlegate
simlegate / mutli_thread_web_server.rb
Last active December 20, 2015 00:49
Ruby 构建一个简单的支持多线程的 Web 服务器
require 'thread'
require 'socket'
class RequestHandler
def initialize(session)
@session = session
end
def process
while @session.gets.chop.length != 0
@simlegate
simlegate / nginx-init
Last active December 19, 2015 09:19
nginx init script
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
@simlegate
simlegate / rubycas_test.md
Last active January 27, 2016 16:52
describe how to spec rubycas with rspec.

rubycas client configuration options in config/envirement.rb
[more details] (https://github.com/rubycas/rubycas-client)

# enable detailed CAS logging
cas_logger = CASClient::Logger.new(::Rails.root+'/log/cas.log')
cas_logger.level = Logger::DEBUG

CASClient::Frameworks::Rails::Filter.configure(
  :cas_base_url  => "https://cas.example.foo/",
  :login_url     => "https://cas.example.foo/login",
@simlegate
simlegate / 签名.sh
Last active December 18, 2015 23:49
ubuntu 签名错误解决办法
#!/bin/bash
sudo apt-get clean
cd /var/lib/apt
sudo rm -rf lists.old
sudo mv lists lists.old
gpg --delete-key --armor 40976EAF437D05B5
sudo apt-key del 40976EAF437D05B5
@simlegate
simlegate / 个人简历.md
Last active December 18, 2015 19:49
简历

个人简介

  • 姓名:张强(simlegate)
  • 性别:男
  • 年龄:23
  • 出生年月:1990.12.28

教育情况

毕业于成都学院(成都大学)软件工程

个人技能

@simlegate
simlegate / gist:5803922
Created June 18, 2013 09:21
git 命令
已经commit的文件即使在.gitignore中也会被跟踪
git rm --cached your_file

Building Rich Domain Models in Rails.

Part 1. Decoupling Persistence.

Abstract

Domain model is an effective tool for software development. It can be used to express really complex business logic, and to verify and validate the understanding of the domain among stakeholders. Building rich domain models in Rails is hard. Primarily, because of Active Record, which doesn't play well with the domain model approach.

One way to deal with this problem is to use an ORM implementing the data mapper pattern. Unfortunately, there is no production ready ORM doing that for Ruby. DataMapper 2 is going to be the first one.

Another way is to use Active Record just as a persistence mechanism and build a rich domain model on top of it. That's what I'm going to talk about in this article.

@simlegate
simlegate / gist:5727530
Created June 7, 2013 07:07
redis error
config set stop-writes-on-bgsave-error no
@simlegate
simlegate / .tmux.conf
Last active December 18, 2015 03:49
tmux configure file for vim
set-window-option -g mode-keys vi
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R