Skip to content

Instantly share code, notes, and snippets.

@cyfdecyf
cyfdecyf / closure-wrap-function.c
Created February 27, 2011 07:41
Examples to wrap function in C in different ways (workable or not)
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
// This code can now only work on Linux system.
// It has some problem on OS X. Maybe I'll fix it someday.
#if __WORDSIZE != 64 || !defined(__x86_64__)
#error "This program only works on IA64 machine."
@cyfdecyf
cyfdecyf / gist:992733
Created May 26, 2011 07:50
dnsmasq configuration for local DNS server
We couldn’t find that file to show.
@cyfdecyf
cyfdecyf / appstore-avgtime.rb
Created July 22, 2011 12:07
Find fast app store download servers
#!/usr/bin/env ruby
# Run the following commands to find the fastest server.
#
# ./appstore-avgtime.rb > speed
# sort -n speed | head -n 10
STDOUT.sync = true
def pingavg(url, count = 10)
@cyfdecyf
cyfdecyf / extractlink.sh
Created July 31, 2011 11:06
A small script to extract all the href links from a web page.
@cyfdecyf
cyfdecyf / xp-cleanup.bat
Created October 3, 2011 15:17
xp clean up script
@echo off
echo cleaning up, please wait......
del /f /s /q %systemdrive%\*.tmp
del /f /s /q %systemdrive%\*._mp
del /f /s /q %systemdrive%\*.log
del /f /s /q %systemdrive%\*.gid
del /f /s /q %systemdrive%\*.chk
del /f /s /q %systemdrive%\*.old
del /f /s /q %systemdrive%\recycled\*.*
del /f /s /q %windir%\*.bak
@cyfdecyf
cyfdecyf / addressbook-macruby.rb
Created November 3, 2011 14:47
Using MacRuby to operate the Address Book contacts
#!/usr/bin/env ruby
# For contacts which have only the first name, move the first name to last name
framework 'AddressBook'
def move_first2last(person)
first = person.valueForProperty(KABFirstNameProperty)
last = person.valueForProperty(KABLastNameProperty)
@cyfdecyf
cyfdecyf / migrate.rb
Created December 12, 2011 14:32 — forked from zellux/migrate.rb
Migrate from wordpress to octopress
# coding: utf-8
require 'rubygems'
require 'hpricot'
require 'fileutils'
require 'time'
require 'ya2yaml'
require 'nokogiri'
require 'cgi'
@cyfdecyf
cyfdecyf / downcase-filter.patch
Created December 13, 2011 07:20
Liquid filter to downcase encoded url
diff --git a/plugins/octopress_filters.rb b/plugins/octopress_filters.rb
index a5bb235..928333b 100644
--- a/plugins/octopress_filters.rb
+++ b/plugins/octopress_filters.rb
@@ -126,6 +126,9 @@ module OctopressLiquidFilters
input.titlecase
end
+ def downcase_escaped_url(input)
+ input.gsub(/%(\d|[ABCDEF]){2}/) { |mat| mat.downcase }
@cyfdecyf
cyfdecyf / join-chinese.rb
Created December 18, 2011 09:12
Join consecutive Chinese lines into a single long line.
#!/usr/bin/env ruby
#encoding: UTF-8
# Requires ruby 1.9.x, and assumes UTF-8 encoding
class String
# The regular expression trick to match CJK characters comes from
# http://stackoverflow.com/a/4681577/306935
# For more info on the regex used here, refer to http://oniguruma.rubyforge.org/svn/Syntax.txt
# And for Unicode Character Categories http://www.fileformat.info/info/unicode/category/index.htm
@cyfdecyf
cyfdecyf / log
Created December 22, 2011 14:31
人人网找回密码出错页面给出的log
/common/menu/stepBar/?pos=1&step=1
500 POST /common/menu/stepBar/; nested exception is java.lang.reflect.InvocationTargetException: [Rose-1.0.1-20100805@Spring-2.5.6.SEC02]Error happended: POST /common/menu/stepBar/->String stepBar(Invocation, int, int) params=[/common/menu/stepBar/, 1, 1]
org.springframework.web.util.NestedServletException: POST /common/menu/stepBar/; nested exception is java.lang.reflect.InvocationTargetException: [Rose-1.0.1-20100805@Spring-2.5.6.SEC02]Error happended: POST /common/menu/stepBar/->String stepBar(Invocation, int, int) params=[/common/menu/stepBar/, 1, 1]
at net.paoding.rose.RoseFilter.throwServletException(RoseFilter.java:546)
at net.paoding.rose.RoseFilter.doFilter(RoseFilter.java:344)
at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:70)
at com.caucho.server.webapp.DispatchFilterChain.doFilter(DispatchFilterChain.java:115)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:229)
at com.caucho.server.webapp.Requ