Skip to content

Instantly share code, notes, and snippets.

View swr1bm86's full-sized avatar
🏠
Working from home

xxx swr1bm86

🏠
Working from home
View GitHub Profile
@swr1bm86
swr1bm86 / sierpinski.hs
Created November 1, 2015 03:54 — forked from Xophmeister/sierpinski.hs
Sierpinski Triangle in Haskell
sumPairs :: [Integer] -> [Integer]
sumPairs (x:y:s) = (x + y) : sumPairs (y:s)
sumPairs _ = []
pascal :: Integer -> [Integer]
pascal 0 = [1]
pascal n = sumPairs $ [0] ++ (pascal $ n - 1) ++ [0]
sierpinski :: Integer -> String
sierpinski n = concat $ map (ascii . odd) $ pascal n
@swr1bm86
swr1bm86 / Pascal.hs
Created November 1, 2015 02:57 — forked from queertypes/Pascal.hs
Pascal's triangle in Haskell
import Control.Applicative ((<$>))
center :: String -> Int -> String
center s n = spaces ++ s ++ spaces
where spaces = replicate ((n - length s) `div` 2) ' '
-- http://www.haskell.org/haskellwiki/Blow_your_mind, Ctrl-F "pascal"
pascal :: [[Int]]
pascal = iterate (\row -> zipWith (+) ([0] ++ row) (row ++ [0])) [1]
-- in fsharp
x |> func
-- let's define it in haskell
let (|>) = flip ($)
1 |> (\x -> x + 1) |> (\x -> x * 3)
(for [[x y] (map vector '(1 2 3) '(4 5 6))]
(list x y))
=> ((1 4) (2 5) (3 6))
(for [[x y] (map vector '(1 2 3) '(4 5 6) '(7 8 9))]
(list x y))
=> ((1 4) (2 5) (3 6))
(for [[x y z] (map vector '(1 2 3) '(4 5 6) '(7 8 9))]
(list x y z))
=> ((1 4 7) (2 5 8) (3 6 9))
(for [[x y z] (map vector '(1 2 3) '(4 5 6) '(7))]
(ns my.app
(:require
[aleph.http :refer :all]
[compojure.core :refer [defroutes GET]]
[compojure.handler :as handler]
[lamina.core :refer :all]
[com.netflix.hystrix.core :as hystrix]
[clj-http.client :as client]))
(defn get-pants []
@swr1bm86
swr1bm86 / monad conclusion
Created October 3, 2015 16:03
think about monad
单子(monad)就是自函子范畴上的幺半群的含义
首先函子也就是functor就是范畴上的映射 而映射的起点和重点相同的函子就可以称为自函子
满足两个定理的群叫半群 如果含有幺元(monoid)就称为幺半群
所以monad是一组集合 是自函子这个范畴下 满足幺半群定义的子集合 就是满足这些范畴定义的类型集合
@swr1bm86
swr1bm86 / Makefile
Last active September 11, 2015 17:03 — forked from jeremyroman/Makefile
llvm-brainfuck: Simple operations
PROGRAM := llvm-brainfuck
OBJECTS := main.o
CXX := clang++
CXXFLAGS := $(shell llvm-config --cppflags) -Wall -Werror -pedantic
LDFLAGS := $(shell llvm-config --ldflags --libs core)
all: $(PROGRAM) $(SHIM)
$(PROGRAM): $(OBJECTS)
@swr1bm86
swr1bm86 / IDEA (Cursive) shortcuts
Last active April 27, 2016 06:53
cursive tips
在oracle的jdk上运行idea会出现一些问题 尤其是在使用cursive的时候 所以要装一下[jdkforosx](https://support.apple.com/kb/DL1572?locale=zh_CN)
然后IntelliJ IDEA->About IntelliJ IDEA.查看idea的运行时是不是用了这个jre如果是就不会有任何问题了
要对某一个自建的symbol设置缩进的时候可以按alt+enter
alt+上下方向键可以格式化选择代码来进行复制删除等操作 alt+左右方向键用来在一个form的左右括号之间来回移动光标
运行repl时需要先switch to current namespace然后再command+shift+l同步一下代码文件再command+shift+p执行某一个form
alt+cmd+left/right 用来跳转到最近光标所在的位置
Settings→Editor→General→Smart Keys→Use structural editing
  • defprotocol: defines an interface
  • deftype: create a bare-bones object which implements a protocol
  • defrecord: creates an immutable persistent map which implements a protocol

Typically you'll use defrecord (or even a basic map);
unless you need some specific Java inter-op,
where by you'll want to use deftype instead.

Note: defprotocol allows you to add new abstractions in a clean way Rather than (like OOP) having polymorphism on the class itself,

@swr1bm86
swr1bm86 / reader.hs
Last active August 29, 2015 14:23 — forked from egonSchiele/reader.hs
import Control.Monad.Reader
hello :: Reader String String
hello = do
name <- ask
return ("hello, " ++ name ++ "!")
bye :: Reader String String
bye = do
name <- ask