Skip to content

Instantly share code, notes, and snippets.

@reyesyang
reyesyang / .gemrc
Created Jun 22, 2017 — forked from jch/.gemrc
gemrc example
View .gemrc
# http://docs.rubygems.org/read/chapter/11
---
gem: --no-ri --no-rdoc
benchmark: false
verbose: true
update_sources: true
sources:
- http://gems.rubyforge.org/
- http://rubygems.org/
backtrace: true
@reyesyang
reyesyang / .gtkrc-eclipse
Created Jun 6, 2017 — forked from andrioli/.gtkrc-eclipse
Config to make Eclipse Juno icons and tabs look small and nice in Linux
View .gtkrc-eclipse
# Create a new file in your home directory called .gtkrc-eclipse
# call eclipse with this command:
# Gtk2 forced:
# export SWT_GTK3=0
# env GTK2_RC_FILES=/usr/share/themes/<YourTheme>/gtk-2.0/gtkrc:/home/<YourUser>/.gtkrc-eclipse '/path_to_eclipse/eclipse'
# In your Eclipse directory find the file 'e4_default_gtk.css'
# In this file there's a CSS class:
@reyesyang
reyesyang / bootstrap.sh
Created Mar 18, 2017
Bootstrap a fresh ubuntu machine with dev tools
View bootstrap.sh
#!/bin/bash
echo '***** Build tools *****'
sudo apt install -y autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev
echo '***** Dev tools *****'
sudo apt install -y git gitg tmux vim-gnome exuberant-ctags memcached redis-server\
mysql-server mongodb postgresql haskell-platform libmysqlclient-dev ipython python-dev\
libsqlite3-dev ubuntu-make
@reyesyang
reyesyang / net_http.rb
Last active Jun 2, 2016
Net::HTTP examples
View net_http.rb
require 'net/http'
# Proxy
proxy_server = 'xxx.xxx.xxx.xxx'
proxy_port = 81
## Example 1
Net::HTTP.new('baidu.com', nil, proxy_server, proxy_port).start { |http| http.get '/' }
## Example 2
@reyesyang
reyesyang / nancy.rb
Created Dec 1, 2015
Nancy is a Sinatra like micro framework for study base on thoughtbot blog: https://robots.thoughtbot.com/lets-build-a-sinatra
View nancy.rb
require 'rubygems'
require 'bundler/setup'
require 'rack'
require 'pry'
module Nancy
METHODS = %w(get post put patch delete head)
class Base
View Smokestack.rb
# https://robots.thoughtbot.com/writing-a-domain-specific-language-in-ruby
module Smokestack
@registry = {}
def self.registry
@registry
end
def self.define(&block)
@reyesyang
reyesyang / kaminari-i18n-zh-CN.yml
Last active Aug 29, 2015
Kaminari I18n translation in zh-CN language
View kaminari-i18n-zh-CN.yml
# Usage:
# 1. Put this file in config/locales/kaminari/zh-CN.yml
# 2. Set load_path in config/application.rb as below:
# config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s]
zh-CN:
views:
pagination:
first: "&laquo; 首页"
last: "末页 &raquo;"
@reyesyang
reyesyang / genrsa.sh
Created Jul 16, 2015
Generate SSL Key, CSR and Self Signed Certificate
View genrsa.sh
# Generate Private Key:
openssl genrsa -out server.key 1024
# Generate a Certificate Signing Request (CSR)
openssl req -new -key server.key -out server.csr
# Generate a Self-Signed SSL Certificate
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
@reyesyang
reyesyang / grape-i18n-zh-CN.yml
Last active Apr 22, 2017
Grape I18n translation in zh-CN language
View grape-i18n-zh-CN.yml
# Usage:
# 1. Put this file in config/locales/grape/zh-CN.yml
# 2. Set load_path in config/application.rb as below:
# config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s]
zh-CN:
grape:
errors:
format: ! '%{attributes} %{message}'
messages:
@reyesyang
reyesyang / rails_template.rb
Last active Aug 29, 2015
Rails project template
View rails_template.rb
# rails new . -d mysql --skip-test-unit
# rails new . --skip-active-record --skip-test-unit
# Edit Gemfile
if yes?('Replace gem source "https://rubygems.org/" with Taobao mirror "https://ruby.taobao.org/"?(y/n)')
gsub_file 'Gemfile', 'rubygems.org', 'ruby.taobao.org'
end
use_mongodb = yes?('Use MongoDB?(y/n)')
gem 'jquery-turbolinks'