Skip to content

Instantly share code, notes, and snippets.

View quwubin's full-sized avatar

Wubin Qu quwubin

View GitHub Profile
@quwubin
quwubin / remove_blank_line.rb
Created June 8, 2012 01:31
Ruby: Remove blank lines and leading ^M characters
#!/usr/bin/env ruby
#
# Wubin Qu <quwubin@gmail.com>
#
if ARGV.size != 1
$stderr.puts "
Remove blank lines and leading ^M characters
Usage:
@quwubin
quwubin / biodb.rb
Created June 12, 2012 07:34
Download database from NCBI
#!/usr/bin/env ruby
#
# Wubin Qu <quwubin@gmail.com>
require 'fileutils'
module Biodb
module DbProcess
attr_reader :ftp_address, :dir
attr_accessor :available_dbs
@quwubin
quwubin / batch_run.rb
Created July 11, 2012 03:03
Ruby tips
#!/usr/bin/env ruby
ARGV[1..-1].each do |file|
puts file
`#{ARGV[0]} #{file}`
end
# Example
# ./batch_run.rb "tar zxvf" refseq_genomic.*.gz
@quwubin
quwubin / gist:3747136
Created September 19, 2012 01:39 — forked from Amitesh/gist:1160287
Word wrap in Ruby
# It works for pure text only. It will fail for html and url type of text.
# http://henrik.nyh.se/2007/03/ruby-wordwrap-method
def wrap_long_string(text,max_width = 20, separator = "\n")
(text.length < max_width) ?
text :
text.scan(/.{1,#{max_width}}/).join(separator)
end
@quwubin
quwubin / 360buy.rb
Created November 5, 2012 00:52 — forked from mimosz/.gitignore
京东商品价格解析
# -*- encoding: utf-8 -*-
require 'mini_magick'
require 'rtesseract'
require 'nokogiri'
require 'nestful'
require 'csv'
require 'pp'
class Buy360
def initialize(url='')
@quwubin
quwubin / st2_user_settings.txt
Last active December 14, 2015 03:48
Sublime text 2 Use Settings
// Settings in here override those in "Default/Preferences.sublime-settings", and
// are overridden in turn by file type specific settings.
{
"tab_size": 2,
"translate_tabs_to_spaces": true,
"default_line_ending": "unix",
"highlight_line": true,
"word_wrap": "true",
"font_size": 12
}
@quwubin
quwubin / parse_and_stats_medline.rb
Created February 24, 2013 13:39
Parse and statistics Medline (PubMed) abstract files
require 'bio'
# Input is abstract file in Medline format.
year_count = Hash.new(0)
File.read(ARGV[0]).split("\n\n").each do |article_block|
article = Bio::MEDLINE.new(article_block)
year_count[article.year] += 1
end
year_count.each do |year, count|
puts "#{year}, #{count}"
@quwubin
quwubin / get_free_memory
Created January 28, 2014 15:18
Get machine free memory both on Mac OS and Linux.
#!/usr/bin/python
# Author: Wubin Qu <quwubin@gmail.com>
# Tue Jan 28 23:17:08 2014
import platform
import subprocess
import re
def get_free_memory():
@quwubin
quwubin / CairoNumberWidth.py
Created March 21, 2014 02:09
Virtual electrophotogram
#!/home/zhangcg/local/python/bin/python
# -*- coding:utf-8 -*-
#-----------------------------------------------------
# File: CairoNumberWidth.py
# Date: 2008-07-04
# Description:
#-----------------------------------------------------
__version__ = '1.0'
@quwubin
quwubin / delete_empty_dir
Created March 25, 2014 01:17
Delete the empty directory
#!/usr/bin/env ruby
Dir.foreach('./') do |dir|
next unless File.directory?(dir)
next if ['.', '..'].include?(dir)
if Dir.entries(dir) == ['.', '..']
Dir.delete(dir)
end
end