Skip to content

Instantly share code, notes, and snippets.

### test
capture_io
flunk msg = nil
pass msg = nil
skip msg = nil, bt = caller
assert test, msg = nil
assert_block msg = nil
assert_empty obj, msg = nil
require 'feedzirra'
# fetching a single feed
feed = Feedzirra::Feed.fetch_and_parse("http://feeds.feedburner.com/PaulDixExplainsNothing")
# feed and entries accessors
feed.title # => "Paul Dix Explains Nothing"
feed.url # => "http://www.pauldix.net"
feed.feed_url # => "http://feeds.feedburner.com/PaulDixExplainsNothing"
feed.etag # => "GunxqnEP4NeYhrqq9TyVKTuDnh0"
@iannono
iannono / notes_of_rails4_patterns.md
Last active December 21, 2015 12:19
notes of rails 4 patterns

models

  • controllers should be responsible for orchestrating the models. means that you should always tell objects what to do, and not ask them question about there state
# controller
if @item.publish
  flash[:notice] = "xxxx"
end
# modle
class Item < ActiveRecord::Base

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 &lt; ActiveRecord::Base
@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"
@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 / .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 / 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 / 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 / rails-ide-workflow.md
Created April 4, 2013 05:02
Vim: rails ide workflow

based on

you need to install plugins blow: