Skip to content

Instantly share code, notes, and snippets.

View niik's full-sized avatar

Markus Olsson niik

  • GitHub Staff
  • Sweden
  • 05:54 (UTC +01:00)
  • X @niik
View GitHub Profile
@niik
niik / uuid.ts
Created April 27, 2017 09:26
Workaround for uuid/getRandom slowness in Electron
import { randomBytes as nodeCryptoGetRandomBytes } from 'crypto'
// Work around synchronously seeding of random buffer in the v1
// version of uuid by explicitly only requiring v4. As far as I'm
// aware we cannot use an import statement here without causing webpack
// to load the v1 version as well.
//
// See
// https://github.com/kelektiv/node-uuid/issues/189
const guid = require('uuid/v4') as (options?: { random?: Buffer }) => string
@niik
niik / RetryWithBackOffStrategy.cs
Last active October 2, 2021 01:42
An Rx retry operator with a customizable back off strategy.
// Licensed under the MIT license with <3 by GitHub
/// <summary>
/// An exponential back off strategy which starts with 1 second and then 4, 9, 16...
/// </summary>
[SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
public static readonly Func<int, TimeSpan> ExponentialBackoff = n => TimeSpan.FromSeconds(Math.Pow(n, 2));
/// <summary>
/// Returns a cold observable which retries (re-subscribes to) the source observable on error up to the
@niik
niik / IsoWeek.cs
Created January 27, 2012 11:47
ISO 8601 Week abstraction
/*
* Copyright (c) 2011 Markus Olsson
*
* var mail = string.Join(".", new string[] {"j", "markus", "olsson"}) + string.Concat('@', "gmail.com");
* var blog = http://blog.freakcode.com
*
* MIT License follows.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software without
@niik
niik / read-tickster-dump.php
Created January 18, 2012 11:18
Compressed Tickster dump file reader
<?php
// Sample code for reading a compressed Tickster dump file in php
// Usage: php read-tickster-dump.php [FILENAME]
// http://docs.php.net/manual/sr/function.gzfile.php#54255
function gzfile_get_contents($filename, $use_include_path = 0)
{
//File does not exist
if( !@file_exists($filename) )
@niik
niik / RedirectingStream.cs
Created November 17, 2011 12:28
RedirectingStream
/*
* Copyright (c) 2008-2009 Markus Olsson
* var mail = string.Join(".", new string[] {"j", "markus", "olsson"}) + string.Concat('@', "gmail.com");
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
@niik
niik / ApiDumpExample.cs
Created September 22, 2011 12:17
Event dump example
/*
* Copyright (c) 2011 Markus Olsson, Tickster AB
* var mail = string.Join(".", new string[] {"markus", "olsson"}) + string.Concat('@', "tickster.com");
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
@niik
niik / ContentDispositionUtils.cs
Created July 12, 2011 17:14
ContentDispositionUtils
/*
* Copyright (c) 2011 Markus Olsson
* var mail = string.Join(".", new string[] {"j", "markus", "olsson"}) + string.Concat('@', "gmail.com");
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
@niik
niik / CryptoRandom.cs
Created June 9, 2011 21:48
Buffered CryptoRandom implementation based on Stephen Toub and Shawn Farkas' CryptoRandom
/*
* Original version by Stephen Toub and Shawn Farkas.
* Random pool and thread safety added by Markus Olsson (freakcode.com).
*
* Original source: http://msdn.microsoft.com/en-us/magazine/cc163367.aspx
*
* Some benchmarks (2009-03-18):
*
* Results produced by calling Next() 1 000 000 times on my machine (dual core 3Ghz)
*