Skip to content

Instantly share code, notes, and snippets.

View taeber's full-sized avatar

Taeber Rapczak taeber

View GitHub Profile
@taeber
taeber / Expect.cs
Created October 25, 2012 20:35
xUnit.net inspired ExpectedExceptionAttribute alternative for MSTest
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace UnitTests
{
/// <summary>
/// Fluent interface for expected exceptions.
/// </summary>
/// <example>
/// Expect.Exception(() => DoSomethingBad())
@taeber
taeber / feecalc.php
Created November 14, 2012 02:50
PHP implementation of PayPal fee calculator
<?php
/// Start of a PayPal fee calculator that I'll probably never finish. :-[
/*
Given:
total(cost, fee) := cost + fee(cost)
fee(cost) := F + P*cost
F := $0.30
P := 2.9%
@taeber
taeber / AsyncLogger.cs
Created February 12, 2013 22:20
Asynchronous Logger using C# TPL
using System;
using System.Collections.Concurrent;
using System.Threading.Tasks;
public interface ILogger
{
void Log(string message);
}
class AsyncLogger : ILogger, IDisposable
@taeber
taeber / ObjectHelper.cs
Last active June 20, 2019 15:38
To return any object as an Enumerable...
using System.Collections.Generic;
public static class ObjectHelper
{
public static IEnumerable<T> AsEnumerable<T>(this T self)
{
yield return self;
}
}
@taeber
taeber / homm2.sh
Created June 24, 2013 14:52
Launch HOMM2 in separate X session
#!/bin/sh
# https://bbs.archlinux.org/viewtopic.php?id=150620
# xinit homm2.xinitrc -- :1
startx -- -depth 16 homm2.xinitrc :1
@taeber
taeber / OptionalDependency.cs
Created January 16, 2014 22:28
Demo of an OptionalDependency helper class which should prevent modifying an optional dependency (see Property Injection pattern) in the middle of a class's lifetime.
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
sealed class OptionalDependency<T> where T : class
{
private OptionalDependency() { }
private OptionalDependency(T defaultDependency)
{
if (defaultDependency == null)
@taeber
taeber / file.html
Created September 14, 2014 20:21
Playing around with the File API
<input type="file" id="input">
<br />
<pre id="output"></pre>
<script>
var output = document.getElementById("output");
var input = document.getElementById("input");
function handleFiles() {
var file = this.files[0];
@taeber
taeber / README.md
Last active August 31, 2017 21:37
C Metaprogramming

C Metaprogramming

Macros are used for metaprogramming in C. As an example, a generic List is typically implemented with macros, such as LIST_HEAD_INIT in the Linux kernal or LL_* in (https://troydhanson.github.io/uthash/utlist.html).

I tend to dislike macros, especially ones that emulate control structures and function-macros liberally shrewn about the code. I do like the idea of C++ metaprogramming, but it can get a bit obscure.

@taeber
taeber / visible.jsx
Created October 20, 2017 16:33
React Visible Component
// before:
var LoginLink = props => (
{!props.loggedIn &&
<a href="#login">Login</a>
}
);
const Visible = props => props.when && props.children;
// after:
@taeber
taeber / .eslintrc.js
Last active November 7, 2017 18:48
Airbnb eslint issue: comma-dangle
module.exports = {
"extends": "airbnb-base"
};