Skip to content

Instantly share code, notes, and snippets.

View xuchunyang's full-sized avatar

Xu Chunyang xuchunyang

View GitHub Profile
@xuchunyang
xuchunyang / hello-emacs-lisp.el
Last active August 29, 2015 14:04
Play with Emacs Lisp
;;; filename: emacs-lisp-basic.el
(+ 23 3)
(message "hi")
;; store variable
(setq my-name "Chunyang Xu")
(setq my-age 21)
(insert "hello" " world")
@xuchunyang
xuchunyang / add-seu-route-linux.sh
Last active August 29, 2015 14:04
添加东南大学校园网静态路由,访问校园网 (GNU/Linux && Mac OS X)
#!/usr/bin/env bash
# add-seu-route-linux.sh - public domain - Chunayng Xu | http://xuchunyang.me
# Program: 添加东南大学路由表 (GNU/Linux version)
# Usage: 添加路由表: sudo add-seu-route.sh
# Note: 使用前需要修改 GATEWAY
GATEWAY=192.168.1.1 # *Change* to your gateway
#-------------------------------------------------------------------------------
# Make sure only root can run our script
@xuchunyang
xuchunyang / add-seu-route.sh
Created August 1, 2014 06:47
修复 Mac 连上 Bras 之后不能访问外网和校内网的问题
#!/usr/bin/env bash
# Program: 添加东南大学路由表 | http://git.io/AOIiRg
# Note: 使用前需要修改 GATEWAY
# Usage: 添加路由表: sudo add-seu-route.sh
# 删除路由表: sudo add-seu-route.sh del
GATEWAY=192.168.7.1 # 修改成你的连接 bras 前的默认网关
#---------------------------------------------------------------
SEU_NETWORKS=(
@xuchunyang
xuchunyang / ydcv.sh
Created September 30, 2014 06:46
ydcv in bash
#!/bin/bash
#
# ydcv in bash using 'jq' to parse json
#
# Check argument
if [ -z $1 ]; then
echo "Usage: $0 word"
exit 1
@xuchunyang
xuchunyang / ydcv.pl
Created September 30, 2014 07:50
ydcv in perl
#!/usr/bin/env perl
#
# ydcv in Perl
#
use strict;
use warnings;
use LWP::UserAgent;
use JSON qw( decode_json );
@xuchunyang
xuchunyang / elisp-demo-01.el
Created December 27, 2014 14:38
elisp-demo-01.el
;; 1. (interactive)
;; "P": prefix argument
;; "B": Buffer name
;; "b": should be a >exiting buffer
;; "r": Point and the mark
;; "*": Signal an error if the current buffer is read-only. Special.
(defun add-by-two (number)
"Add NUMBER by two."
(interactive "P\nbF buffer: ") ; Enable the prefix argument
(message "The result is %d." (+ number 2)))
;; Narrowing -- use save-restriction
(defun my-what-line ()
"Print the current line number (in the buffer) of point."
(interactive)
(save-restriction
(widen)
(save-excursion
(beginning-of-line)
(message "Line %d"
(1+ (count-lines 1 (point)))))))
@xuchunyang
xuchunyang / elisp-demo-03.el
Created December 28, 2014 08:40
elisp-demo-03.el
;; List -- car/cdr/nthcdr/nth
(defvar my-list '(a b c) "My demo LIST")
my-list
(car my-list)
a
(cdr my-list)
(b c)

Learning notes for Emacs Lisp

This is my notes while reading GNU Emacs Lisp Reference Manual.

Lisp Data Types

Type 可以重叠

一个 Lisp “object” 可以有多个 “type”,因此只会问是否一个 “object” 属不属于哪一个 “type”,而不会问一个 “object” 的 “type” 是什么。

@xuchunyang
xuchunyang / google-trans-cn-curl.sh
Last active August 29, 2015 14:12
google-trans-cn-curl.sh
#!/bin/bash
#
# Filename: google-trans-cn-curl.sh
# Program: Access https://translate.google.cn/ from command line by 'curl(1)'
# Usage: ./google-trans-cn-curl.sh <text>
#
text="$1"
if [[ -z "$text" ]]; then
echo "Usage: $0 <word>"