Skip to content

Instantly share code, notes, and snippets.

@gentam
gentam / install-postgis-amazon-linux2.sh
Created March 16, 2023 07:54
Install PostGIS 3.1.5 for PostgreSQL 13.10 on Amazon Linux 2
# Install PostGIS 3.1.5 for PostgreSQL 13.10 on Amazon Linux 2
# ref:
# - https://ja.stackoverflow.com/questions/75401/amazon-linux2-%E3%81%B8-postgresql-postgis-%E3%82%92%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB%E3%81%97%E3%81%9F%E3%81%84
# - https://qiita.com/tmiki/items/00d22edc6a554f61bd04
sudo yum update -y
sudo amazon-linux-extras install epel
sudo yum install -y epel-release
@gentam
gentam / servefile.sh
Created April 7, 2022 08:53
serve a file with netcat on macOS
#!/bin/bash -e
[ $# -ne 1 ] && { echo "Usage: `basename $0` <filename>"; exit 1; }
F=$1
IP=`ifconfig en0 | awk '/inet / {print $2}'`
PORT=8080
ADDR="$IP:$PORT"
echo $ADDR | pbcopy
echo "serving $F at $ADDR (copied)"
@gentam
gentam / prependBOM.sh
Last active April 25, 2022 08:45
prepend a UTF-8 byte order mark (BOM) to a file
#!/bin/bash -e
[ $# -ne 1 ] && { echo "Usage: `basename $0` <filename>"; exit 1; }
F=$1
echo -en '\xEF\xBB\xBF' | cat - "$F"
// cc -Wall -lm dmod.c -o dmod && ./dmod
#include <stdio.h>
#include <math.h>
static inline double dmod(double n, double d) { return n - floor(n/d)*d; }
int main() {
double n = -0.1;
double d = 20.0;
Lambda Calculus Examples
========================
Alpha-Beta Conversion
---------------------
(λu. (λx. x (λy. x y)) u ((λu. u)(λw. w))) (λz. (λv. z v y))
-α-> (λu. (λx. x (λy. x y)) u ((λa. a)(λw. w))) (λz. (λv. z v y))
-β-> (λx. x (λy. x y)) (λz. (λv. z v y)) ((λa. a)(λw. w))
-β-> (λx. x (λy. x y)) (λz. (λv. z v y)) (λw. w)
-α-> (λx. x (λa. x a)) (λz. (λv. z v y)) (λw. w)
@gentam
gentam / aax2mp4.sh
Created November 18, 2018 22:38
convert Audible AAX file to MP4
#!/usr/bin/env bash
[ $# -ne 1 ] && { echo >&2 "Usage: `basename $0` audiobook.aax"; exit 1; }
type ffmpeg > /dev/null 2>&1 || { echo >&2 "Error: ffmpeg required"; exit 1; }
SRC="$1"
ACTIVATION_BYTES='' # can be obtained by audible-activator <https://github.com/inAudible-NG/audible-activator>
[ "$ACTIVATION_BYTES" = '' ] && read -p '4 byte activation secret (e.g. 1CEB00DA): ' ACTIVATION_BYTES
ffmpeg -activation_bytes "$ACTIVATION_BYTES" -i "$SRC" -vn -c:a copy "${SRC%.aax}.mp4"
@gentam
gentam / unification.txt
Created November 2, 2018 00:27
Unification example for type inference
Unification Algorithm
=====================
Attempt 1
---------
Unify
{ (F('a,F('b,'b)) = F(P('c,L('c)), F(P('e,L('d)),P('c,'f))))
, (P(P(N,'d),'c) = P('a,'c))
}
set terminal svg
set output 'mult_tiled_1024.svg'
set grid
set title 'Tiled Matrix Multiplication (when N=1024): time vs. tile\_size'
set ylabel 'Time (sec)'
set xlabel 'tile\_size'
set yrange [9:15]
show label
plot './mult_tiled_1024.dat' with linespoints notitle, \
'./mult_tiled_1024.dat' using 1:2:(sprintf("%d", $1)) with labels offset 1,1 notitle
@gentam
gentam / matrix.cpp
Created September 28, 2018 05:42
matrix multiply and transpose optimizations
#define IND(row,col,n) ((row)*n+(col))
void transpose_basic(double* A, double* B, int N) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
B[IND(i,j,N)] = A[IND(j,i,N)];
}
}
}
@gentam
gentam / pingall.sh
Created September 21, 2018 20:29
ping all IP addresses in the subnet and print the result
#!/usr/bin/env bash
NETADDR='192.168.1'
for ip in "$NETADDR".{1..254}; do
echo -n $ip
ping -c1 -W1 "$ip" > /dev/null 2>&1 && echo ' ok' || echo
sleep 0.25
done