Skip to content

Instantly share code, notes, and snippets.

@jchia
jchia / things-learnt.txt
Created April 27, 2012 16:40
What I learnt
git push -u origin (branch.name) # make new remote branch with current local repo
git checkout --track -b (localbranch.name) (remote)/(remotebranch.name) # checkout and track remote branch
git push (remote) :(remotebranch.name) # delete remote branch
.gitconfig: push.default=upstream # config "git push" to push only current branch
# Generate detailed ASM listing
g++ -S -fverbose-asm (source).cpp; as -alhnd (source).s > (verbose.listing).s
# oprofile incantation. It seems that bug in old version requires shutdown to get rid of some silly warning about missed samples.
@jchia
jchia / foo.sublime-build
Created April 29, 2012 08:07
Some config file to help SublimeText 2 parse gcc error messages.
{
"cmd":
[
"make", "-j", "30", "-k",
"foo", "# This is a SublimeText2 file in my User directory to parse GCC errors."
],
"selector": "source.c++",
"working_dir": "/home/josh.chia/git/build/target",
"file_regex": "^([^:]*):([0-9]+):[0-9]+: (?:error|note):"
}
@jchia
jchia / scales.py
Created April 30, 2012 05:25
Music scale manipulation
#!/usr/bin/python
# Transpose the deltas so that the first one is 0 and everything is in [0, 12).
def normalize(deltas):
root = deltas[0] % 12
return [(delta + 12 - root) % 12 for delta in deltas]
def transpose(deltas, base):
return [(delta + base) % 12 for delta in deltas]
@jchia
jchia / bld-gcc-boost.sh
Created November 11, 2012 04:49
Build gcc 4.7.2 and boost 1.51 (all libraries) on CentOS 6, adapted from someone else's script
#!/bin/bash
#
# $Id: bld.sh,v 1.2 2012/09/22 16:04:19 jlinoff Exp jlinoff $
#
# Author: Joe Linoff
#
# This script downloads, builds and installs the gcc-4.7.2 compiler
# and boost 1.51. It takes handles the dependent packages like
# gmp-5.0.5, mpfr-3.1.1, ppl-1.0 and cloog-0.17.0.
#
@jchia
jchia / ca.cabal
Last active August 9, 2016 00:25
call-haskell-from-anything gets build error
name: ca
version: 0.1.0.0
synopsis: Initial project template from stack
description: Please see README.md
license: BSD3
license-file: LICENSE
author: Josh Chia
maintainer: joshchia@gmail.com
copyright: Copyright (c) 2016 Joshua Chia
category: Development
@jchia
jchia / graphviz-direction.hs
Created October 13, 2017 06:02
graphviz package generates graph with wrong arc direction.
#!/usr/bin/env stack
-- stack --resolver nightly-2017-10-08 runghc --package graphviz
import qualified Data.GraphViz.Types.Graph as GV
import Data.GraphViz.Commands (GraphvizOutput(..), dirCommand, runGraphvizCommand)
main :: IO ()
main = do
-- This generates an arc with the wrong direction. There should be an arc from 0 to 1 but this code produces
-- an arc from 1 to 0, contrary to the documentation of the fields of DotEdge, popular convention and fgl
-- convention.
@jchia
jchia / gist:c7c69e1f0e4c2001c1bccd687197e59d
Created January 8, 2018 14:56
stderr from `stack build --verbose` for broken case
Version 1.6.3, Git revision b27e629b8c4ce369e3b8273f04db193b060000db (5454 commits) x86_64 hpack-0.20.0
2018-01-08 22:54:31.020091: [debug] Checking for project config at: /home/jchia/hs/doc/stack.yaml
@(Stack/Config.hs:842:9)
2018-01-08 22:54:31.020271: [debug] Loading project config file stack.yaml
@jchia
jchia / gist:50e508a08958361b4a87f1b90edb7cdc
Created January 8, 2018 14:57
`stack build --verbose` stderr for normal case
Version 1.6.3, Git revision b27e629b8c4ce369e3b8273f04db193b060000db (5454 commits) x86_64 hpack-0.20.0
2018-01-08 22:54:41.320427: [debug] Checking for project config at: /home/jchia/hs/doc/stack.yaml
@(Stack/Config.hs:842:9)
2018-01-08 22:54:41.320552: [debug] Loading project config file stack.yaml
@jchia
jchia / Lib3.hs
Created March 28, 2018 15:16
How to fix Lib4.hs:10?
{-# LANGUAGE DataKinds, FlexibleInstances, TemplateHaskell, TypeFamilies, TypeOperators #-}
module Lib3 (partQ) where
import ClassyPrelude hiding (IsMap, Map)
import Data.Proxy
import GHC.TypeLits
import Language.Haskell.TH
import Labels
@jchia
jchia / LabelsTH.hs
Created March 28, 2018 16:15
TH for making 'labels' named tuples
{-# LANGUAGE DataKinds, FlexibleInstances, TemplateHaskell, TypeFamilies, TypeOperators #-}
module LabelsTH where
import ClassyPrelude
import Language.Haskell.TH
import Labels ((:=))
typeForFieldname :: String -> Type
typeForFieldname "x" = ConT ''Int