Skip to content

Instantly share code, notes, and snippets.

View lanrion's full-sized avatar
🎯
Focusing

lanrion lanrion

🎯
Focusing
  • guǎng zhōu
View GitHub Profile
@lanrion
lanrion / hexstring.js
Created March 23, 2020 13:52 — forked from tauzen/hexstring.js
Hex string to byte and other way round conversion functions.
function byteToHexString(uint8arr) {
if (!uint8arr) {
return '';
}
var hexStr = '';
for (var i = 0; i < uint8arr.length; i++) {
var hex = (uint8arr[i] & 0xff).toString(16);
hex = (hex.length === 1) ? '0' + hex : hex;
hexStr += hex;
@lanrion
lanrion / status_header_setter
Created September 14, 2016 09:41 — forked from ktkaushik/status_header_setter
Set HTTP status headers with respond_with( object ) in rails.
1xx Informational
100 Continue :continue
101 Switching Protocols :switching_protocols
102 Processing :processing
2xx Success
200 OK :ok
### Install OpenJDK
cd ~
sudo apt-get update
sudo apt-get install openjdk-7-jre-headless -y
### Download and Install ElasticSearch
### Check http://www.elasticsearch.org/download/ for latest version of ElasticSearch and replace wget link below
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.3.1.deb
sudo dpkg -i elasticsearch-1.3.1.deb
alias 和 alias_method 区别 ruby

1

class User

  def full_name
class ApplicationController < ActionController::Base
...
#Problem:
#In rails 3.0.1+ it is no longer possible to do this anymore;
# rescue_from ActionController::RoutingError, :with => :render_not_found
#
#The ActionController::RoutingError thrown is not caught by rescue_from.
#The alternative is to to set a catch-all route to catch all unmatched routes and send them to a method which renders an error
#As in http://techoctave.com/c7/posts/36-rails-3-0-rescue-from-routing-error-solution
@lanrion
lanrion / README.md
Created October 13, 2013 01:41 — forked from nikcub/README.md
@lanrion
lanrion / gist:6503952
Created September 10, 2013 01:41 — forked from ihower/gist:366372
class Dragon; end
# 使用 def 定義 class method
Dragon.instance_eval do
def foo
puts "bar"
end
end
Dragon.foo # bar
@lanrion
lanrion / test.clj
Created September 9, 2013 06:24 — forked from adambard/test.clj
; Comments start with semicolons.
; Clojure is written in "forms", which are just
; lists of things inside parentheses, separated by whitespace.
;
; The clojure reader assumes that the first thing is a
; function or macro to call, and the rest are arguments.
;
; Here's a function that sets the current namespace:
(ns test)

Implement Routing for Subdomains

Rails 3.0 introduced support for routing constrained by subdomains.

A subdomain can be specified explicitly, like this:

match '/' => 'home#index', :constraints => { :subdomain => 'www' }