Skip to content

Instantly share code, notes, and snippets.

View robinp's full-sized avatar

Robin Palotai robinp

  • Budapest, Hungary
View GitHub Profile
@robinp
robinp / run.bat
Created February 10, 2019 22:11
Converting image dirs to pdf using imagemagick on Windows
for /D %%f in (*) do (
cd %%f
mkdir annotated
magick mogrify -path annotated -set filename:xxx %%t -fill black -undercolor white -gravity southwest -pointsize 24 -annotate +0+0 "%%[filename:xxx]" *png *jpg
magick convert annotated/* ../%%~nf.pdf
rm -r annotated
cd ..
)
@robinp
robinp / Bazel build error
Created January 17, 2019 10:49
Bazel action_env gets lost somewhere
$ sh invoke-build.sh kythe/cxx/extractor/...
...
SUBCOMMAND: # //kythe/cxx/extractor:index_pack [action 'Compiling kythe/cxx/extractor/index_pack.cc [for host]']
(cd /home/ron/.cache/bazel/_bazel_ron/084c77e61dfc73e2d0fc7fb1fb9a9252/execroot/io_kythe && \
exec env - \
PATH=/nix/store/vs6d2fjkl4kb3jb7rwibsd76k9v2n4xy-bash-4.4-p23/bin:/nix/store/lvhndwdy2q09fhwgzykjjigz7yxq5yiv-coreutils-8.30/bin:/nix/store/5c2428hk25dwsgnifcmn5dvgrwvvgvrx-findutils-4.6.0/bin:/nix/store/9jjxqhwak78zi94m7gvwdw3gqzd1hr1b-gawk-4.2.1/bin:/nix/store/f7c1ijdv5czqb0dxi4mi5wkfvi1pc7rn-gnugrep-3.3/bin:/nix/store/4lvbww6zrphadhcbqidx8qskc0rsblg6-gnused-4.7/bin:/nix/store/mwc5mwvw080nbahpdc0xr1rk3mhkcdp1-which-2.21/bin:/nix/store/c39nikyab2qfifbqzy7hqqkhvk7k05ca-unzip-6.0/bin \
PWD=/proc/self/cwd \
/nix/store/isg8rxaxkijl9x3hr2gzsf8pqfnqxg3k-gcc-wrapper-7.4.0/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -B/nix/store/isg8rxaxkijl9x3hr2gzsf8pqfnqxg3k-gcc-wrapper-7.4.0/bin -B/usr/bin -Wunused-but-set-parameter -Wno-free-n
@robinp
robinp / pom.xml
Created July 21, 2011 09:43
Sample pom.xml for Scala 2.8.1 maven project
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mygroup/groupId>
<artifactId>my-artifact</artifactId>
<version>1.0-SNAPSHOT</version>
<name>${project.artifactId}</name>
<description>My wonderfull scala app</description>
<inceptionYear>2010</inceptionYear>
<licenses>
<license>
@robinp
robinp / ghc-api-reuse.md
Last active April 2, 2018 10:42
Calling GHC API multiple times: choose your ExitFailure

GHC API lets you process Haskell sources, and (among other) specify code generation and linking level. For example:

  • (1) no codegen & no link
  • (2) bytecode generation & link in memory
  • (3) machine code generation & linking output binaries

For code analysis purposes, based on generating the typechecked AST, option (1) suffices most of the time. There are some situations in which it doesn't:

  • TemplateHaskell (TH) splice needs to execute code (at compile time) from an imported module: the imported module must be available in compiled form, so either (2) or (3) is needed. Example: in $([|$(foo)|]), foo will be evaluated at compile-time.
  • Code uses FFI imports. For this one would expect that (2) is needed (see checkCOrAsmOrLlvmOrInterp in TcForeign.hs), but actually unless it is used (say by TH, see below), even (1) works too (see the wrapper checkCg).
@robinp
robinp / graph-bashing.sh
Last active September 4, 2017 19:59
Extract callgraph edges with awk
gunzip -c all.nq.gz | grep 'node/kind" "package' > packages.nq
gunzip -c all.nq.gz | awk 'NR==FNR { a[$1]; next } /childof/{if ($3 in a) print $1}' packages.nq - > pkgchildren.txt
gunzip -c all.nq.gz | awk 'NR==FNR { a[$1]; next } /childof/{if ($3 in a) print $1" "$3}' pkgchildren.txt - | gzip - > topchildren.txt.gz
gunzip -c all.nq.gz | awk 'NR==FNR { a[$1]=$2; mx=FNR; next } (NR-mx==FNR) { b[$1] ; next } /kythe\/edge\/ref/{if (($1 in a) && ($3 in b)) print a[$1]" "$3}' <(gunzip -c topchildren.txt.gz) pkgchildren.txt - | uniq | gzip - > callgraph.txt.gz
@robinp
robinp / cayley-load.sh
Created June 30, 2017 20:24
Load Kythe data into Cayley
/opt/kythe/tools/triples --graphstore ~/dev/ghc-vagrant/entries/gs > entries.all
cayley init -db leveldb -dbpath cdb
cayley load -db leveldb -dbpath cdb -quads=entries.all -alsologtostderr
@robinp
robinp / GhcWrapper.hs
Created July 13, 2017 20:38
Random GHC wrapper script.
import GHC.Paths
import System.Posix.Process
import System.Environment
import System.IO
import Data.List (intercalate)
import Control.Monad (when)
lg = appendFile "/tmp/fake.lg" . (++ "\n")
main = do
@robinp
robinp / ghc_wrapper.sh
Created June 30, 2017 20:36
Indexing GHC source
#!/bin/bash
# GHC wrapper for indexing Haskell packages.
# Note that variables INDEXER_OUTPUT_DIR and REALGHC are set outside this script.
log() {
echo "$1" >> "$INDEXER_OUTPUT_DIR/$PKG.log"
}
log "GHC $*"
@robinp
robinp / ghc8-ast.txt
Last active June 14, 2017 20:22
GHC 8 AST changes
=== Recursive function with type signature
A recursive call (with typesig) targets the polymorphic binding (vs the monomorphic one usually targeted).
Now there's a new ctor for this kind of function (AbsBindsSig), having only a poly-like binding exposed.
Caveat: the internal FunBind still refers the monomorphic binding. So it's a bit less obvious to make the connection.
module Sphinx where
import Data.Text (Text)
import Foreign (alloca, peek)
import Foreign.C.String (CString)
import Foreign.Ptr (Ptr, nullPtr)
-- TODO move utils
peekIntegral = fmap fromIntegral . peek