Skip to content

Instantly share code, notes, and snippets.

# Idea taken from https://gist.github.com/jackcarter/d86808449f0d95060a40
# This script requires python lib: requests
# You can install by: `python -m pip install requests`
import time
import codecs
import requests
reader = codecs.getreader("utf-8")
@zernel
zernel / psql-with-gzip-cheatsheet.sh
Created August 18, 2018 03:00 — forked from brock/psql-with-gzip-cheatsheet.sh
Exporting and Importing Postgres Databases using gzip
# This is just a cheat sheet:
# On production
sudo -u postgres pg_dump database | gzip -9 > database.sql.gz
# On local
scp -C production:~/database.sql.gz
dropdb database && createdb database
gunzip < database.sql.gz | psql database
@zernel
zernel / install.sh
Last active March 6, 2018 05:52 — forked from chuyik/install.sh
Bandwagon(搬瓦工) CentOS 7 安装 shadowsocks-libev 和 kcptun
######################
## shadowsocks-libev
######################
# install dependencies
yum install epel-release -y
yum install gcc gettext autoconf libtool automake make pcre-devel asciidoc xmlto udns-devel libev-devel -y
# install shadowsocks-libev
cd /etc/yum.repos.d/
@zernel
zernel / Caddyfile
Created November 18, 2017 01:35 — forked from bendo01/Caddyfile
Caddy Web Server As Service on Centos 7
#cd /etc/caddy/Caddyfile
example.com {
root /usr/share/nginx/html
gzip
log /var/log/caddy/access.log
#fastcgi / unix:/var/run/php-fpm/php-fpm.sock php # Fast CGI php interpreter
#fastcgi / fastcgi / 127.0.0.1:9000 php # Fast CGI php interpreter
#using with laravel
fastcgi / unix:/var/run/php-fpm/php-fpm.sock php {
index index.php
@zernel
zernel / surge.conf
Created June 30, 2016 06:39
📦 Surge 安装步骤导览 | http://bit.ly/292EJz3
# 规则配置仅供参考,适用于 Surge iOS & Mac;
# 包含 Proxy Group、URL Rewrite 特性
# 包含 Reject 规则,用于拦截广告、行为分析、数据统计
# 屏蔽 Hao123、百度联盟广告以及部分运营商网页漂浮广告
# 部分特性可能仅适用于最新的 TestFlight 版本
[General]
# warning, notify, info, verbose
loglevel = notify
ipv6 = true

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
@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 / 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.