Skip to content

Instantly share code, notes, and snippets.

@resilar
resilar / lyn.c
Created June 15, 2016 14:23
Lyndon factorization
/**
* Compute the Lyndon factorization of S[0..n-1].
* O(n) time and O(1) space blabla.
*
* ... because Duval's algorithm is a piece of shit.
*/
void lyn(unsigned char *S)
{
int u, v;
u = v = 0;
@resilar
resilar / spoiler.pl
Last active February 25, 2017 19:11
irssi script
use strict;
use warnings;
use Irssi;
our $VERSION = '0.0.6283185307';
our %IRSSI = (
authors => 'def',
contact => 'def <def@lelantos.org>',
name => 'spoiler',
description => 'Colorize lines of idiots with black on black text',
@resilar
resilar / irc.rs
Last active September 23, 2017 07:38
babby's first irc client in rust
use irc::command::{IrcCommand};
use futures::stream::{self, Stream};
use futures::sync::mpsc::{self, UnboundedReceiver, UnboundedSender};
use futures::{future, Future};
use tokio_core::net::TcpStream;
use tokio_core::reactor::Handle;
use tokio_io::{io, AsyncRead};
@resilar
resilar / offsetof.rs
Last active March 10, 2018 09:07
offset_of & container_of macros for Rust
#[derive(Debug)]
struct Foo {
p: u16,
q: u32,
}
macro_rules! offset_of {
($container:ty, $field:ident) => (unsafe {
&(*(0usize as *const $container)).$field as *const _ as usize
})
@resilar
resilar / pam_badlog.c
Last active November 27, 2018 13:51
PAM module to log bad SSH passwords (for non-/home/ users only)
/*
* pam_badlog.c
*
* $ gcc -fPIC -fno-stack-protector -c pam_badlog.c
* $ sudo ld -x --shared -o /lib/security/pam_badlog.so pam_badlog.o
* $ rm pam_badlog.o
*
* then add "auth required pam_badlog.so" in the beginning of /etc/pam.d/sshd
*
* $ /etc/init.d/sshd restart
@resilar
resilar / tormap.py
Last active July 11, 2019 10:59
map(GET(url)) over Tor exit nodes
#!/usr/bin/env python
TORPROXY=("localhost", 9050)
CONTROLPORT=9051
COOKIE="/var/lib/tor/control_auth_cookie"
URL="http://showip.net"
OUT="scan/"
RELAY="firsthop"
EXITS="exit-addresses"
@resilar
resilar / opt.tex
Last active October 8, 2019 12:20
The *correct* way to typeset optimization problems in LaTeX
% Output: http://i.imgur.com/88G3s9V.png
\begin{equation}
\begin{split}
& \text{\large Primal} \\
\text{min } & \sum_{j=1}^s x_j + Bz \\
\text{s.t. } &
\begin{aligned}[t]
x_j + z &\ge 1 & \forall j = 1,2,\dots,s \\
x_j &\ge 0 & \forall j = 1,2,\dots,s \\
z &\ge 0
@resilar
resilar / makeuniq.rs
Created March 10, 2018 08:11
Remove duplicate lines without sorting
// rustc -O makeuniq.rs
// cat .bash_history | ./makeuniq > .bash_history_uniq
use std::io::{self, Write};
use std::io::prelude::BufRead;
use std::collections::HashSet;
fn main() {
let mut uniqs = HashSet::new();
@resilar
resilar / .zshrc
Last active August 22, 2021 23:57
Dynamic window title with zsh shell
# Dynamic window title with zsh shell.
# Shows current directory and running (multi-line) command.
case "$TERM" in (rxvt|rxvt-*|st|st-*|*xterm*|(dt|k|E)term)
local term_title () { print -n "\e]0;${(j: :q)@}\a" }
precmd () {
local DIR="$(print -P '[%c]%#')"
term_title "$DIR" "zsh"
}
preexec () {
local DIR="$(print -P '[%c]%#')"
@resilar
resilar / zylom.c
Last active September 21, 2021 02:04
zylom trivial pursuit genus edition questions.dat.! (de)cryptor
#include <stdio.h>
static const unsigned char D[256] =
"\x3E\x29\xEB\x7F\x9E\xB9\x60\xC7\x8B\x18\x77\xA0\xD3\x35\xB5\x5F"
"\x44\x49\x1B\x74\xA3\x6A\xF5\xCD\x28\x88\x0C\x53\x01\xA4\xB6\x47"
"\x2E\x65\x9B\xC5\x83\x66\x10\x22\xDF\xFD\xD1\x70\x0A\xB1\x8A\xA9"
"\xF3\x21\x6B\x30\xF4\x27\xBC\x11\x15\xDD\xF7\xED\x48\xE1\x17\x9A"
"\x46\xC4\xB7\x6C\xD0\x91\xAA\x8E\xCC\xC6\x1F\x2C\x73\xDB\x5D\x71"
"\x1E\x6F\xFC\x33\xCA\x25\xF2\x4D\x0B\x1C\xF6\x06\xB8\x26\xC9\x36"
"\xB3\xE0\xBE\xD2\xDE\x67\xE6\x4F\x81\x3F\xF0\xD7\xC3\x00\x75\x6E"