Skip to content

Instantly share code, notes, and snippets.

View davidxifeng's full-sized avatar
🥛
Go/Linux/Vim/React/Flutter/Astro/Kubernetes

David Nishikaze davidxifeng

🥛
Go/Linux/Vim/React/Flutter/Astro/Kubernetes
View GitHub Profile
@davidxifeng
davidxifeng / my_vim_script.vim
Created January 10, 2012 06:21
A hashset of my vim scripts
"also my gist test
"get words count of current line
echo "current line words count : ".len(split(getline(".")))
"Double Pinyin Schema
let s:yunmu={ "iu": "q", "ia": "w", "ua": "w", "e": "e", "uan": "r", "er": "r", "ue": "t",
\ "uai": "y", "v": "y", "u": "u", "i": "i", "uo": "o","o":"o", "un": "p",
\ "a":"a","ong":"s","iong":"s","uang":"d","iang":"d","en": "f","eng":"g",
\ "ang": "h", "an": "j", "ao": "k", "ai":"l", "ing":";",
@davidxifeng
davidxifeng / remove_comment.hs
Created July 13, 2012 05:06
delete the first /**/ comment in .h and .c file in a directory
-- remove first long comment in a directory's all .h and .c file and it's all sub directory
import System.Environment
import System.Directory
import System.FilePath.Windows
import Control.Monad
import Data.List
-- 必须保证/*和*/是匹配的...这里满足这个条件
removeFirstComment :: String -> String
removeFirstComment [] = []
@davidxifeng
davidxifeng / finally_know_foldX_functions.hs
Created December 5, 2012 09:51
foldM and foldr &foldl
import System.Directory
import Control.Monad
selectM :: Monad m => (a -> m Bool) -> ([a], [a]) -> a -> m ([a], [a])
selectM p ~(ts,fs) x = do
r <- p x
if r then return (x:ts, fs) else return (ts, x:fs)
partitionM :: Monad m => (a -> m Bool) -> [a] -> m ([a],[a])
partitionM p xs = do
c = let x = 0 : y
y = 1 : x
in
x
-- c [0,1,0,1...]
-- 这种技巧是用来使用data来实现图,双向链表等结构的
@davidxifeng
davidxifeng / little_lisp.py
Created May 19, 2013 07:18
a small lisp in python
################ Lispy: Scheme Interpreter in Python
## (c) Peter Norvig, 2010; See http://norvig.com/lispy.html
################ Symbol, Procedure, Env classes
from __future__ import division
Symbol = str

测试使用gist

你好

I love Haskell.

{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
import Network.Wai
import Control.Exception (Exception, throwIO, assert)
import Control.Applicative ((<$>))
import Control.Monad (when, forever, unless)
import Data.Typeable (Typeable)
import Network.HTTP.Types (status200, status404)
import Network.Wai.Handler.Warp (run)
@davidxifeng
davidxifeng / ssh-copy-id.sh
Created June 17, 2014 08:54
the missing ssh-copy-id for Mac OS X
#!/bin/sh
# Shell script to install your public key on a remote machine
# Takes the remote machine name as an argument.
# Obviously, the remote machine must accept password authentication,
# or one of the other keys in your ssh-agent, for this to work.
ID_FILE="${HOME}/.ssh/id_rsa.pub"
if [ "-i" = "$1" ]; then
@davidxifeng
davidxifeng / csv_test.hs
Created July 24, 2014 07:39
fail mzero and Parser
import Data.Csv
import Control.Monad
import Control.Applicative
-- 2014-07-24 15:26:22 fail and mzero
data Test = A | B | C
deriving (Show, Read)
instance FromField Test where
@davidxifeng
davidxifeng / custom_hashset.hs
Created July 25, 2014 12:29
data structure for fast merge-insert
import qualified Data.HashSet as HS
import Data.Hashable
-- 2014-07-25 20:27:29
-- TODO custom HashSet with special ``insert`` ``fromListWith`` ...
data Test = A Int | B Double | C Char | D
deriving (Show)
instance Eq Test where