Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am milleniumbug on github.
  • I am milleniumbug (https://keybase.io/milleniumbug) on keybase.
  • I have a public key whose fingerprint is 61BE F024 E95B CDFC FFE0 354A E069 867F CF5D 84EA

To claim this, I am signing this object:

import collections, csv, itertools
recipes = collections.defaultdict(set)
tolerance = 0
with open('rec.csv') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
recipes[row[0]].add(row[1])
@milleniumbug
milleniumbug / mystatus.hs
Created February 8, 2016 15:28
append xmms2 status to i3status
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.Aeson as JS
import qualified Data.Aeson.Types as JST
import Data.Maybe (maybeToList)
import Data.Aeson ((.:), (.:?), (.=))
import qualified Data.Text.Lazy as T
import Data.Text.Lazy.Encoding as E
import qualified Control.Monad as M
import qualified Data.JsonStream.Parser as JSPar
@milleniumbug
milleniumbug / build.sh
Last active March 13, 2016 20:29
Wide on Fedora 23
#!/bin/bash
PREMAKE=$PWD/../premake/bin/release/premake4
$PREMAKE --llvm-path=$PWD/../llvm gmake
cd Wide
make -j `nproc` config=release64
cd ..
@milleniumbug
milleniumbug / powershell_fu.md
Last active March 5, 2017 16:44
for Unix converts

Note: PowerShell is object based, as opposed to byte stream based Unix utilities. This means text operations aren't that common, and also means many idioms aren't directly translateable.

Equivalents of common commands and idioms

  • var=text -> $var = object
  • cat file1 file2 file3 > target -> gc -Encoding Byte file1,file2,file3 | sc -Encoding Byte target (binary concatenation, with text files you can specify different encoding or let it guess)
  • curl -> iwr (Invoke-WebRequest)
  • date -> date (Get-Date)
  • man command-name -> help command-name (Get-Help)
@milleniumbug
milleniumbug / ddclient.conf
Created August 4, 2017 02:18
DynamicDNS configuration for dns.he.net
# /etc/ddclient.conf
ssl=yes
protocol=dyndns2
use=web
web=whatismyip.org
server=dyn.dns.he.net
login=<your domain name>
password='<your API key>'
<your domain name>
@milleniumbug
milleniumbug / passphrasegen.sh
Created August 4, 2017 03:15
Generate a passphrase from a dictionary file (like /usr/share/dict/english)
#!/bin/bash
if [ $# -lt 2 ]; then
echo "Usage: passphrasegen.sh path-to-dictionary number-of-words"
exit 1
fi
# TOFIX: the actual number of possible passwords is not N^M, but N*(N-1)*(N-2)*...*(N-M+1)
shuf -n "$2" "$1" --random-source /dev/urandom | paste -d\ --serial
public static class ObservableCollectionExtensions
{
public static IDisposable SuppressCollectionEvents(this INotifyCollectionChanged collection,
bool fireEventWhenComplete = true)
{
return new CollectionEventSuppressor(collection, fireEventWhenComplete);
}
private class CollectionEventSuppressor : IDisposable
{
public class ValueBased<T> : IEquatable<ValueBased<T>>
{
private static readonly IReadOnlyList<FieldInfo> fields;
static ValueBased()
{
fields = typeof(T).GetRuntimeFields().Where(field => !field.IsStatic).ToList();
}
/// <inheritdoc />
@milleniumbug
milleniumbug / rule_of_zero.cpp
Last active March 20, 2018 20:03
Rule of Zero introduction
#include <vector>
#include <iostream>
// nice little class A
class A
{
B b;
int a;
std::vector<int> allTheInts;
int doThisThing() { return b.stuff() + a; }