Skip to content

Instantly share code, notes, and snippets.

View jcdickinson's full-sized avatar
🐵

Jonathan Dickinson jcdickinson

🐵
View GitHub Profile
@jcdickinson
jcdickinson / Program.Bar.il
Last active August 29, 2015 13:56
Accessing Structs Methods via Interfaces
.method private hidebysig static
bool Bar<(class [mscorlib]System.IEquatable`1<valuetype ConsoleApplication4.MyEquatableThing>) -T> (
!!T obj1,
!!T obj2
) cil managed
{
// Method begins at RVA 0x20a4
// Code size 22 (0x16)
.maxstack 2
.locals init (
@jcdickinson
jcdickinson / Program.cs
Created February 20, 2014 09:02
Not Calling EndInvoke Does Not Leak Memory
class Program
{
static void Main(string[] args)
{
var last = 0L;
for (var i = 0; i < 100000; i++ )
{
var fn = new Func<ReallyBigObject>(Test);
var iar = fn.BeginInvoke(null, null);
@jcdickinson
jcdickinson / AssetManager.cpp
Created July 29, 2014 11:46
Fancy Asset Loading
#include "stdafx.h"
#include "AssetManager.hpp"
AssetManager::AssetManager()
{
}
AssetManager::~AssetManager()
@jcdickinson
jcdickinson / MakeArrayType.cs
Created August 7, 2014 15:47
MakeArrayType
Type MakeArrayType(Type elementType, int rank)
{
if (rank == 1)
return elementType.MakeArrayType();
else
return elementType.MakeArrayType(rank);
}
@jcdickinson
jcdickinson / manymouse.d
Last active August 29, 2015 14:07
ManyMouse Derelict Bindings
module derelict.manymouse.manymouse;
private {
import derelict.util.loader;
import derelict.util.system;
static if( Derelict_OS_Windows )
enum libNames = "manymouse.dll";
else static if( Derelict_OS_Mac )
enum libNames = "manymouse.dylib";
@jcdickinson
jcdickinson / Readme.md
Last active August 29, 2015 14:11
Proof-of-work JS

POW?

[The idea isn't new.][1] It's a technique that asks the client to perform proof-of-work in order to increase the costs associated with spamming a website. For a single user the workload shouldn't be an issue at all, but a spammer (or indeed a brute-forcing hacker) might run into problems with being able to maintain a high throughput of requests. Validating the proof of work is trivially computational and hence will not put your server under the same amount of stress.

POWJS on my laptop takes 17 seconds to solve the problem in Chrome (50 seconds in IE 11) with 22 bits required to be zero. The workload can be started as soon as the user opens the page and will run asyncronously in the background (in a web worker if the browser supports them).

POWJS uses CryptoJS, but won't pollute your global namespace with it. This can't be used (as-is) to farm bitcoins or what-have-you, it merely performs a random POW.

Usage

@jcdickinson
jcdickinson / Program.cs
Created July 8, 2015 17:11
ThreadContext
using System;
using System.Threading;
using System.Threading.Tasks;
namespace ContextDemo
{
class SimpleContext : SynchronizationContext
{
public override void Post(SendOrPostCallback d, object state)
{
@jcdickinson
jcdickinson / Demo.cs
Created July 8, 2015 18:13
Return To SynchronizationContext
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
async void button1_Click(object sender, EventArgs e)
{
var context = SynchronizationContext.Current;
using System.Security.Cryptography;
/// <summary>
/// Represents the Murmur 3 Hash Algorithm.
/// </summary>
/// <remarks>
/// Murmur 3 is not cryptographically secure, instead it is used
/// for content identification.
/// </remarks>
public sealed class Murmur3 : HashAlgorithm
@jcdickinson
jcdickinson / Program.cs
Created August 17, 2015 11:07
Find All Roots For Type
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Diagnostics.Runtime;
using System.IO;
using System.Collections;
using System.Diagnostics;
namespace EEHeap