Skip to content

Instantly share code, notes, and snippets.

@joesavage
joesavage / wsp.py
Created March 17, 2019 15:25
Halldorsson's algorithm (WSP)
from math import sqrt
# Find an approximate solution to the weighted set packing problem using
# Halldorsson's algorithm (2000). Our approximate solution is at worst only a
# factor of sqrt(m) worse than the optimal solution.
#
# Input:
# S = { a, b, c... } # Set of base elements (m = |S|)
# C = { C_1, C_2, C_3, ... } # Collection of weighted subsets of S
# C_i = ({ a, c, ... }, weight) # Weighted subset of S
@joesavage
joesavage / commands.txt
Last active August 11, 2016 06:41
`dwarfdump` on macOS and Linux
=== macOS
$ clang -v
Apple LLVM version 7.0.2 (clang-700.1.81)
<snip>
$ clang hello.c -g -o hello.out
$ dwarfdump hello.out # NOTE: macOS-specific binary that reads Mach-O rather than ELF executables
----------------------------------------------------------------------
File: hello.out (x86_64)
----------------------------------------------------------------------
.debug_info contents:
# /etc/csh.login OR ~/.login
setenv SHELL /bin/bash
exec /bin/bash -l
Background: #202020
Font: Monaco, 11pt
Text: #CFCFCF
Bold Text: #CFCFCF
Selection: #CFCFCF (65% Opacity) / #9C9C9C
Cursor: #CFCFCF
ANSI Colours:
Black (0): #151515
Bright Black (8): #3E3E3E
Red (1): #9A2D32
@joesavage
joesavage / after.js
Created March 15, 2016 08:27
emscripten_suspend web worker test case
self.addEventListener('message', (function(e) {
var data = e.data;
switch (data.cmd) {
case 'init':
(function() {
run();
var desiredInput = "success";
var insertChar = (function(i, self) {
Module.userInput.push(desiredInput.charCodeAt(i));
Module.resume("char_ready");
(function() {
var desiredInput = "success";
var insertChar = (function(i, self) {
userInput.push(desiredInput.charCodeAt(i));
Module.resume("char_ready");
if (i < desiredInput.length) {
return setTimeout((function() { self(i + 1, self) }), Math.floor(Math.random() * 1500));
}
});
insertChar(0, insertChar);
row(0, R, R) :- !.
row(N, R, Acc) :- L is N - 1,
row(L, R, [N | Acc]).
% LESS EFFICIENT VERSION:
% row(0, []) :- !.
% row(N, R) :- L is N - 1,
% row(L, S),
% append(S, [N], R).
@joesavage
joesavage / zz.countries.nerd.dk.rbldnsd
Created July 26, 2014 14:38
zz.countries.nerd.dk.rbldnsd
This file has been truncated, but you can view the full file.
$SOA 7200 countries-ns.mdc.dk. read.the.homepage.at.http.countries.nerd.dk. 2013013100 28800 7200 604800 7200
5.224.7.0/24 :127.0.0.20:ad
5.224.254.0/23 :127.0.0.20:ad
5.225.7.0/24 :127.0.0.20:ad
5.225.254.0/23 :127.0.0.20:ad
31.201.76.0/24 :127.0.0.20:ad
37.19.14.248/29 :127.0.0.20:ad
37.222.7.0/24 :127.0.0.20:ad
37.222.254.0/23 :127.0.0.20:ad
37.223.254.0/23 :127.0.0.20:ad
@joesavage
joesavage / dabblet.css
Created January 24, 2014 19:27
Untitled
body {
background: #222;
text-align: center;
}
input {
font-size: 1.5em;
width: 20em;
margin-top: 2em;
}
# Basic Rewrites
location ~ ^(.*/)index(\.html)?$ { return 301 $scheme://$host$1; }
location ~ ^(/.+)\.html$ { return 301 $scheme://$host$1; }
location ~ /$ {
# 'try_files' > 'index', to avoid re-write/location rules.
try_files $request_uri/index.html $request_uri/index.php =404;
}
try_files $uri.html $uri/ =404;