Skip to content

Instantly share code, notes, and snippets.

View shunwen's full-sized avatar
🐢

shunwen shunwen

🐢
View GitHub Profile
@Ameeda
Ameeda / NokogiriXPathNamespaces
Created May 5, 2011 14:48
Selecting elements in some namespace using Nokogiri with XPath
2 ways to extract elements from within XML namespaces using Nokogiri
When trying to select elemenets in the default namespace, e.g. "xmlns= http://www.w3.org/2005/Atom", try the following two ways. Note the xmlns=" attribute on entry element:
Original xml:
Nokogiri::XML(@xml_string).xpath("//author/name").each do |node|
puts node
end
1. Define a namespace context for your XPath expression and point your XPath steps to match elements in that namespace. Define a namespace-to-prefix mapping and use this prefix (a) in the XPath expression.
@myobie
myobie / mountain-lion-brew-setup.markdown
Created February 18, 2012 20:14
Get Mountain Lion and Homebrew to Be Happy

Get Mountain Lion and Homebrew to Be Happy

1) Install XCode 4.4 into /Applications

Get it from the App Store.

2) Install Command Line Tools

In XCode's Preferences > Downloads you can install command line tools.

@them0nk
them0nk / rspec_rails_cheetsheet.rb
Created March 23, 2012 03:39
Rspec Rails cheatsheet (include capybara matchers)
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
@andrerpbts
andrerpbts / contato_mailer.rb
Created May 25, 2012 11:15
IMAP Mail Receive Ruby
#encoding: utf-8
class ContatoMailer < ActionMailer::Base
def receive(message)
p message
end
end
@letoh
letoh / gist:2790559
Last active March 13, 2024 07:23
[筆記] 為什麼在 x86,MBR 會被載入到 0x7C00?(完全版)

原文 Assembler / なぜx86ではMBRが"0x7C00"にロードされるのか?(完全版)

感謝 descent 大大分享本文,隨便看隨便譯。本文不是逐句譯,同時也不是這方面的專家 (不管是語言或技術),用語不一或缺漏錯誤在所難免,歡迎自行 fork 修正指教

誰適合看本文?

對 x86 架構與組合語言有基礎認識,以及從 MBR 到載入 OS 這一段過程有興趣的人 (還有談到中斷向量或 INT xxx 時不會一臉茫然的人)

@pzol
pzol / README.md
Created June 5, 2012 07:23
RVM + Puma + Ubuntu

Running Puma on Nginx

I use the latest Puma v1.4.0 from rubygems.

Make sure you have nginx installed with these options:

>/opt/nginx/sbin/nginx -V
nginx version: nginx/1.0.15

built by gcc 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3)

@davidjrice
davidjrice / redcarpet.rb
Created June 29, 2012 00:34
Rails 3.2 Markdown Template Handler
# config/initializers/redcarpet.rb
module ActionView
module Template::Handlers
class Markdown
class_attribute :default_format
self.default_format = Mime::HTML
def call(template)
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true)
markdown.render(template.source).html_safe.inspect
@ledsun
ledsun / toWareki.js
Created July 23, 2012 04:51
JavaScript 西暦→和暦の変換処理
function toWareki(year,month,day)
{
var wareki = "";
year = Number (year);
if (year == 1868)
{
/* 9月8日から明治元年 */
/* 誕生日がここの人はいないだろうから細かくは気にしない */
wareki = '明治元年';
}
@zenkay
zenkay / gist:3237860
Created August 2, 2012 15:19
Installation tips for RVM/Ruby on OSX 10.8 Mountain Lion

Ruby, RVM and Mountain Lion

Key problems

Mountain Lion (10.8) has three main difference compared to Lion (10.7):

  • XCode 4.4 does not install Command Line Tools by default
  • X11 isn't available anymore
  • The installed version of OpenSSL has some bugs

How to work around

@trcarden
trcarden / gist:3295935
Created August 8, 2012 15:28
Rails 3.2.7 SSL Localhost (no red warnings, no apache config)
# SSL self signed localhost for rails start to finish, no red warnings.
# 1) Create your private key (any password will do, we remove it below)
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key