Skip to content

Instantly share code, notes, and snippets.

using Images
data = rand(10, 10)
image = Image(data)
immutable Point{T}
i::T
j::T
end
@maleadt
maleadt / Makefile
Created May 29, 2014 10:24
Unable to read from STDIN in ccall'ed DSO
MAKEFLAGS += --no-builtin-rules
CXX=g++
all: libinput.so demo
%.o: %.cpp
$(CXX) -fPIC -c -o $@ $<
lib%.so: %.o
$(CXX) -shared -o $@ $<
@maleadt
maleadt / Makefile
Last active July 12, 2016 18:21
Interpolate kernel - Julia vs C++
CXX=clang++
CXXFLAGS=-std=c++11 -O3 -DNDEBUG $(shell pkg-config --cflags eigen3)
JL=julia
# JLFLAGS=-O3
.PHONY:all
all: interpolate.julia.ll interpolate.c++.ll
interpolate: interpolate.cpp
@maleadt
maleadt / interpolate.c++.ll
Created June 2, 2014 07:00
Interpolate kernel bitcode - Julia vs C++
define float @interpolate(%"class.Eigen::Matrix"* nocapture readonly %source, %"class.Eigen::Matrix.2"* nocapture readonly %p) #3 {
%x_int = alloca float, align 4
%y_int = alloca float, align 4
%1 = getelementptr inbounds %"class.Eigen::Matrix.2"* %p, i64 0, i32 0, i32 0, i32 0, i32 0, i64 0
%2 = load float* %1, align 4
%3 = call float @modff(float %2, float* %x_int) #2
%4 = getelementptr inbounds %"class.Eigen::Matrix.2"* %p, i64 0, i32 0, i32 0, i32 0, i32 0, i64 1
%5 = load float* %4, align 4
%6 = call float @modff(float %5, float* %y_int) #2
%7 = load float* %y_int, align 4
@maleadt
maleadt / gist:02a58eb46118c1d8014c
Created September 30, 2014 15:03
Sample smartd.conf
# WD Red
# - check some stuff and track everything (-a)
# - ignore temperature (194 and 231) and power-on hours (9) attributes (-I)
/dev/disk/by-id/ata-WDC_WD30EFRX-68AX9N0_WD-WMC1T0938110 -a -d sat \
-I 194 -I 231 -I 9 \
-m root -M diminishing
/dev/disk/by-id/ata-WDC_WD30EFRX-68AX9N0_WD-WMC1T0965778 -a -d sat \
-I 194 -I 231 -I 9 \
-m root -M diminishing
/dev/disk/by-id/ata-WDC_WD30EFRX-68AX9N0_WD-WMC1T0876678 -a -d sat \
#!/bin/bash -e
# Usage
function print_usage {
echo "Usage: $0 FILES... [-- MAKE OPTIONS...]"
}
# Process names options
MODE="files"
FILES=()
@maleadt
maleadt / decrypt
Created October 21, 2014 09:55
encrypt/decrypt
#!/usr/bin/perl
use strict;
my $secfile = shift || die("Usage: " . basename($0) . " <filename>\n");
die("Error: encrypted source file does not exist.\n") unless (-f $secfile);
my $file = $secfile;
$file =~ s/\.gpg$// || die("Error: unrecognized file");
die("Error: decrypting would overwrite existing unencrypted file.\n") if (-f $file);
@maleadt
maleadt / gist:ef26a7d567b8a9d27534
Created January 24, 2015 20:25
Accessing nRF24LE1 PROG commands using the Bus Pirate's binary SPI mode.
#!/usr/bin/perl
#
# Initialization
#
use strict;
use warnings;
use Time::HiRes qw/usleep/;
@maleadt
maleadt / Makefile
Created March 19, 2015 10:48
encfs mounting Makefile
SHELL := /bin/bash
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
LOOPDEV=/dev/loop0
MOUNTPOINT=$(ROOT_DIR)/mount
PASSWORD=foobar
.PHONY: default
@maleadt
maleadt / gist:ee1ab7e3127672395ad2
Created March 27, 2015 12:16
LaTeX macro to obfuscate text as an image (to prevent selecting, parsing, ...)
\makeatletter
\newcount\@imagecount
\newcommand\showasimage[1]{%
\global\advance\@imagecount 1
\edef\x{image-\the\@imagecount}%
\immediate\write18{echo '\unexpanded{\font\1=}\fontname\font' > \x.tex}%
\immediate\write18{echo '\unexpanded{\1#1\nopagenumbers\bye}' >> \x.tex}%
\immediate\write18{pdftex \x.tex}%
\immediate\write18{pdf2ps -dNoOutputFonts \x.pdf \x.ps}
\immediate\write18{ps2pdf \x.ps \x.pdf}