Fork me on GitHub
Skip to content

第一次拍夜景

27-Feb-12
IMG_9129 by Kenziii Ma
IMG_9129, a photo by Kenziii Ma on Flickr.

Happy my birthday

18-Nov-11
IMG_5618 by kenziiima
IMG_5618, a photo by kenziiima on Flickr.

Disable guest icon in login for Mac OS 10.7.2

14-Oct-11

Tick below:

[update]Terminal Prompt

16-Sep-11
#curl https://raw.github.com/git/git/master/contrib/completion/git-completion.bash > ~/.git-completion.bash
source ~/.git-completion.bash

############################################
# Modified from emilis bash prompt script
# from https://github.com/emilis/emilis-config/blob/master/.bash_ps1
#
# Modified for Mac OS X by
# @corndogcomputer
# Customize colors by
# @kenziii
###########################################
# Fill with minuses
# (this is recalculated every time the prompt is shown in function prompt_command):
fill="--- "

WHITE='\[\033[1;37m\]'
GREEN='\[\033[0;32m\]'
CYAN='\[\033[0;36m\]'
GRAY='\[\033[0;37m\]'
BLUE='\[\033[0;34m\]'
reset_style='\[\033[00m\]'
status_style=$reset_style'\[\033[0;90m\]' # gray color; use 0;37m for lighter color
prompt_style=$reset_style
command_style=$reset_style'\[\033[1;29m\]' # bold black

# Prompt variable:
PS1="$status_style"'$fill \t\n'"$prompt_style"'${debian_chroot:+($debian_chroot)}\u@\h:\w\ '"$CYAN"'$(__git_ps1 "(%s)")'"$prompt_style"' $'"$command_style "
# Reset color for command output
# (this one is invoked every time before a command is executed):
trap 'echo -ne "\033[00m"' DEBUG
function prompt_command {
	# create a $fill of all screen width minus the time string and a space:
	let fillsize=${COLUMNS}-9
	fill=""
	while [ "$fillsize" -gt "0" ]
	do
		fill="-${fill}" # fill with underscores to work on
		let fillsize=${fillsize}-1
	done
	# If this is an xterm set the title to user@host:dir
	case "$TERM" in
		xterm*|rxvt*)
		bname=`basename "${PWD/$HOME/~}"`
		echo -ne "\033]0;${bname}: ${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"
		;;
		*)
		;;
	esac
}
PROMPT_COMMAND=prompt_command

Charcoal After Hair Cutting

05-Sep-11
IMG_5096 by kenziiima
IMG_5096, a photo by kenziiima on Flickr.

[rails] download file snippet

31-Aug-11

def download function first

def download full_url, to_here
    require 'open-uri'
    open(to_here, 'wb') do |file|
      file << open(full_url).read
    end
end

Use 'tmpdir' to save file or give a target directory

require 'tmpdir'
filename = Pathname.new(url).basename
dst = File.join(Dir.tmpdir, filename.to_s)
download url, dst

[rails]weibo api oauth example

19-Aug-11

in Gemfile add

gem "oauth", ">= 0.3.6"

go to this project directory, and run follow command in Terminal

bundle install

create a weibo controller by follow command

rails g controller weibo

and follow is example

require 'oauth/consumer'
class WeiboController < ApplicationController
  def authorize
    if params[:oauth_verifier] then
      request_token = OAuth::RequestToken.new(
        consumer,
        session[:request_token],
        session[:request_token_secret]
      )
      access_token = request_token.get_access_token(:oauth_verifier=>params["oauth_verifier"])
      @this_access_token = access_token.token
      @this_access_token_secret = access_token.secret

      access_token = OAuth::AccessToken.new(consumer, @this_access_token, @this_access_token_secret)
      @response = access_token.get(@url)
    else
      @request_token=consumer.get_request_token
      session[:request_token] = @request_token.token
      session[:request_token_secret] = @request_token.secret
      redirect_to @request_token.authorize_url(:oauth_callback => weibo_authorize_url)
    end
  end
private
  def consumer
    ::OAuth::Consumer.new('key', 'secret', :site => "http://api.t.sina.com.cn")
  end
end

Some Mac OS Lion shortcuts and effects

02-Aug-11
  • DashBoard: select a widget, press command+r
  • Launchpad: press command+b
  • Launchpad: press command+m, then slide left or right

Update:

  • Mission Control: press `
  • Mission Control: swipe up with two fingers on application window
  • Finder: command+c, then command+option+v = cut & paste

Uninstall RVM

01-Aug-11
rvm implode
sudo rm -r /usr/local/rvm
sudo rm /etc/rvmrc

git completion on Mac and Terminal Prompt

18-Jul-11
curl https://raw.github.com/git/git/master/contrib/completion/git-completion.bash > .git-completion.bash

Open ~/.profile, insert those:

source ~/.git-completion.bash
function prompt
{
local WHITE="\[\033[1;37m\]"
local GREEN="\[\033[0;32m\]"
local CYAN="\[\033[0;36m\]"
local GRAY="\[\033[0;37m\]"
local BLUE="\[\033[0;34m\]"
local CLEAR="\[\e[0m\]"
export PS1="
${GREEN}\u${CYAN}@${BLUE}\h ${CYAN}\w"' $(__git_ps1 "(%s)") '"${CLEAR}"
}
prompt