Skip to content

Instantly share code, notes, and snippets.

@rhaberkorn
rhaberkorn / aes.apl
Last active November 11, 2023 14:07
AES in GNU APL
⍝ Left rotate ⍺ bit
Rot8 ← {2⊥⍺⌽(8⍴2)⊤⍵}
⍝ Addition and subtraction in finite field GF(2)
Add2 ← {⍺ ⊤≠ ⍵}
⍝ Multiplication in GF(2) [x]/(x8 + x4 + x3 + x + 1)
Mul2 ← {⊤≠/({⍵,$FF ⊤∧ ($11B×$80≤¯1↑⍵) ⊤≠ 2ׯ1↑⍵}⍣7 ⍺) × ⌽(8⍴2)⊤⍵}
⍝ Multiplicative inverse, calculated by brute force
Mul2Inv ← {$FF ⊤∧ 1⍳⍨⍵ Mul2¨⍳255}
SBox ← {⊤≠/$63,(1-⍨⍳5) Rot8¨Mul2Inv ⍵}¨1-⍨⍳256
@samoshkin
samoshkin / toggle_keybindings.tmux.conf
Last active February 5, 2024 02:26
tmux.conf excerpt to toggle on/off session keybindings and prefix handling
bind -T root F12 \
set prefix None \;\
set key-table off \;\
set status-style "fg=$color_status_text,bg=$color_window_off_status_bg" \;\
set window-status-current-format "#[fg=$color_window_off_status_bg,bg=$color_window_off_status_current_bg]$separator_powerline_right#[default] #I:#W# #[fg=$color_window_off_status_current_bg,bg=$color_window_off_status_bg]$separator_powerline_right#[default]" \;\
set window-status-current-style "fg=$color_dark,bold,bg=$color_window_off_status_current_bg" \;\
if -F '#{pane_in_mode}' 'send-keys -X cancel' \;\
refresh-client -S \;\
bind -T off F12 \
@marcan
marcan / brainfuck.sh
Created April 22, 2016 01:27
Brainfuck interpreter in POSIX sh
#!/bin/sh
# Brainfuck interpreter implemented in pure POSIX sh builtins only (except I/O)
# Tested in bash and busybox ash (getchar uses a bash-specific read)
# === I/O ===
getchar() {
# bashism
IFS= read -rN 1 a
if [ -z "$a" ]; then
echo $th
@lydell
lydell / bigrams-to-pairs.js
Created August 23, 2015 08:54
English bigram and letter pair frequencies from the Google Corpus Data in JSON format
// By Simon Lydell 2015.
// This file is in the public domain.
var stdin = require("get-stdin")
var tools = require("text-frequencies-analysis")
var helpers = require("text-frequencies-analysis/lib/helpers")
stdin(function(text) {
process.stdout.write(tools.jsonStringifyRow(convert(JSON.parse(text))))
})
@ijansch
ijansch / jsonarrayfun.php
Last active August 29, 2015 14:05
2 common issues in php based apis
<?php
// Issue 1, empty associative arrays (dictionaries) become regular arrays.
$dictionary = array('key' => 'value');
var_dump(json_encode($dictionary)); // gives '{"key":"value"}';
unset($dictionary['key']);
var_dump(json_encode($dictionary)); // Gives '[]' -> json dictionary turned into array
@aras-p
aras-p / preprocessor_fun.h
Last active May 18, 2024 08:55
Things to commit just before leaving your job
// Just before switching jobs:
// Add one of these.
// Preferably into the same commit where you do a large merge.
//
// This started as a tweet with a joke of "C++ pro-tip: #define private public",
// and then it quickly escalated into more and more evil suggestions.
// I've tried to capture interesting suggestions here.
//
// Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_,
// @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant,
@willurd
willurd / web-servers.md
Last active May 17, 2024 16:24
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@eirikbacker
eirikbacker / addEventListener-polyfill.js
Created June 3, 2012 19:30
addEventListener polyfill for IE6+
//addEventListener polyfill 1.0 / Eirik Backer / MIT Licence
(function(win, doc){
if(win.addEventListener)return; //No need to polyfill
function docHijack(p){var old = doc[p];doc[p] = function(v){return addListen(old(v))}}
function addEvent(on, fn, self){
return (self = this).attachEvent('on' + on, function(e){
var e = e || win.event;
e.preventDefault = e.preventDefault || function(){e.returnValue = false}
e.stopPropagation = e.stopPropagation || function(){e.cancelBubble = true}
anonymous
anonymous / xmms2addcover.pl
Created September 17, 2010 03:35
#!/usr/bin/perl
# Add cover images to XMMS2 medialib entries from file.
use strict;
use Audio::XMMSClient;
sub fold(&@) {
my $f = shift;
local ($a,$b) = (shift,undef);
$a = $f->($a, $b) while defined ($b = shift);
return $a;