Skip to content

Instantly share code, notes, and snippets.

View wangzuo's full-sized avatar
🎯
Focusing

Wang Zuo wangzuo

🎯
Focusing
View GitHub Profile
@wangzuo
wangzuo / LICENSE.txt
Created January 8, 2012 09:03 — forked from p01/LICENSE.txt
Sudoku Solver in 140bytes
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Mathieu 'p01' Henri - http://www.p01.org/releases/
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@wangzuo
wangzuo / latency.txt
Created May 31, 2012 13:07 — forked from jboner/latency.txt
Latency numbers every programmer should know
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns
Mutex lock/unlock 25 ns
Main memory reference 100 ns
Compress 1K bytes with Zippy 3,000 ns
Send 2K bytes over 1 Gbps network 20,000 ns
Read 1 MB sequentially from memory 250,000 ns
Round trip within same datacenter 500,000 ns
Disk seek 10,000,000 ns
@wangzuo
wangzuo / dynamic-gist-embed.html
Created June 7, 2012 04:41
Dynamic Gist Embedding
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Dynamic Gist Embedding</title>
</head>
<body>
<p>
@wangzuo
wangzuo / README.md
Created August 2, 2012 02:25 — forked from fnichol/README.md
Download a cacert.pem for RailsInstaller

Why?

There is a long standing issue in Ruby where the net/http library by default does not check the validity of an SSL certificate during a TLS handshake. Rather than deal with the underlying problem (a missing certificate authority, a self-signed certificate, etc.) one tends to see bad hacks everywhere. This can lead to problems down the road.

From what I can see the OpenSSL library that Rails Installer delivers has no certificate authorities defined. So, let's go fetch some from the curl website. And since this is for ruby, why don't we download and install the file with a ruby script?

Installation

The Ruby Way! (Fun)

@wangzuo
wangzuo / github.css
Created September 13, 2012 03:00 — forked from theconektd/github.css
Github Markdown CSS - for Markdown Editor Preview
body {
font-family: Helvetica, arial, sans-serif;
font-size: 14px;
line-height: 1.6;
padding-top: 10px;
padding-bottom: 10px;
background-color: white;
padding: 30px; }
body > *:first-child {
@wangzuo
wangzuo / gist:3737917
Created September 17, 2012 15:09 — forked from shijinkui/gist:3402506
HADOOP报错Incompatible namespaceIDs
今早一来,突然发现使用-put命令往HDFS里传数据传不上去了,抱一大堆错误,然后我使用bin/hadoop dfsadmin -report查看系统状态
admin@adw1:/home/admin/joe.wangh/hadoop-0.19.2>bin/hadoop dfsadmin -report
Configured Capacity: 0 (0 KB)
Present Capacity: 0 (0 KB)
DFS Remaining: 0 (0 KB)
DFS Used: 0 (0 KB)
DFS Used%: ?%
-------------------------------------------------
Datanodes available: 0 (0 total, 0 dead)
@wangzuo
wangzuo / redcarpet.rb
Created September 23, 2012 12:24 — forked from stephencelis/redcarpet.rb
Redcarpet (Markdown) template handler for Rails 3.1.
# config/initializers/redcarpet.rb
class ActionView::Template
class Redcarpet < Handler
include Handlers::Compilable
def compile template
::Redcarpet.new(template.source).to_html.inspect
end
end
@wangzuo
wangzuo / rails.org
Created September 28, 2012 04:45 — forked from map7/rails.org
Rails 3.1 autocomplete using coffee-script and jquery-ui
@wangzuo
wangzuo / subject.rb
Created September 28, 2012 17:39
carrierwave simple validation
class Subject < ActiveRecord::Base
mount_uploader :icon, IconUploader
validates_presence_of :icon
validate :image_size_validation, :image_type_validation, :if => "icon?"
def image_size_validation
errors[:icon] << "should be less than 2MB" if icon.size > 2.megabytes
end
@wangzuo
wangzuo / example-fade.js
Created October 20, 2012 14:48
javascript closure
// Define a function that sets a DOM node's color
// to yellow and then fades it to white.
var fade = function (node) {
var level = 1;
var step = function () {
var hex = level.toString(16); node.style.backgroundColor = '#FFFF' + hex + hex; if (level < 15) {
level += 1;
setTimeout(step, 100);
}
};