Skip to content

Instantly share code, notes, and snippets.

@tranma
tranma / sac.md
Created April 24, 2019 23:30
SACs
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default
;; Base distribution to use. This is a layer contained in the directory
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="/Users/meow/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
{-
Write a function for retrieving the total number of substring palindromes.
For example the input is 'abba' then the possible palindromes= a, b, b, a, bb, abba
So the result is 6.
-}
-- Bruteforce:
-- check every contiguous subsequence.
-- imaging placing ( ) around each subsequence.
-- for n choices of ( there are n-1 choices of )
{-# LANGUAGE NoImplicitPrelude #-}
module Tree where
import P hiding (Left, Right)
data Tree a = Leaf a | Bin (Tree a) (Tree a)
data Circular a = Node a (Circular a) (Circular a)
-- pre-order traversal
# this doesn't work with 3.6
# also the homebrew formula won't work, missing the dylib
wget http://llvm.org/releases/3.5.0/llvm-3.5.0.src.tar.xz
wget http://llvm.org/releases/3.5.0/cfe-3.5.0.src.tar.xz
wget http://llvm.org/releases/3.5.0/compiler-rt-3.5.0.src.tar.xz
tar xvf llvm-3.5.0.src.tar.xz
cd llvm-3.5.0.src/tools
tar xvf ../../cfe-3.5.0.src.tar.xz
mv cfe-3.5.0.src clang
@tranma
tranma / handle-cheatsheet.md
Last active July 20, 2016 01:18
Haskell handle IO cheatsheet
Type State Function What to expect
Unix pipe Open, Empty ByteString.hGetContents (strict) Blocks until state changes
Unix pipe Closed ByteString.hGetContents (strict) Runtime exception: "handle is closed"
File ... ... ...
@tranma
tranma / Generic.hs
Created February 29, 2016 11:48
optparse-generic attempt
{-# LANGUAGE DeriveGeneric, ScopedTypeVariables, RankNTypes, InstanceSigs, DefaultSignatures, FlexibleContexts, TypeOperators, FlexibleInstances #-}
import Control.Applicative
import GHC.Generics
import Options.Applicative hiding (argument)
import Data.Monoid
newtype ExampleArg = ExampleArg Int
deriving Generic
@tranma
tranma / Plot.hs
Created October 20, 2015 09:34
Plot simple y(x) functions in ASCII
-- * Plot simple y(x) functions in ASCII
--
import Control.Monad
import Control.Arrow
import Control.Monad.ST
import Data.Array.ST
import Data.Array.Unboxed
import qualified Data.Array.ST as AS
import qualified Data.Array.MArray as AM
import Data.Ord
@tranma
tranma / With.hs
Last active August 29, 2015 14:07
Using MMonad and MonadTransControl to define (with :: (a -> Foo m x) -> Foo m x) in terms of (with :: (a -> m x) -> Foo m x)
{-# LANGUAGE GeneralizedNewtypeDeriving, TypeFamilies, TupleSections #-}
import Control.Exception
import Control.Applicative
import Control.Monad.State.Strict
import Control.Monad.Trans.Class
import Control.Monad.Trans.Either
import Control.Monad.Error
import Control.Monad.Trans.Control
import Control.Monad.Morph