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 / gist:5250899
Last active December 15, 2015 11:09
Convert from Excel to JSON

Convert from Excel to JSON

roo document: roo

require 'rubygems'
require 'roo'
require 'json'

hash = {}

Routes

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

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

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

# routes.rb

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' } 
@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)
@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 / README.md
Created October 13, 2013 01:41 — forked from nikcub/README.md
@lanrion
lanrion / gist:9320326
Last active August 29, 2015 13:56
fork 了某个开源项目,发了PR后,需要更新master的代码的做法
fork 了某个开源项目,发了PR后,需要更新master的代码的做法:
git remote add --track master upstream git://github.com/upstreamname/projectname.git
git fetch upstream
git merge upstream/master
注意:upstream 是定义名称。
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 / gist:9479631
Last active December 5, 2023 08:20
浅析微信信息信息接收与信息回复

微信的信息接收与回复,两者是独立的。

信息接收

共同点在于:都有 ToUserName,FromUserName,CreateTime,MsgType, 这四个字段。

在信息接收方面,分为“普通消息”、“事件推送”,“语音识别结果(微信用户发送语音,微信服务器翻译成文本,只不过比语音消息多一个识别结果字段:Recognition)”。

  • 文本消息(通过“Content”关键字来获取文本内容,这点比较重要,也是使用比较多的场合)
  • 图片消息
@lanrion
lanrion / gist:9801783
Last active August 29, 2015 13:57
ubuntu 快捷命令收集

Alt+F2 : 快速打开搜索栏。

Alt+Tab : 不同应用之间的切换,选中某一个,再Alt+~ 即可放大当前栏目。

下载了Sublime Text 之后,我们需要建立一个快捷命令

sudo mv Sublime\ Text\ 2 /opt/
sudo ln -s /opt/Sublime\ Text\ 2/sublime_text /usr/bin/sublime

参考 http://my.oschina.net/yexingkong/blog/140726