Skip to content

Instantly share code, notes, and snippets.

View celadevra's full-sized avatar

徐栖 Xuqi celadevra

View GitHub Profile
@celadevra
celadevra / 11.4.el
Created November 28, 2011 07:39
Code Examples and Exercises
; Write a function similar to `triangle' in which each row has a value which is the square of the row number. Use a `while' loop.
(defun square-triangle (number-of-rows)
"Calculate the total number of pebbles in a triangle where the number of
pebbles in each row is the square of the number of the row."
(let ((total 0)
(row-number 1))
(while (<= row-number number-of-rows)
(setq total (+ total (* row-number row-number)))
(setq row-number (1+ row-number)))
@celadevra
celadevra / pythonexec.rb.patch
Created May 27, 2012 06:45
Make Octopress's rubypython 0.5.3 work with newer Python in Gentoo 12.0
1c31
< @library = find_python_lib
---
> @library = 'python2'
126c126
< %x(#{@python} -c "#{command}").chomp if @python
---
> %x("#{@python} -c #{command}").chomp if @python
@celadevra
celadevra / ip-up.sh
Created July 31, 2012 03:12
Fix chnroute minor bug under mac
# If you use chnroutes.py generated ip-up to add to route table addresses
# that don't route through VPN, you may encounter error saying
# "bad address:\n $yourgateway" where $yourgateway is the gate way for
# non-VPN addresses. This is because the \n is not accepted by OS X's route
# command. Just remove the \n with another sed command:
OLDGW=`netstat -nr | grep '^default' | grep -v 'ppp' | sed 's/default *\([0-9\.]*\) .*/\1/' | sed '/^$/d'`
@celadevra
celadevra / coursera_PL_course_notes.org
Last active December 14, 2015 23:48
Course Notes for the Coursera Programming Languages Course

Concepts

Values

Values are expressions that cannot be further simplified. Thus all values are expressions, but expressions are not always values.

Static vs. Dynamic

Functional vs. Object Oriented

One very powerful feature of functional language is that the contents of a binding cannot be changed. You may shadow a variable but the original variable name in the original environment will always point to the original expression. This is called immutability.

Type inference

As SML uses pattern-matching to process arguments passed to the function in the form of tuples, it is not necessary to write types for each member of the tuple.

Type-check vs. Ducktyping

Polymorphic

@celadevra
celadevra / main.css
Last active December 16, 2015 14:39
My Scriptogr.am HTML and CSS
/* HTML5 Boilerplate */
article, aside, details, figcaption, figure, footer, header, hgroup, nav, section { display: block; }
audio, canvas, video { display: inline-block; *display: inline; *zoom: 1; }
audio:not([controls]) { display: none; }
[hidden] { display: none; }
html { font-size: 100%; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; }
html, button, input, select, textarea { font-family: sans-serif; color: #222; }
body { margin: 0; font-size: 1em; line-height: 1.4; }
@celadevra
celadevra / patch-1.5.21.tt.create_rfc2047_params.1.patch
Last active July 30, 2017 03:06
Enable mutt 1.5.21 to send attachments conforming to RFC 2047
diff -uNr mutt-1.5.21.orig/PATCHES mutt-1.5.21/PATCHES
--- mutt-1.5.21.orig/PATCHES 2008-03-20 04:07:06.000000000 +0800
+++ mutt-1.5.21/PATCHES 2013-05-28 14:12:57.000000000 +0800
@@ -0,0 +1 @@
+patch-1.5.21.tt.create_rfc2047_params.1
diff -uNr mutt-1.5.21.orig/init.h mutt-1.5.21/init.h
--- mutt-1.5.21.orig/init.h 2010-09-15 23:39:31.000000000 +0800
+++ mutt-1.5.21/init.h 2013-05-28 10:50:19.000000000 +0800
@@ -419,6 +419,18 @@
** characters as question marks which can lead to undesired
@celadevra
celadevra / mutt.rb
Created May 28, 2013 06:45
Updated Homebrew Formula mutt.rb
require 'formula'
class Mutt < Formula
homepage 'http://www.mutt.org/'
url 'ftp://ftp.mutt.org/mutt/devel/mutt-1.5.21.tar.gz'
sha1 'a8475f2618ce5d5d33bff85c0affdf21ab1d76b9'
option "with-debug", "Build with debug option enabled"
option "with-sidebar-patch", "Apply sidebar (folder list) patch"
option "with-trash-patch", "Apply trash folder patch"
@celadevra
celadevra / timestampseries.el
Created October 2, 2013 00:51
Generate a series of org-style time stamps, can be used with org-capture-templates. Easing daily time planning.
(defun org-install-series-time-stamp (a b)
"For inserting a morning diary using org's template system.
At the function call, it calls org-insert-time-stamp to
insert a series of active time stamps, one line each. The
function is called with 2 parameters: a hour of the
work day and the b, in the form of int N and M.
i.e. (org-install-series-time-stamp 9 18)"
()
(cond ((< b a) (org-install-series-time-stamp b a))
@celadevra
celadevra / badifier.rb
Created November 24, 2013 03:35
Make your name look like one from the Breaking Bad staff :) #ruby
class String
def green; "\033[32m#{self}\033[0m" end
end
elements = ["he", "li", "be", "ne", "na", "mg", \
"al", "si", "cl", "ar", "ca", "sc", "ti",\
"cr", "mn", "fe", "co", "ni", "cu", "zn",\
"ga", "ge", "as", "se", "br", "kr", "rb",\
"sr", "zr", "nb", "mo", "tc", "ru", "rh",\
"pd", "ag", "cd", "in", "sn", "sb", "te",\
@celadevra
celadevra / get_uniq_char.rb
Last active July 30, 2017 03:03
Filter out uniq Chinese characters used in a text file. #ruby
#!/usr/bin/env ruby
everything = ""
chars, charcodes = ""
File.open("main.md", "r") do |file|
while line = file.gets
everything << line
end
chinese_only = everything.gsub(/[\*()%:<>\-\/#\.\+\{\}!\[\]\s\w]+/, '')
chinese_array = chinese_only.scan(/./)