Skip to content

Instantly share code, notes, and snippets.

View duxins's full-sized avatar

Xin Du duxins

  • Tokyo, Japan
  • 15:29 (UTC +09:00)
View GitHub Profile
@duxins
duxins / private.xml
Last active November 28, 2015 10:37
Keyboard Remapping
<?xml version="1.0"?>
<root>
<item>
<name>Du Xin's Custom Settings</name>
<item>
<name>OPTION_R+hjkl to Left/Down/Up/Right</name>
<identifier>private.vi_mode</identirider>
<autogen>__KeyToKey__ KeyCode::H, ModifierFlag::OPTION_R, KeyCode::CURSOR_LEFT</autogen>
@duxins
duxins / screenshot.rb
Last active September 18, 2015 01:23
RubyMotion 截屏
# http://paulsturgess.co.uk/blog/2015/02/05/tweeting-a-screenshot-in-rubymotion-with-uiactivityviewcontroller/
def screenshot
window = UIApplication.sharedApplication.keyWindow
UIGraphicsBeginImageContextWithOptions(
window.bounds.size,
false,
UIScreen.mainScreen.scale
)
window.drawViewHierarchyInRect(
//
// EXPMatches+match.h
// Created by Jonathan Crooke on 25/03/2014.
//
#import "Expecta.h"
/**
* Expect string to match regular expression
*/
@duxins
duxins / Gemfile
Last active August 29, 2015 14:08
Sinatra With Puma
source 'https://rubygems.org'
gem 'sinatra'
gem 'sinatra-contrib'
gem 'puma'
@duxins
duxins / rss.rb
Last active August 29, 2015 14:08
Create RSS Feeds
require('rss')
rss = RSS::Maker.make("atom") do |maker|
maker.channel.author = "Xin Du"
maker.channel.updated = Time.now.to_s
maker.channel.about = "#{@url}"
maker.channel.title = "RSS"
maker.channel.icon = icon_url
maker.channel.logo = icon_url
@duxins
duxins / swift_compile.sh
Created June 3, 2014 07:18
swift: CodeRunnder compilation script
compname=`echo "$1" | sed 's/\(.*\)\..*/\1/'`
/Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift "$1" -o "$compname" -sdk $(xcrun --show-sdk-path --sdk macosx)
status=$?
if [ $status -eq 0 ]
then
echo $compname
exit 0
fi
exit $status
@duxins
duxins / vehicle.c
Last active August 29, 2015 14:01
vehicle
#include <stdio.h>
#include <string.h>
#include <limits.h>
#define PERCENTAGE 1
#define EXPECTED_TYPE 700
#define LINK_IS_FIXED 1
#define LINK_NUM 50 //
int link_map[26][8] = {

URL-rewriting for klein PHP router

Why rewrite URLs? Check Wikipedia

Apache

Make sure AllowOverride is on for your directory, or put in httpd.conf

# Apache (.htaccess or httpd.conf)

RewriteEngine On

@duxins
duxins / ubuntu_locale.sh
Created October 17, 2013 13:22
fix ubuntu locale issue
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
sudo locale-gen en_US.UTF-8
sudo dpkg-reconfigure locales
@duxins
duxins / update_centos_cert.sh
Created October 17, 2013 12:53
Update CentOS root certificate
curl http://curl.haxx.se/ca/cacert.pem -o /etc/pki/tls/certs/ca-bundle.crt