Skip to content

Instantly share code, notes, and snippets.

@lg0
lg0 / fibonacci.sml
Last active Dec 26, 2015
Standard ML
View fibonacci.sml
(* 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 Jan 11, 2018
show/hide iTerm2 Dock icon
View toggleiTerm2icon
# 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 Sep 23, 2012
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.
View Default (OSX).sublime-keymap
[
{ "keys": ["ctrl+n"], "command": "move", "args": {"by": "lines", "forward": true} }
]
@lg0
lg0 / index.html
Created Sep 4, 2012
Depth of field effect on hover. Based on PNGs with alpha transparency and SVG filters in CSS3. Currently only works in Chrome.
View index.html
<!-- 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 Aug 27, 2012
Toggle VPN on/off and add/clean vpn routes
View gist:3490009
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 Oct 9, 2015
解决 OSX 上原生 VPN (Cisco IPSec)每隔一小时要求输入密码的情况
View gist:3481797

解决方案来自:[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 Apr 20, 2012
applescript:get selected filename and extension
View filename.applescript
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 Apr 10, 2012
Markdown Syntax Highlighting for Sublime text 2
View markdown.xml
<!-- 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 Apr 4, 2012
modify Terminal Prompt and cloor,enable ls 256 color
View bash_profile.txt
# 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 Mar 28, 2012
为octopress博客侧边栏添加 Related Post
View related.html