Skip to content

Instantly share code, notes, and snippets.

@xbin999
xbin999 / convert to mp3.workflow
Last active March 30, 2017 04:29
convert to mp3
for f in "$@"
do
echo "`basename $f`" >> /tmp/echo.log
/usr/local/bin/ffmpeg -i "$f" "${f%.*}.mp3"
done
@xbin999
xbin999 / qiniu_md
Last active August 29, 2015 14:10
为七牛云存储上传的文件日志显示图像的markdown格式
# only display markdown result
/Users/yangbin/bin/qrsync /Users/yangbin/bin/qiniu-conf.json 2>&1 | grep "Put" | awk -F"[:]" '{printf "![](http://xbin999.qiniudn.com/%s )\n", $6 }'
# replace the original log with markdown format
/Users/yangbin/bin/qrsync /Users/yangbin/bin/qiniu-conf.json 2>&1 |sed -e 's/\(=> xbin999:\)\(.*\)/=> ![](http:\/\/xbin999.qiniudb.com\/\2\)/'
@xbin999
xbin999 / gist:563b35592714d3625e41
Created September 18, 2014 07:45
replace specified string in files
grep -- "- tools" *.md | awk -F"[:]" '{print $1;}'|xargs sed -ig 's/-\ tools/-\ tool/g'
@xbin999
xbin999 / db2z.rb
Created September 1, 2014 11:58
从豆瓣购书单中挑出有亚马逊促销的书籍
# encoding:utf-8
require 'net/http'
require 'uri'
def fetch(uri_str, limit = 10)
# You should choose better exception.
raise ArgumentError, 'HTTP redirect too deep' if limit == 0
url = URI.parse(uri_str)
req = Net::HTTP::Get.new(url.request_uri)
@xbin999
xbin999 / howto.md
Created February 19, 2014 08:24 — forked from leomelzer/howto.md

How To

  1. Install homebrew if you don't have it already: http://mxcl.github.com/homebrew/
  2. Run brew install vpnc --hybrid
  3. Check if you already have virtual tunnel interfaces, run ls /dev/tun*. If there are none, install "Tun Tap OSX" (see below)
  4. Go to https://www.rz.uni-konstanz.de/angebote/e-mail/usermanager/ and login, then download both the certificate (you need the .pem file) and vpn profile
  5. Run openssl x509 -in <certificateFile>.pem -noout -hash
  6. Rename <certificateFile>.pem to the output of (5) with .pem as extension
  7. Move the .pem certificate to a permanent location, e.g. /etc/ssl/certs/
  8. Open /usr/local/etc/vpnc/default.conf in your favorite text editor, delete the contents
  9. Run pcf2vpnc /.pcf and paste the output to your open text editor
@xbin999
xbin999 / mydu.rb
Created August 6, 2013 09:10
Get disk usage for specified directory. You can specify search depth and limit directory and file size to display.
require 'optparse'
def du(dir, all, depth, dsize, fsize)
return if depth <= 0
value = %x(du -sm \'#{dir}\'/*)
h = Hash.new
value.split("\n").each{ |line|
arr = line.split(' ', 2) # only split into 2 pieces
h[arr[0].to_i] = arr[1]
@xbin999
xbin999 / push.rb
Last active December 16, 2015 17:40
Convert a markdown file to HTML and publish it to wordpress.
#!/usr/bin/ruby
# Convert a Markdown file to HTML with Github Flavored Markdown(refer to https://gist.github.com/ttscoff/3732963), and publish it to wordpress.
#
# Requirements: json gem (`gem install json`)
#
# Input: filename
# Output: STDOUT
# Arguments: "-s" to speify title, -t to specify tags, -c to specify categories
# ruby post.rb -s "title" -t "tag1,tag2" -c "category1,category2" filename
@xbin999
xbin999 / article.rb
Created September 24, 2012 11:25 — forked from Achillefs/article.rb
Sample Article class posting to a Wordpress blog via wp-json-api
require 'rubygems'
require 'open-uri'
require 'json'
require 'net/http'
# Please note that the vanilla wp-json-api plugin does not support user authentication for create_post.
# Check out my fork for authentication support: https://github.com/Achillefs/wp-json-api
class Article
API_URI = 'http://mywpblog.com/api/'
API_USER = 'my_wp_username'
@xbin999
xbin999 / crawler.rb
Created June 19, 2012 09:51
ruby sample
def crawler( http, request_uri, user_regexp)
request = Net::HTTP::Get.new(request_uri)
response = http.request(request)
r = user_regexp.match(response.body.force_encoding('utf-8'))
return r
end