Skip to content

Instantly share code, notes, and snippets.

@tokland
tokland / adt.rb
Last active December 24, 2021 03:35
Simple Algebraic Data types for Ruby
#https://gist.github.com/tokland/871431
module Adt
# Build a ADT parent class with its children constructors.
#
# class_names_with_constructors -- Hash of key=class_name, value=constructor_arguments
# class_body -- Body to add to the parent class
#
# Example:
#
@gavinheavyside
gavinheavyside / mapreduce_conway.rb
Created September 19, 2010 20:02
A MapReduce algorithm for Conway's Game of Life
#!/usr/bin/env ruby
require 'rubygems'
require 'wukong'
# Given a file with the coordinate pair of a live cell on each line,
# generate the next iteration of Game of Life, using MapReduce
#
# The map phase takes each live cell, and outputs 9 key value pairs, 1 for
# each of the adjacent cells and itself. The reduce phase dedupes, detects
@wavded
wavded / promise.js
Last active May 6, 2021 13:25
Promise A+ Implementation
"use strict"
var Promise = function () {
this.state = 'pending'
this.thenables = []
}
Promise.prototype.resolve = function (value) {
if (this.state != 'pending') return
this.state = 'fulfilled'

前陣子一直打算謝謝markdown寫作,拖到現在被這位老兄搶了先,很不錯的介紹文章:[为什么Markdown+R有较大概率成为科技写作主流?](http://www.douban.com/note/220903450/).所以我就不再重複了,此文打算用問答的形式介紹下markdown對於文科寫作的意義[^ft]。

###1. 什麼是markdown?

markdown是一種輕量化的標記語言。大家所熟知的標記語言還有latex,lyx, XML,HTML,這類文本的特點就是你在編輯時可以使用各種tag來控制文本的格式。話說回來,mac下的pages,M$的docx也都時XML文檔,只是你在編輯的時候,不需要加入tag,軟件本身替你增加tag了。

這類語言最大的好處就是在編輯時,你可以很大程度的減少格式對於文本的干擾。你想啊,打開一個word文檔,你調個文字大小,設置個 加粗,二號標題,再來個 斜體 什麼的, 時間大半過去了。而標記語言的最大優勢在於,你只要使用系統能夠識別的tag就可以非常方便地控制這些格式。比如markdown,你可以先使用系統默認的那些tag來寫作,等到最後輸出的時候,配置下css模版即可。

markdown是各種標記語言中的小兄弟,一來是因為它年輕,二來因為它非常輕量化。md是 John GruberAaron Swartz 最初發明的,廣泛用於技術文檔的寫作。它的最大優勢在於人機皆可讀 (machine-readble, human-readble)。

@SaitoWu
SaitoWu / gollum.md
Created August 9, 2012 02:46
self host a gollum wiki.

nginx configuration:

user root admin;

worker_processes  1;

# pid of nginx master process
pid /var/run/nginx.pid;
@fnhipster
fnhipster / html5.haml
Created April 9, 2011 01:19
HTML5 HAML Template
!!! 5
%html
%head
%title= "Your Website"
%meta{ :content => "", :name => "description" }
%meta{ :content => "", :name => "author" }
%meta{ :content => "3 days", :name => "revisit-after" }
%link{ :href => "http://creativecommons.org/licenses/by/3.0/", :rel => "license", :title => "Creative Commons Attribution 3.0 Unported License" }
%link{ :href => "/feed", :rel => "alternate", :title => "Atom", :type => "application/atom+xml" }
%link{ :href => "/css/screen.css", :media => "screen", :rel => "stylesheet" }
@gavinheavyside
gavinheavyside / trivial_file_upload_service.rb
Created November 3, 2009 20:09
Trivial file upload service using Sinatra
require 'rubygems'
require 'sinatra'
require 'fileutils'
# upload with:
# curl -v -F "data=@/path/to/filename" http://localhost:4567/user/filename
post '/:name/:filename' do
userdir = File.join("files", params[:name])
@gavinheavyside
gavinheavyside / fizzbuzz.rb
Last active September 27, 2019 08:43 — forked from mrb/fizzbuzz.rb
Writing FizzBuzz without modulus division or 'if'
fizz = [nil, nil, "Fizz"].cycle
buzz = [nil, nil, nil, nil, "Buzz"].cycle
(1..100).zip(fizz, buzz) do |num, *fb|
puts fb.compact.reduce(:+) || num
end
@mrb
mrb / constraint.lisp
Created January 8, 2014 03:53
"Logic Programming in Lisp" from Luger and Stubblefield
;;; This is one of the example programs from the textbook:
;;;
;;; Artificial Intelligence:
;;; Structures and strategies for complex problem solving
;;;
;;; by George F. Luger and William A. Stubblefield
;;;
;;; These programs are copyrighted by Benjamin/Cummings Publishers.
;;;
;;; We offer them for use, free of charge, for educational purposes only.
@postmodern
postmodern / array_comprehension.rb
Created October 1, 2010 07:50
Adds Haskell style list comprehensions to the Ruby Array
class Array
#
# Iterates over each permutation of the enumerable values within the
# {Array}.
#
# @yield [list]
# The given block will be passed each permutation of the enumerable
# values in the {Array}.
#