Skip to content

Instantly share code, notes, and snippets.

@iannono
iannono / mvc3+dwz简明指南
Created January 1, 2013 12:44
MVC3: Concise Guide
## 准备工作
[从全新数据库开始](http://msdn.microsoft.com/en-us/data/jj193542)
[从已有的数据库开始](http://msdn.microsoft.com/en-us/data/jj200620)
*值得注意的是需要安装Nuget和Power Tools两个插件,并且保证你的EF是5.0*
## 模型
对于需要返回多个模型到同一个视图的情况,可以采用如下的方式:
@iannono
iannono / Linux: rails env install guide
Last active December 14, 2015 03:39
rails env install guide
# this guide is based on http://ruby-china.org/wiki/install_ruby_guide and linuxmint
# -------what'new-----
# fixed some bug
# add solution for common errors
# 2013-10-17
# install sqlite3
sudo apt-get install libsqlite3-dev
# 2013-8-15
@iannono
iannono / Linux: config mint env
Last active December 15, 2015 05:48
Linux: config mint env
## config sources
sudo vim /etc/apt/sources.list
#网易源(速度很快)
deb http://mirrors.163.com/ubuntu/ precise main universe restricted multiverse
deb-src http://mirrors.163.com/ubuntu/ precise main universe restricted multiverse
deb http://mirrors.163.com/ubuntu/ precise-security universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/ precise-security universe main multiverse restricted
deb http://mirrors.163.com/ubuntu/ precise-updates universe main multiverse restricted
deb http://mirrors.163.com/ubuntu/ precise-proposed universe main multiverse restricted
@iannono
iannono / rails-ide-workflow.md
Created April 4, 2013 05:02
Vim: rails ide workflow

based on

you need to install plugins blow:

@iannono
iannono / fetch_weather.rb
Created June 28, 2013 03:47
抓取天气的小脚本
#!/usr/bin/env ruby
#encoding:utf-8
require 'csv'
require 'open-uri'
require 'nokogiri'
require 'date'
def generate_url(date)
"http://history.tianqizx.cn/his_1582_" + date.strftime('%Y/%-m/%-d') + ".aspx"
@iannono
iannono / angular_notes.js
Last active December 20, 2015 00:49
angularJS学习笔记
//在controller和directive中定时修改作用域模型的方式
app.controller('generalCtrl', ['$scope', function($scope) {
$scope.pv = 0;
//通过调用apply触发内部的direct循环,从而更新作用域和模型
setInterval(function(){$scope.$apply()}, 1000);
}])
directives.directive('rtIp', function(){
return function(scope, elm, attrs) {
setInterval(function(){scope.pv = scope.pv + 1;}, 1000);
@iannono
iannono / .bash_profile
Last active December 20, 2015 08:08
bash config
export PATH=$HOME/local/bin:$PATH
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
#for git
BASH_NEWLINE="\n"
BASH_GRAY="\[\e[1;30m\]"
BASH_LIGHT_GREEN="\[\e[1;32m\]"
BASH_WHITE="\[\e[1;0m\]"
@iannono
iannono / fetch_asciicast.rb
Created August 15, 2013 06:21
fetch asciicast from railscast.com
#!/usr/bin/env ruby
##encoding:utf-8
require 'open-uri'
require 'nokogiri'
require 'stringio'
def generate_cast_url(link)
link + "?view=asciicast"
end
@iannono
iannono / fetch_asciicast_with_auth.rb
Created August 15, 2013 08:35
fetch_asciicast_with_auth
#!/usr/bin/env ruby
##encoding:utf-8
require 'open-uri'
require 'nokogiri'
require 'stringio'
require 'watir-webdriver'
def generate_cast_url(link)
link + "?view=asciicast"

My issues with Modules

In researching topics for RailsCasts I often read code in Rails and other gems. This is a great exercise to do. Not only will you pick up some coding tips, but it can help you better understand what makes code readable.

A common practice to organize code in gems is to divide it into modules. When this is done extensively I find it becomes very difficult to read. Before I explain further, a quick detour on instance_eval.

You can find instance_eval used in many DSLs: from routes to state machines. Here's an example from Thinking Sphinx.

class Article < ActiveRecord::Base