Skip to content

Instantly share code, notes, and snippets.

@lg0
lg0 / fibonacci.sml
Last active December 26, 2015 00:39
Standard ML
(* Traditional (not tail-recursive) *)
fun fibonacci n =
case n of
0 => 0
| 1 => 1
| _ => fibonacci(n-1) + fibonacci(n-2)
(* tail-recursive *)
fun fbnc_tail n =
let fun aux (n, n_1, n_2) =
@lg0
lg0 / toggleiTerm2icon
Last active January 11, 2018 02:51
show/hide iTerm2 Dock icon
# toggle iTerm Dock icon
# add this to your .bash_profile or .zshrc
function toggleiTerm() {
pb='/usr/libexec/PlistBuddy'
iTerm='/Applications/iTerm.app/Contents/Info.plist'
echo "Do you wish to hide iTerm in Dock?"
select ync in "Hide" "Show" "Cancel"; do
case $ync in
'Hide' )
@lg0
lg0 / Default (OSX).sublime-keymap
Created September 23, 2012 15:20
fix keyboard shortcut [control+n], move cursor to next line for sublime text 2 on mac osx(open new file by default), just like [control+p] move up one line.
[
{ "keys": ["ctrl+n"], "command": "move", "args": {"by": "lines", "forward": true} }
]
@lg0
lg0 / index.html
Created September 4, 2012 14:11
Depth of field effect on hover. Based on PNGs with alpha transparency and SVG filters in CSS3. Currently only works in Chrome.
<!-- This depth of field effect uses SVG filters in CSS3 it currently only works in Chrome -->
<div id="photoframe">
<img id="full" src="https://dl.dropbox.com/u/32918455/camera%20pics/full.png" />
<img class="blurable" data-blurindex="10" id="fullblur" src="https://dl.dropbox.com/u/32918455/camera%20pics/full.png" />
<img class="blurable" data-blurindex="8" id="lenses" src="https://dl.dropbox.com/u/32918455/camera%20pics/lens.png" />
<img class="blurable" data-blurindex="6" id="cameras" src="https://dl.dropbox.com/u/32918455/camera%20pics/camera.png" />
<img class="blurable" data-blurindex="4" id="film" src="https://dl.dropbox.com/u/32918455/camera%20pics/film.png" />
<img class="blurable" data-blurindex="2" id="filters" src="https://dl.dropbox.com/u/32918455/camera%20pics/filters.png" />
<img class="blurable" data-blurindex="0" id="loupes" src="https://dl.dropbox.com/u/32918455/camera%20pics/loupe.png" usemap="loupemap" />
<map id="loupemap" name="loupemap">
@lg0
lg0 / gist:3490009
Created August 27, 2012 16:19
Toggle VPN on/off and add/clean vpn routes
on vpnToggle(vpnName)
tell application "System Events"
tell current location of network preferences
set VPNservice to service vpnName
set isConnected to connected of current configuration of VPNservice
if isConnected then
disconnect VPNservice
do shell script "./ip-down" with administrator privileges
else
do shell script "./ip-up" with administrator privileges
@lg0
lg0 / gist:3481797
Last active October 9, 2015 09:37
解决 OSX 上原生 VPN (Cisco IPSec)每隔一小时要求输入密码的情况

解决方案来自:[Apple Support Communities] (https://discussions.apple.com/thread/3275811?start=0&tstart=0)

  1. 连接 VPN Cisco IPSec (让系统生成配置文件)
  2. 拷贝配置文件到/etc/racoon打开终端执行:
    $ sudo cp /var/run/racoon/xxx.xxx.xxx.xxx.conf /etc/racoon
  3. 修改 racoon 配置文件:
    $ sudo vim /etc/racoon/racoon.conf
  4. 将最后一行注释掉(目的是不使用系统生成配置):
    # include "/var/run/racoon/*.conf" ;
  5. 将下面一行添加到文件末尾,包含分号(使用定制的配置文件):
@lg0
lg0 / filename.applescript
Created April 20, 2012 15:57
applescript:get selected filename and extension
tell application "Finder" to set theFile to POSIX path of (selection as alias)
tell application "Finder" to set fileExtension to name extension of (selection as alias)
@lg0
lg0 / markdown.xml
Created April 10, 2012 19:58
Markdown Syntax Highlighting for Sublime text 2
<!-- copy this to YOUR_THEME.tmTheme-->
<dict>
<key>name</key>
<string>diff: deleted</string>
<key>scope</key>
<string>markup.deleted</string>
<key>settings</key>
<dict>
<key>background</key>
<string>#EAE3CA</string>
@lg0
lg0 / bash_profile.txt
Created April 4, 2012 12:14
modify Terminal Prompt and cloor,enable ls 256 color
# copy to ~/.bash_profile
#
# xTerm-256color
export LS_OPTIONS='--color=auto'
export CLICOLOR='Yes'
export LSCOLORS='Exfxcxdxbxegedabagacad'
# Modify Terminal Prompt and Color
case $(id -u) in
0)
@lg0
lg0 / related.html
Created March 28, 2012 13:33
为octopress博客侧边栏添加 Related Post