Skip to content

Instantly share code, notes, and snippets.

@aprell
aprell / nvim-from-vim.sh
Created October 22, 2016 20:28
Neovim setup
mkdir -p ~/.config
ln -s ~/.vim ~/.config/nvim
ln -s ~/.vimrc ~/.config/nvim/init.vim
@aprell
aprell / alias.sh
Created July 3, 2016 15:53
Pipe to gnuplot
alias plot="gnuplot -p -e \"plot '-'\""
@aprell
aprell / nested.c
Created June 29, 2016 13:17
Nested functions in GNU C
#include <stdio.h>
#include <assert.h>
#define defer_(x) \
({ typeof(x) fun(void) { return x; } fun; })
#define defer(n, x) \
typeof(x) (*n)() = defer_(x)
int main(void)
@aprell
aprell / Makefile
Created January 28, 2016 20:47
Calling C++ from C
CC = clang
CFLAGS = -Wall -Wextra
CXX = clang++
CXXFLAGS = $(CFLAGS) -std=c++11
extern: extern.o extern_C.o
$(CXX) $(CXXFLAGS) $^ -o $@
clean:
@aprell
aprell / Makefile
Last active January 28, 2016 20:35
Calling C from C++
CC = clang
CFLAGS = -Wall -Wextra
CXX = clang++
CXXFLAGS = $(CFLAGS) -std=c++11
extern_C: extern_C.o sum.o
$(CXX) $(CXXFLAGS) $^ -o $@
clean:
@aprell
aprell / atomic.cpp
Last active January 28, 2016 20:17
Atomic read-modify-write test
#include <vector>
#include <thread>
#include <atomic>
#include <cassert>
int main()
{
std::vector<std::thread> threads(16);
std::atomic<unsigned int> ai(0);
@aprell
aprell / taskloop.c
Last active December 18, 2015 13:09
Task loops in OpenMP
#include <stdio.h>
#include <assert.h>
#include <omp.h>
int s;
void loop(void)
{
int i;
@aprell
aprell / nqueens.lua
Created December 7, 2015 16:50
N-Queens problem
-- Programming in Lua, Chapter 10, Page 98
local N = 8
-- Number of solutions up to N=10
local num_solutions = {1, 0, 0, 2, 10, 4, 40, 92, 352, 724}
-- Check whether (row, col) can be attacked by queens
local function isok(queens, row, col)
for i = 1, row-1 do
@aprell
aprell / expand.sh
Created November 9, 2015 19:49
Shell parameter expansion
#!/bin/bash
# Use if unset or null
echo ${x:-x} # x
echo $x #
# Assign if unset or null (only regular variables)
echo ${y:=y} # y
echo $y # y
@aprell
aprell / lambda-term-inputrc
Created October 28, 2015 15:10
Lambda-Term key bindings
[read-line]
M-n: complete-bar-next
M-p: complete-bar-prev
C-w: kill-prev-word