Skip to content

Instantly share code, notes, and snippets.

View marshluca's full-sized avatar
🏠
Working from home

Lucas Zhang marshluca

🏠
Working from home
View GitHub Profile
@marshluca
marshluca / ssh_tunnel.txt
Created June 24, 2011 02:37
proxy via ssh tunnel
用ssh代理来翻墙也很容易,为了避免和自己的管理账户冲突,可以新建一个ssh用户,并且禁用该用户的shell。以下是相关命令:
1. groupadd sshfq(增加组sshfq)
2. useradd -d /home/sshfq -m -g sshfq -s /bin/false sshfq (增加用户sshfq创建同名目录并属于组sshfq并禁止shell)
3. passwd sshfq (修改sshfq密码)
4.ssh -qTfnN -D 7070 [email protected]
@marshluca
marshluca / tqq_oauth.rb
Created June 17, 2011 13:10
Tqq OAuth in Ruby
require "rubygems"
require "oauth"
TQQ_CONSUMER_KEY = "9b43a5afaca04afd8eb573e673fce3f9"
TQQ_CONSUMER_SECRET = "dd6b3cef9a6896e373085a83cd8b74f9"
# 1. 获取Request Token
consumer = OAuth::Consumer.new(TQQ_CONSUMER_KEY, TQQ_CONSUMER_SECRET, {
:site => "https://open.t.qq.com",
:request_token_path => "/cgi-bin/request_token",
@marshluca
marshluca / xml_escape.rb
Created June 17, 2011 13:07
XML Response without escaping in Rails 3
require 'rubygems'
require "builder"
module Builder
class XmlBase
def _escape(text)
text
end
end
end
@marshluca
marshluca / json_escape.rb
Created June 17, 2011 13:06
Json Response without escaping in Rails 3
module ActiveSupport
module JSON
module Encoding
def self.escape(string)
if string.respond_to?(:force_encoding)
string = string.encode(::Encoding::UTF_8, :undef => :replace).force_encoding(::Encoding::BINARY)
end
json = string.gsub(escape_regex) { |s| ESCAPED_CHARS[s] }
json = %("#{json}")
json.force_encoding(::Encoding::UTF_8) if json.respond_to?(:force_encoding)
@marshluca
marshluca / observe_network.m
Created May 21, 2011 03:59
Observer network with Reachablity
- (void)reachabilityChanged:(NSNotification *)note
{
Reachability* curReach = [note object];
NSParameterAssert([curReach isKindOfClass: [Reachability class]]);
NetworkStatus status = [curReach currentReachabilityStatus];
if (status == NotReachable) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil
message:@"当前没有可用网络"
delegate:nil
*.pbxproj -crlf -diff -merge
#!/usr/bin/env ruby -wKU
require "net/http"
require "uri"
####################### Standard HTTP Request #######################
def standard_http_request
uri = URI.parse("http://wwwgoogle.com.hk")
# Shortcut
@marshluca
marshluca / apns.rb
Created March 17, 2011 07:58
Apple Push Notification Services
require "rubygems"
require "/Library/Ruby/Gems/1.8/gems/apns-0.9.0/lib/apns"
###################
# Hosts Config
###################
# Push Notification Service:
#
# (default: gateway.sandbox.push.apple.com is)
#!/usr/bin/env ruby
# object_model/alphanumeric.rb
require "test/unit"
class String
def to_alphanumeric
gsub(/[^\w\s]/,'')
end
end
@marshluca
marshluca / ancestors.rb
Created March 13, 2011 14:12
ancestors.rb
#!/usr/bin/env ruby
class C
end
p C.ancestors # => [C, Object, Kernel, BasicObject]
# => [C, Object, Kernel] in Ruby 1.8
p Class.ancestors # => [Class, Module, Object, Kernel, BasicObject]
# => [Class, Module, Object, Kernel] in Ruby 1.8