Skip to content

Instantly share code, notes, and snippets.

@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
@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; }
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 / rules.md
Last active March 31, 2018 19:22
Basic ground rules on multithreading

Following the analogy of basic ground rules, here I'm trying to come up with a similar list for multithreading.

  1. Nothing is thread safe unless effort has been made to make it thread safe.
  2. You can't assume that composition of two thread safe operations (g(f());) or objects is thread safe itself. This is a special case of the rule 1.
@milleniumbug
milleniumbug / swallow-idiom.md
Created March 31, 2018 19:49
Swallow idiom description

some text goes here

#include <random>
#include <iostream>
int main()
{
std::random_device rd;
std::uniform_int_distribution<> dist(-1000000, 1000000);
for(int i = 0; i < 10000000; ++i)
std::cout << dist(rd) << "\n";
}
@milleniumbug
milleniumbug / install_hub.sh
Created June 27, 2018 22:18 — forked from Taytay/install_hub.sh
Install latest version of Github's hub on Linux
#!/bin/bash
# Installs latest release of hub on Linux
# Echo, halt on errors, halt on uninitialized ENV variables. (https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/)
set -euxo pipefail
# Hub doesn't have a way to install the latest version using `apt` yet, so I wrote this as a hacky substitute.
# This will be unnecessary when this issue is resolved: https://github.com/github/hub/issues/718#issuecomment-65824284
# Linux options include:
@milleniumbug
milleniumbug / android_rant.txt
Created July 2, 2018 19:31
why Android sucks
wow fuck android
the general platform is fundamentally broken and even the open source applications are hilariously broken for many reasons
you have no way of distinguishing client and non-client area in general when you visit web, so have fun distinguishing ads from real UI elements - very needed when you want to distinguish ads. since you can't block ads without rooting reliably, rooting is required to have usable Android experience
if you visit a website and you want to download a specific image you can typically long-press it - unless shitty scripts break the functionality, in which case it results in endless "I long-press a button, some random text gets selected"
sometimes it may result in you actually managing to trigger the popup
but sometimes nope
on normal PC you would just "inspect element" that shit out
and in general it's bullshit when you actually want to anything beyond "consume internet content"
I have this file manager that I have been using for a while, except now it seems to fail copy from a