Skip to content

Instantly share code, notes, and snippets.

@venj
venj / unpack.rb
Created October 19, 2011 09:55
This is a simple script to batch unpack and rename books downloaded from "that" ebook site. If you are want to know about "my rename ..." command, pay a visit to https://gist.github.com/1149120
#!/usr/bin/env ruby
require "fileutils"
PUBS = ["Oreilly", "Microsoft Publication",
"Sitepoint", "Apress"]
def normalize(name)
n = name.gsub(/\w{3,4}\.[0-9]{4}$/, "").gsub(/\.\w+\.Edition/i, "").gsub(/[^[:alnum:]]/, " ")
PUBS.each do |p|
r = Regexp.new(p, true)
@venj
venj / transcode.sh
Created September 28, 2011 03:10
a simple bash wrap for iconv.
#!/bin/bash
usage() {
echo Usage: `basename $0` from_encoding to_encoding file_or_dir_to_transcode
}
if [ $# -ne 3 ]; then
usage
exit 1
fi
@venj
venj / getpics.rb
Created September 20, 2011 16:16
Yet another script for grab pictures....
#!/usr/bin/env ruby
require "rubygems"
require "open-uri"
require "fileutils"
require "hpricot"
(puts "Usage: #{File.basename $0} http://link.to.webpage" ; exit 1) if ARGV.size != 1
begin
imagedir = "images"
@venj
venj / parseXML.rb
Created September 5, 2011 09:11
Ruby version of parsexml
#!/usr/bin/env ruby
def parse(f)
buffer = ""
open(f) { |file| file.seek 0x404;file.each_byte {|c| buffer << (0xff - c).chr} }
rindex = buffer.rindex(/<\/word>/) + "</word>".size
open(f.sub(".ydic", ".xml"), "w+").write(buffer[0...rindex].gsub("</word>", "</word>\n"))
end
(puts "Usage: #{File.basename $0} dict_file_1 [...]";exit 1) if ARGV.size < 1
@venj
venj / ydDumper.py
Created September 5, 2011 07:53
a small change to original ydDumper.py
#!/usr/bin/env python
#This Python file uses the following encoding: utf-8
#Author:Superfan
#Version 1.0
#Latest Update:July,31,2011
#Usage:This script will convert youdao dictonary(plus version) to Mdict source file,put it in the same directory which offline glossories exist, and run it with python VM.
#This script is for STUDY use ONLY.DO NOT USE IT FOR ANY COMMERCIAL PURPOSE!!!
# Small changes by Venj, 2011-09-05
from __future__ import division
@venj
venj / exportXML.py
Created September 5, 2011 06:48
parse raw dict file to xml
from __future__ import division
import sys,os
def decrypt(str):
i=0
tmp=''
try:
while True:
tmp+=chr((255-ord(str[i]))) #XD
i+=1
@venj
venj / NSWindow+Extension.m
Created September 4, 2011 06:11
Resize Window
/* NSWindow+Extension.h */
#import <Foundation/Foundation.h>
@interface NSWindow(Extension)
- (void)resizeTo:(NSSize)newSize display:(BOOL)display animated:(BOOL)animated;
- (void)resizeTo:(NSSize)newSize;
@end
@venj
venj / repack_epub.rb
Created September 3, 2011 04:37
Repack ePubs that can not show a correct cover image in iTunes and iBooks for iOS.
#!/usr/bin/env ruby
require "fileutils"
include FileUtils
ERROR = 255
def repack(book, tmpdir)
book_name = File.basename(book, ".epub")
system(%|unzip "#{book}" -d #{tmpdir} > /dev/null 2>&1|)
cd(tmpdir) do
@venj
venj / split.rb
Created August 25, 2011 13:06
Split a image into two halves.
#!/usr/bin/env ruby
require "fileutils"
(puts "Usage: #{File.basename $0} widthxheight"; exit 0) if ARGV.size != 1
width, height = ARGV[0].split("x").collect(&:to_i)
(puts "Please enter a valid size."; exit 0) if ((width.to_i == 0) or (height.to_i == 0))
half_width = width / 2
FileUtils.cd("images") do
Dir['**/*'].each do |f|
@venj
venj / iOS System Fonts.txt
Created August 21, 2011 08:02
iOS System Fonts
American Typewriter:
AmericanTypewriter
AmericanTypewriter-Bold
Apple Color Emoji:
AppleColorEmoji
AppleGothic:
AppleGothic