Skip to content

Instantly share code, notes, and snippets.

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 />
public static class ObservableCollectionExtensions
{
public static IDisposable SuppressCollectionEvents(this INotifyCollectionChanged collection,
bool fireEventWhenComplete = true)
{
return new CollectionEventSuppressor(collection, fireEventWhenComplete);
}
private class CollectionEventSuppressor : IDisposable
{
@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; }
@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 / 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 / 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 / java_rant.txt
Last active May 7, 2023 21:49
why Java sucks
Let's start with: Java is a language that one would create when looking at the state of C++ in early 90's and thinking how can I make it "better" in terms of being error prone.
But this was only an evolution instead of a revolution STL introduced as a way of programming
(sure, they weren't first, but I'd say they were the first to introduce it to masses)
The rest is a consequence of being backward
Problem with null pointers? Still there
Speaking of pointers in Java, I like how Java fans continuously say "they're not pointers, they're references"
But guess what happens when you access a null reference? A NullPointerException is thrown
So what I don't like?
Collections API. Just terrible.
The "unmodifiable" lists are your regular lists that throw exceptions on modifications
@milleniumbug
milleniumbug / shared_resource.hpp
Created January 22, 2017 13:29
shared_resource<T>
#pragma once
#include <mutex>
#include <shared_mutex>
#include <type_traits>
#include <tuple>
template<typename Mutex = std::shared_timed_mutex>
struct Shared
{
typedef Mutex MutexType;
@milleniumbug
milleniumbug / rng.md
Last active May 10, 2018 15:38
Resources on random number generation (PRNGs, CSPRNGs, distributions, statistical tests, and so on)