立方根程序

SICP, 1.8, page17

#!/usr/bin/env racket
#lang racket

(define (root-iter guess x)
    (if (good guess x)
    	guess
	(root-iter (improved guess x) x)))

(define (good y x)
    (< (abs (- (* y y y) x)) 0.001))

(define (improved y x)
    (/ (+ (/ x y y) (+ y y)) 3))

(define (root x)
    (root-iter 1 x))

(root 30000.001)

Fill in vpn token

 

activate application "SystemUIServer"
tell application "System Events"
	tell process "SystemUIServer"
		
		set x to item 3 of menu bar items of menu bar 1
		tell x
			click
			click menu item "Connect Cisco VPN" of front menu
			delay 3
			keystroke token
			keystroke return
		end tell
	end tell
end tell

 

gen tokens with apple script

 

set tokens to ""
tell application "System Events" to tell process "SofToken II"
	tell application "SofToken II" to activate
	delay 1
	keystroke "***"
	delay 1
	repeat 10 times
		keystroke return
		set token to the clipboard
		set tokens to tokens & "\r" & token
		delay 1
	end repeat
end tell

tokens

 

mac tips

  • 刷新DNS sudo dscacheutil -flushcache

  • 在终端中打开当前文件夹 open .

 

 

disable vmware compile each time

 

Set VSOCK_CONFED = "no" in /etc/vmware/config

via http://resalxh.wordpress.com/2010/09/09/vmware-player-3-1-1-on-ubuntu-10-10-maverick-meerkat/

duckhood-checking

from python cookbook. How to check a variable is String or not.

如果它走路像鸭子,叫声也像鸭子,那么对于我们而言,就可以认为它是鸭子了。

Read more

javascript cookie simple solution

3 functions are borrowed from Here

Read more

jquery: bind key events

as subject.

Read more

linux tips

  • 查看硬件信息:sudo lshw  #ls hardware
  • 查看CPU位数32/64:getconf LONG_BIT #longest integer bit.
  • 快速建立文件服务器并显示自已的IP:ifconfig |grep  -oP "(?<=inet addr:)[0-9.]+" |grep -v 127.0.0.1 | sed "s/\$/:8000/"  && python -m SimpleHTTPServer
  • resize image: convert source -resize '100x200' dest
     

run python function as daemon

simply wrap it with threading.

Read more