Skip to content

Instantly share code, notes, and snippets.

@zernel
zernel / .zshrc
Created September 18, 2015 02:52
ZSH
# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="robbyrussell"
# Uncomment the following line to use case-sensitive completion.
@zernel
zernel / .gvimrc
Last active November 26, 2015 08:28
My vim config with Neobundle
"set colortheme
"colorscheme autumn
"colorscheme blackboard
colorscheme asu1dark
" 启动gvim时窗口的大小
set lines=42 columns=170
" set font

Routes

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

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

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

# routes.rb
require 'rubygems'
require 'zip/zip'
def unzip_file (file, destination)
Zip::ZipFile.open(file) { |zip_file|
zip_file.each { |f|
f_path=File.join(destination, f.name)
FileUtils.mkdir_p(File.dirname(f_path))
zip_file.extract(f, f_path) unless File.exist?(f_path)
}
# Resize selenium browser window to avoid Selenium::WebDriver::Error::MoveTargetOutOfBoundsError errors
#
# Example usage with Rspec (in spec/support/spec_helper.rb):
#
# config.before(:each) do
# set_selenium_window_size(1250, 800) if Capybara.current_driver == :selenium
# end
#
def set_selenium_window_size(width, height)
window = Capybara.current_session.driver.browser.manage.window
#!/bin/bash
backup_path="/root/production_backup/database_backup"
mv $backup_path/bak_data.19.sql $backup_path/bak_data.20.sql
mv $backup_path/bak_data.18.sql $backup_path/bak_data.19.sql
mv $backup_path/bak_data.17.sql $backup_path/bak_data.18.sql
mv $backup_path/bak_data.16.sql $backup_path/bak_data.17.sql
mv $backup_path/bak_data.15.sql $backup_path/bak_data.16.sql
mv $backup_path/bak_data.14.sql $backup_path/bak_data.15.sql
mv $backup_path/bak_data.13.sql $backup_path/bak_data.14.sql
mv $backup_path/bak_data.12.sql $backup_path/bak_data.13.sql
@zernel
zernel / 0.rb
Created March 1, 2013 16:43 — forked from chancancode/0.rb
mbp:godfrey json_expressions [master] $ irb -Ilib
>> require 'json_expressions/matcher'
=> true
>> m = JsonExpressions::Matcher.new({a: :capture_me})
=> {:a=>:capture_me}
>> require 'json'
=> true
>> m =~ JSON.parse('{"a": 123}')
=> true
>> m.captures
@zernel
zernel / gist:4116514
Created November 20, 2012 07:07
Uncompress CSS
cat somefile.css | awk '{gsub(/{|}|;/,"&\n"); print}' >> uncompressed.css
@zernel
zernel / README.markdown
Created October 26, 2012 03:13 — forked from greypants/README.markdown
RAILS 3: nav_link helper for adding 'selected' class to navigation elements

#Behold, the nav_link:

The nav_link helper works just like the standard Rails link_to helper, but adds a 'selected' class to your link (or its wrapper) if certain criteria are met. By default, if the link's destination url is the same url as the url of the current page, a default class of 'selected' is added to the link.

For full usage details, see: http://viget.com/extend/rails-selected-nav-link-helper

Drop nav_link_helper.rb into app/helpers in your Rails 3.x app and enjoy.

@zernel
zernel / routes
Created October 24, 2012 03:12
Devise disable signup
devise_for :users, :skip => [:registrations]
as :user do
get 'users/edit' => 'devise/registrations#edit', :as => 'edit_user_registration'
put 'users' => 'devise/registrations#update', :as => 'user_registration'
end
# And then modify the app/views/devise/shared/_links.erb