Skip to content

Instantly share code, notes, and snippets.

@luikore
luikore / gist:149493
Created July 18, 2009 09:55
chinese string
# regexps to check if a string is pure chinese
class String
# 20k chars
CHINESE_UCS2 = /^(?:
[\x4e-\x9e][\x00-\xff]
|\x9f[\x00-\xa5]
)+$/xn
# 20k chars
CHINESE_UTF8 = /^(?:
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@mfdela
mfdela / fiber.rb
Created February 13, 2011 00:44
Ruby fiber benchmark
#!/usr/bin/ruby1.9
require 'fiber'
require 'benchmark'
class Ring
attr_reader :id
attr_accessor :attach
def initialize(id)
@WizardOfOgz
WizardOfOgz / gist:1012107
Created June 7, 2011 12:13
Save Base64-encoded images with Paperclip
class Avatar < ActiveRecord::Base
attr_accessor :content_type, :original_filename, :image_data
before_save :decode_base64_image
has_attached_file :image,
PAPERCLIP_CONFIG.merge(
:styles => {
:thumb => '32x32#',
:medium => '64x64#',
@AndorChen
AndorChen / README.markdown
Created November 17, 2011 08:29
Howto Depoly Rails App to VPS

#如何将 Rails 应用程序部署到 VPS 上

如果已经在 VPS 上假设好了 Rails 生产环境,接下来就可以将部署应用程序了。

###需要用到的工具


@nightire
nightire / Changes in Rails 4_1.md
Last active May 11, 2022 04:50
拥抱 Rails 4 —— 详述 Rails 4 的新变化

Routes

小心地使用 Match(Rails 3 已实现)

Rails 3 提供了 match 方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:

注:(r3 代表 Rails 3,r4 代表 Rails 4)

# routes.rb
@baya
baya / gist:5386883
Created April 15, 2013 09:07
exception retry
def try(title, options = { }, &p)
tried_times = 0
max_times = options[:max_times] || 3
exceptions = options[:on] || Exception
exceptions = [exceptions] if !exceptions.is_a?(Array)
rescue_text = <<-EOF
begin
# 不能用yield
p.call
rescue #{exceptions.join(',')} => e
@shou65
shou65 / jobs.md
Last active December 20, 2015 12:09
收留我shou65 - 招募中...

[杭州] 旅行新体验,创业邀约~

shou65.com

Web Developer

我们都有梦想,不管在现实中苦苦挣扎,还是在高楼里锦衣玉食,我们都想做点属于自己的事情、有利于这个社会的事情,因为只有这样,才能证明生存的价值。

我们不想说改变世界,但我们为此从未停步!

我们,一群想活出自己的人,在寻找同舟共济的伙伴,不管你在学校苦心孤谐,或者在楼群里朝九晚五,只要你自认籍籍无名却梦想不灭。

@maxivak
maxivak / webpacker_rails.md
Last active June 15, 2024 21:37
Webpack, Yarn, Npm in Rails