Skip to content

Instantly share code, notes, and snippets.

View sighingnow's full-sized avatar
💭
typing...

Tao He sighingnow

💭
typing...
View GitHub Profile
@sighingnow
sighingnow / stack-config.yaml
Created December 26, 2016 15:02
Personal stack global configuration.
# This file contains default non-project-specific settings for 'stack', used
# in all projects. For more information about stack's configuration, see
# http://docs.haskellstack.org/en/stable/yaml_configuration.html
#
# {}
package-indices:
- require-hashes: false
gpg-verify: false
name: TUNA
@sighingnow
sighingnow / T.hs
Created December 27, 2016 14:13
Haskell's $ operator for types.
{-# LANGUAGE TypeOperators #-}
module T where
-- | Infix application.
--
-- @
-- f :: IO $ Maybe Int
-- =
@sighingnow
sighingnow / Makefile
Last active December 27, 2016 15:38
Expose C++ API to Haskell via FFI.
all: libacpp.dll app.exe
GHC := stack ghc --
%.o: %.cpp
$(CXX) -c $< -o $@
libacpp.dll: acpp.o acpp_capi.o
$(CXX) $^ -shared -o $@ # On Linux/Unix, -fPIC is needed.
@sighingnow
sighingnow / misc.hs
Created January 2, 2017 13:23
concatMap and filter using Foldable and Traversable.
concatMap :: (Foldable f, Monoid (f b)) => (a -> f b) -> f a -> f b
concatMap = foldMap
filter :: (Applicative f, Foldable f, Monoid (f a)) =>
(a -> Bool) -> f a -> f a
filter p = foldMap (\a -> if p a then pure a else mempty)
@sighingnow
sighingnow / tensorboard_logging.py
Last active December 31, 2017 11:18 — forked from gyglim/tensorboard_logging.py
Logging to tensorboard with manually generated summaries (not relying on summary ops)
"""Simple example on how to log scalars and images to tensorboard without tensor ops.
License: Copyleft
"""
__author__ = "Michael Gygli, Tao He"
import tensorflow as tf
try:
from StringIO import StringIO
except:
@sighingnow
sighingnow / error-message
Created April 26, 2018 14:06
ghc treat certain kinds of warnings as errors when compile c source file.
D:\Open>gcc test.c -Wall -c
test.c: In function 'g':
test.c:8:14: warning: passing argument 1 of 'f' from incompatible pointer type [-Wincompatible-pointer-types]
return f(cp);
^~
test.c:1:5: note: expected 'int *' but argument is of type 'char *'
int f(int *a) {
^
D:\Open>stack exec -- ghc -c test.c -Wall
@sighingnow
sighingnow / bench-enum.hs
Created May 3, 2018 05:29
Benchmark on several implementations of `numericEnumFromThen` and `numericEnumFromThenTo`.
{-# LANGUAGE BangPatterns #-}
import Criterion.Main
import Weigh
numericEnumFromThen :: (Fractional a) => a -> a -> [a]
numericEnumFromThen n m = n `seq` m `seq` (n : numericEnumFromThen m (m+m-n))
numericEnumFromThenTo :: (Ord a, Fractional a) => a -> a -> a -> [a]
numericEnumFromThenTo e1 e2 e3
@sighingnow
sighingnow / unsafe.hs
Last active July 6, 2018 09:41
Unsafe perform computation in some monads.
import Control.Monad.ST
import System.IO.Unsafe
import Unsafe.Coerce
unsafePerformST :: ST s a -> a
unsafePerformST m = unsafePerformIO $
stToIO $ -- unsafely do it
unsafeCoerce m -- convert to ST Realworld a
{-# NOINLINE unsafePerformST #-}
@sighingnow
sighingnow / .gitconfig
Last active July 23, 2018 05:26
My gitconfig file.
[gui]
fontui = -family 微软雅黑Monaco -size 8 -weight normal -slant roman -underline 0 -overstrike 0
fontdiff = -family \"YaHei Consolas Hybrid\" -size 8 -weight normal -slant roman -underline 0 -overstrike 0
encoding = utf-8
warndetachedcommit = true
tabsize = 4
recentrepo = D:/Open/foundationdb-haskell
[user]
email = sighingnow@gmail.com
name = HE, Tao
@sighingnow
sighingnow / cgroup-limit-memory.c
Last active July 27, 2018 04:17
Limit memory usage with libcgroup interface.
#include <assert.h>
#include <libcgroup.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#define _GNU_SOURCE
#include <unistd.h>