Skip to content

Instantly share code, notes, and snippets.

View MaskRay's full-sized avatar
🏠
Working from home. Need food

Fangrui Song MaskRay

🏠
Working from home. Need food
View GitHub Profile
@MaskRay
MaskRay / gist:465a38a1c9851385c0e6
Created January 25, 2012 15:09
usaco dec 11 grassplant haskell
{-# LANGUAGE BangPatterns #-}
import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.State
import Data.Array
import Data.Array.IO
import Data.Bits
import Data.Bits.Extras
import qualified Data.ByteString.Char8 as B
@MaskRay
MaskRay / pod2db.hs
Created February 10, 2012 15:08
po2db
{-# LANGUAGE DeriveDataTypeable, TemplateHaskell #-}
import Prelude hiding (catch)
import Control.Applicative hiding (optional, many, (<|>))
import Control.Exception hiding (try)
import Control.Monad
import Data.Lens.Common
import Data.Lens.Template
import Data.List
import Data.Maybe
import Database.HDBC
" -*- vim: set sts=2 sw=2 et fdm=marker: ------------- vim modeline -*-
" [Pathogen] ------------------------------------------ {{{1
" call pathogen#infect()
" Basic Settings -------------------------------------- {{{1
syntax on
set nocompatible
filetype plugin indent on
set hlsearch
╭─ray at lap >>= /tmp
╰─% jruby -v
Exception in thread "main" java.lang.NoClassDefFoundError: org/jruby/ext/posix/JavaSecuredFile
at org.jruby.RubyInstanceConfig.<init>(RubyInstanceConfig.java:407)
at org.jruby.Main.<init>(Main.java:96)
at org.jruby.Main.main(Main.java:185)
@MaskRay
MaskRay / thu_syllabus2ical.hs
Created June 7, 2012 07:24
thu_syllabus2ical.hs
{-# LANGUAGE NoMonomorphismRestriction #-}
import Control.Applicative hiding ((<|>), many)
import Control.Monad
import Data.List
import Data.List.Split (splitOn)
import Data.Maybe
import Data.Time.Format
import Data.Time.Calendar
import Data.Time.Calendar.WeekDate
import Data.Time.Clock
@MaskRay
MaskRay / config.erl
Created June 23, 2012 14:17
erl-chat
{port,8888}.
@MaskRay
MaskRay / gist:2995458
Created June 26, 2012 12:07
ruby on prefix
% ls ~/gentoo/usr/lib/libpython2.7.so.1.0
/home/sfr/gentoo/usr/lib/libpython2.7.so.1.0
>>> Installing (1 of 1) dev-lang/ruby-1.9.3_p194-r1
/home/sfr/gentoo/usr/bin/python2.7: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
* ERROR: dev-lang/ruby-1.9.3_p194-r1 failed (prerm phase):
* filter-bash-environment.py failed
*
#include <algorithm>
#include <cmath>
#include <functional>
#include <numeric>
#include <unordered_map>
#include <vector>
#include <stdint.h>
#include <stdio.h>
using namespace std;
@MaskRay
MaskRay / gist:4134245
Created November 23, 2012 06:32
Flesch Reading Ease Score of several programming books
% xargs -i sh -c 'echo -n "{} @ "; pdftotext "{}" - 2>/dev/null | ruby -e "require \"lingua\"; p Lingua::EN::Readability.new(STDIN.read).flesch"' < /tmp/books | sort -t@ -k2n
scheme/sicp.pdf @ 42.013863374063305
smalltalk/Joy of Smalltalk.pdf @ 47.861949781603954
falcon/Falcon Survival Guide.pdf @ 52.899363840845155
ruby/The Rails 3 Way.pdf @ 55.05629641057524
c/The C Programming Language.pdf @ 55.17174939358114
python/Learning Python.pdf @ 56.67476157760058
c++/C++ Primer.pdf @ 57.237840064930595
ruby/The Ruby Programming Language.pdf @ 57.75836947304364
haskell/Real World Haskell.pdf @ 58.23158652909788
@MaskRay
MaskRay / a.ml
Created February 8, 2013 04:37
给个数组,打乱了,比如:索引 0 1 2 3 4;值 3 2 1 4 0 。数组的值是下次跳的索引位置,这样的话数组有环,比如 0 -> 3 -> 4 -> 0 1 -> 2 -> 1, 求最长环的长度。
let huangBingchao a =
let n = Array.length a in
let rec go2 j i l =
if a.(i) < 0 then
(j, l)
else
let ii = a.(i) in
a.(i) <- j;
go2 (lnot i) ii (l+1) in
let rec go i mx =