Skip to content

Instantly share code, notes, and snippets.

View yesmeck's full-sized avatar
:octocat:
<img src="x" onerror="alert(1)" />

Wei Zhu yesmeck

:octocat:
<img src="x" onerror="alert(1)" />
View GitHub Profile
@yesmeck
yesmeck / memcached.rb
Created December 17, 2012 04:02
List all keys in memcached
#!/usr/bin/env ruby
require 'net/telnet'
cache_dump_limit = 100
localhost = Net::Telnet::new("Host" => "localhost", "Port" => 11211, "Timeout" => 3)
slab_ids = []
localhost.cmd("String" => "stats items", "Match" => /^END/) do |c|
matches = c.scan(/STAT items:(\d+):/)
slab_ids = matches.flatten.uniq
end
#!/usr/bin/env bash
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev ruby1.9.3
gem install chef ruby-shadow bundler --no-ri --no-rdoc
@yesmeck
yesmeck / stock.rb
Last active December 17, 2015 14:59
Stock
require 'open-uri'
require 'nokogiri'
code = 2904
doc = Nokogiri::HTML(open("http://just2.entrust.com.tw/z/zc/zca/zca_#{code}.djhtm"))
# 當前股價,既網頁中的收盤價
doc.css('table')[2].css('tr')[1].css('td').last.inner_text.to_f
@yesmeck
yesmeck / gems.diff
Created June 7, 2013 18:16
gems.diff
2,7c2,7
< * actionmailer (3.2.13)
< * actionpack (3.2.13)
< * activemodel (3.2.13)
< * activerecord (3.2.13)
< * activeresource (3.2.13)
< * activesupport (3.2.13)
---
> * actionmailer (3.2.12)
> * actionpack (3.2.12)
@yesmeck
yesmeck / core.sh
Last active December 26, 2018 14:30
Sunspot create solr core
# 假设新建一个叫 core1 的 core
mkdir -p /path/to/core1/data
cd /path/to/project
cp -r `bundle show sunspot_solr`/solr/solr/conf /path/to/core1
bundle exec rake sunspot:solr:start
@yesmeck
yesmeck / tor_note.txt
Last active April 23, 2017 21:32
Tor note
# 更换身份
> telnet localhost 9051
AUTHENTICATE
SETCONF ExitNodes={us}
SETCONF StrictNodes=1
SIGNAL NEWNYM
QUIT
Or
@yesmeck
yesmeck / dump.txt
Created August 7, 2013 01:55
gvim crash info
*** buffer overflow detected ***: gvim terminated
======= Backtrace: =========
/usr/lib/libc.so.6(__fortify_fail+0x37)[0x7f681dd17e67]
/usr/lib/libc.so.6(+0xf9070)[0x7f681dd16070]
/usr/lib/libc.so.6(+0xfadd7)[0x7f681dd17dd7]
gvim[0x5206a5]
gvim(mch_call_shell+0x577)[0x522297]
gvim(call_shell+0x6d)[0x4ec86d]
gvim(do_shell+0xe3)[0x47bc33]
gvim(ex_make+0x298)[0x529b88]
@yesmeck
yesmeck / README.md
Last active December 21, 2015 14:29
简体中文检测

Put pre-commit and han.yml under /path/to/project/.git/hooks.

@yesmeck
yesmeck / Gemfile
Created October 6, 2013 21:44
Rails 4 + Compass
source 'https://rubygems.org'
gem 'rails', '4.0.0'
gem 'mysql2'
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
#gem 'turbolinks'
gem 'jbuilder', '~> 1.2'
@yesmeck
yesmeck / role_constraint.rb
Created October 19, 2013 19:21
Rails 4 user role constraint
# app/constraints/role_constraint.rb
class RoleConstraint
def initialize(*roles)
@roles = roles.map { |r| r.to_s }
end
def matches?(request)
@roles.include? request.env['warden'].user(:user).try(:role)
end
end