Skip to content

Instantly share code, notes, and snippets.

@fschwiet
fschwiet / Main.cs
Last active September 13, 2022 20:24
experimenting with default interface implementation overrides in C#
using System;
public interface ISparrow
{
double GetAirspeed() => 1.0;
}
public class AfricanSparrow : ISparrow
{
public double GetAirspeed() => 2.0;
@fschwiet
fschwiet / gist:ff088954086c402ae7a42ae3a8d3d7c2
Last active October 3, 2017 04:54
autoclicker for online challenge cookie clicker
// Autoclicker for Cookie Clicker, Cookie Clicker is at http://orteil.dashnet.org/cookieclicker/
// Run it in the debug console
var clicky = function() { ($(".shimmer") || $("#bigCookie")).click(); setTimeout(clicky, 30); };
clicky();
@fschwiet
fschwiet / gist:05ffd75570755688cafff7cf3e2c62e6
Last active September 28, 2016 19:21
Experimenting with Reactive schedulers
Experiment code:
var emitter = new Subject<string>();
var schedulers = new[]
{
new KeyValuePair<string, IScheduler>("EventLoop", new EventLoopScheduler()),
new KeyValuePair<string, IScheduler>("RxApp.MainThreadScheduler", RxApp.MainThreadScheduler),
new KeyValuePair<string, IScheduler>("RxApp.TaskpoolScheduler", RxApp.TaskpoolScheduler),
};
@fschwiet
fschwiet / gist:8343378
Created January 9, 2014 22:34
just dreamin
<<someHypthoticalScriptCS command: inherit from GivenWhenThenFixture override Specify>>
var someDllPath = arrange(() => GetPathOfBinDeployed("SomeTestLibrary.dll"));
expect(() => File.Exists(someDllPath));
given("an AppDomain wrapper for a test DLL", delegate()
{
    var appDomainWrapper = arrange(() => new AppDomainWrapper(someDllPath));
@fschwiet
fschwiet / gist:7902608
Created December 10, 2013 23:55
How to simplify this code? Promises won't help, as leaving the stack causes the IndexedDB transactions to close.
function remix(recording, frameSwitches) {
var keyRanges = [];
var lastRecordingId = null;
var lastTimeRange = Number.MIN_VALUE;
frameSwitches.switches.forEach(function(frameSwitch) {
if (lastRecordingId !== null) {
@fschwiet
fschwiet / gist:6627425
Last active December 23, 2015 11:19
Quick reference for Javascript's apply, call and related functions.
Function.prototype.apply(thisArg[, argsArray])
Function.prototype.call(thisArg[, arg1[, arg2[, ...]]])
Q.nfcall(FS.readFile, "foo.txt", "utf-8");
Q.nfapply(FS.readFile, ["foo.txt", "utf-8"]);
Q.ninvoke(FS, "readFile", "foo.txt", "utf-8");
Q.npost(FS, "readFile", ["foo.txt", "utf-8"]);
Q.nbind(FS.readFile, FS)("foo.txt", "utf-8");
var input = "e299a5205765204d616b652054756d6d792048617070792120e299a5"
var output = new Buffer(input.length / 2);
for(var i = 0; i < input.length / 2; i++) {
output[i] = parseInt(input.slice(i*2, i*2 + 2), 16);
}
console.log(output.toString('utf8'));
@fschwiet
fschwiet / gist:5803151
Last active December 18, 2015 15:19
feedparser repro
var FeedParser = require('feedparser'), request = require('request'), endpoint = require('endpoint');
function runOne(url) {
console.log("starting " + url);
request(url, function(error, response, body) {
if (error !== null) {
console.log("error A " + error);
console.log("done with " + url);
@fschwiet
fschwiet / gist:5667135
Last active January 7, 2016 00:14
trying to use promises with phantomjs
var Q = require("q");
var phantom=require('node-phantom');
function promisify(nodeAsyncFn, context, modifier) {
return function() {
var args = args = Array.prototype.slice.call(arguments);
var defer = Q.defer()
args.push(function(err, val) {
@fschwiet
fschwiet / gist:3037986
Created July 3, 2012 06:02
use SinonJS XHR to spy on outgoing AJAX requests - useful for debugging
// SinonJS's XHR support is great for unit testing code that makes
// AJAX requests. But you can also use it to measure AJAX requests
// made from production code if you insert the below code snippet.
// full docs here: http://sinonjs.org/docs/#server
sinon.useFakeXMLHttpRequest();
sinon.FakeXMLHttpRequest.useFilters = true;
sinon.FakeXMLHttpRequest.addFilter(function (method, url, async, username, password) {