Skip to content

Instantly share code, notes, and snippets.

@zellux
zellux / extract.rb
Created July 31, 2013 11:37
Extract words and explanations from epub version of Merriam Webster's Vocabulary Builder. See http://blog.yxwang.me/notes/languages/vocabulary-builder.html for more details.
require 'nokogiri'
unit = ARGV[0].to_i
started = false
titles = []
1.upto(3000) do |i|
filename = "html/Merriam-Webster_s_Vocabulary_Bu_split_#{'%03d' % i}.html"
doc = Nokogiri::HTML(open(filename))
title = doc.css('div span.bold').first
next if title == nil
@zellux
zellux / zhihu.recipe
Last active August 9, 2019 16:50
知乎日报 Kindle 版生成工具,可用于 Calibre
#!/usr/bin/env python
__copyright__ = 'Yuanxuan Wang <zellux at gmail dot com>'
from calibre.web.feeds.news import BasicNewsRecipe
from calibre.ebooks.BeautifulSoup import Tag, NavigableString
from collections import OrderedDict
from contextlib import nested, closing
import json
@zellux
zellux / migrate.rb
Created November 29, 2011 03:10
Migrate from wordpress to octopress
# coding: utf-8
require 'rubygems'
require 'hpricot'
require 'fileutils'
require 'time'
require 'ya2yaml'
require File.join(File.dirname(__FILE__), "downmark_it")
require 'nokogiri'
require 'cgi'
@zellux
zellux / laplacian-smoothing.rb
Created October 29, 2011 16:17
Probability calculator
require 'set'
k = 1.0
list1 = %w(a perfect world my perfect woman pretty woman)
list2 = %w(a perfect day electric storm another rainy day)
ncases1 = 3
ncases2 = 3
list1name = 'movie'
list2name = 'song'
@zellux
zellux / crop.rb
Created October 3, 2011 16:45
chncode book downloader
require 'thread'
require 'logger'
require 'fileutils'
dir_name = ARGV[0] || '707-kindle'
NTHREADS = 4
$logger = Logger.new STDERR
puts "Resizing all images..."
@zellux
zellux / client.c
Created July 1, 2011 03:17
UDP file transfer
#include <string.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <fcntl.h>
#define SERV_PORT 49312
#define MAXLINE 1024
char *END_FLAG = "================END";
@zellux
zellux / gist:867949
Created March 13, 2011 07:19
Katamari Hack
javascript:var i,s,ss=['http://kathack.com/js/kh.js','http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js'];for(i=0;i!=ss.length;i++){s=document.createElement('script');s.src=ss[i];document.body.appendChild(s);}void(0);