Skip to content

Instantly share code, notes, and snippets.

@lski
lski / array.forEach-shim.js
Last active January 11, 2016 12:02
Simply shims array.forEach for projects that utilize it, such as the es6-promise-shim
/*!
* This is a copy of the shim provided by MDN
* https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
*/
(function () {
// Production steps of ECMA-262, Edition 5, 15.4.4.18
// Reference: http://es5.github.io/#x15.4.4.18
if (!Array.prototype.forEach) {
@lski
lski / LineF.cs
Created December 24, 2014 11:12
Represents a line (using decimal values) on a drawing pane. Can be used to simply represent two points.
using System;
/// <summary>
/// Represents a line (using decimal values) on a drawing pane. Can be used to simply represent two points.
/// </summary>
public class LineF {
public System.Drawing.PointF PointOne { get; set; }
public System.Drawing.PointF PointTwo { get; set; }
@lski
lski / XXTea.cs
Created December 24, 2014 13:29
A c# implementation of XXTea encryption algorithm based on the javascript version by Chris Veness
using System;
using System.Text;
/// <summary>
/// A class for encrypting and decrypting a string into base64 format which makes it safe for transfer
/// between applications.
///
/// Reference:
/// Based upon the javascript implementation of xxtea by: Chris Veness
/// www.movable-type.co.uk/tea-block.html
@lski
lski / Process.cs
Created December 24, 2014 14:41
Simple functions for working with processes
using System;
using System.Diagnostics;
using Dia = System.Diagnostics;
/// <summary>
/// Simple functions for working with processes
/// </summary>
public static class Process {
/// <summary>
@lski
lski / Impersonate.cs
Created December 24, 2014 14:59
IDisposible wrapper for running code as a different user. Designed to be using in an using statement.
using System;
using System.Runtime.InteropServices;
using System.Security.Principal;
/// <summary>
/// IDisposible wrapper for running code as a different user. Designed to be using in an using statement.
///
/// An adaptation of a sample from Msdn.
/// </summary>
public class Impersonate : IDisposable {
@lski
lski / Objects.cs
Created December 28, 2014 17:25
Offers simple static functions for exporting and importing an object to xml from and into a file
/// <summary>
/// Offers simple static functions for exporting and importing an object to xml from and into a file
/// </summary>
public static class Objects {
/// <summary>
/// Exports passed object to the file stated using a DataContractSerialiser to convert it into XML. REQUIRED A serializable attribute type recongnised by DataContractSerializer
/// E.g. Serializable, XmlSerializable, and DataContract
/// </summary>
/// <param name="filename">The file to export to</param>
@lski
lski / Object.keys-polyfill.js
Created July 21, 2015 15:47
Basic Object.keys polyfill
; (function () {
if (!Object.keys) {
Object.keys = function (o) {
if (o !== Object(o)) {
throw new TypeError('Object.keys called on a non-object');
}
@lski
lski / CorsOptionsExt.cs
Created July 27, 2015 09:51
Allows restriction of cors requests when using the app.UseCors() rather than just CorsOptions.AllowAll
/// <summary>
/// To be used with CorsMiddleware <code>app.UseCors()</code> where origins are restricted to the parameters passed in.
/// </summary>
public partial class CorsOptionsExt {
public static CorsOptions AllowOrigins(params string[] origins) {
return new CorsOptions() {
PolicyProvider = new CorsPolicyProvider() {
@lski
lski / array.map-shim.js
Last active January 11, 2016 09:53
An array.map polyfill created by MDN
// Required for code highlightpack
// Production steps of ECMA-262, Edition 5, 15.4.4.19
// Reference: http://es5.github.io/#x15.4.4.19
if (!Array.prototype.map) {
Array.prototype.map = function (callback, thisArg) {
var T, A, k;
if (this == null) {
@lski
lski / array.reduce-polyfill.js
Last active April 28, 2022 09:16
Array.reduce polyfill created by MDN, made available to use with NPM
// Production steps of ECMA-262, Edition 5, 15.4.4.21
// Reference: http://es5.github.io/#x15.4.4.21
if (!Array.prototype.reduce) {
Array.prototype.reduce = function(callback /*, initialValue*/) {
'use strict';
if (this == null) {
throw new TypeError('Array.prototype.reduce called on null or undefined');
}
if (typeof callback !== 'function') {
throw new TypeError(callback + ' is not a function');