Skip to content

Instantly share code, notes, and snippets.

View patbonecrusher's full-sized avatar
:octocat:

Patrick Laplante patbonecrusher

:octocat:
View GitHub Profile
@patbonecrusher
patbonecrusher / uniqueRandom.cs
Last active September 28, 2017 17:24
Generating a sequence of unique random numbers in C#
Random rnd = new Random();
var randomNumbers = Enumerable.Range(1, 100)
.Select(x => new { val = x, order = rnd.Next() })
.OrderBy(i => i.order)
.Select(x => x.val)
.ToArray();
@patbonecrusher
patbonecrusher / gist:667e51bf6a632a128629
Created October 14, 2014 14:49
Xamarin CGContext wrapper enabling you to the context in a using statement
using System;
using MonoTouch.CoreGraphics;
namespace Utilities
{
public class CGContextHelper : IDisposable
{
private readonly CGContext _context;
private bool _disposed;
@patbonecrusher
patbonecrusher / JS-LINQ.js
Created June 30, 2016 01:19 — forked from DanDiplo/JS-LINQ.js
JavaScript equivalents of some common C# LINQ methods. To help me remember!
// JS array equivalents to C# LINQ methods - by Dan B.
// Here's a simple array of "person" objects
var people = [
{ name: "John", age: 20 },
{ name: "Mary", age: 35 },
{ name: "Arthur", age: 78 },
{ name: "Mike", age: 27 },
{ name: "Judy", age: 42 },
{ name: "Tim", age: 8 }
@patbonecrusher
patbonecrusher / monelectron.js
Created August 23, 2016 15:41
how to auto restart electron browser process upon file changes
#!/usr/bin/env node
require('babel-register');
const electron = require('electron-prebuilt');
const proc = require('child_process');
const sleep = require('sleep');
const RxNode = require('rx-node');
const Rx = require('rx');
@patbonecrusher
patbonecrusher / ramda rename object properties
Created October 18, 2016 20:18
Given a list of oldname->newname mappings, it will rename object properties accordingly
export const renameKeys = R.curry((keysMap, obj) => {
return R.reduce((acc, key) => {
acc[keysMap[key] || key] = obj[key]
return acc
}, {}, R.keys(obj))
})
const permissionKeyMapping = { PermissionID: 'I', PermissionName: 'N' }
renameKeys(permissionKeyMapping, {PermissionID: 'a', PermissionName: 'b'}) // --> {I: 'a', N: 'b'}
@patbonecrusher
patbonecrusher / nginx-non-transparent-ssl-proxy.md
Created December 1, 2016 16:47 — forked from dannvix/nginx-non-transparent-ssl-proxy.md
Guide to set up nginx as non-transparent SSL proxy, which subsitutes strings in the server responses

Use nginx as Non-Transparent SSL Proxy

Introduction

Many mobile apps have back-end API servers. They usually rely on the API replies to determine whether certain information is supposed to be shown. If the API responses could be manipulated on the fly, we may easily fool an unmodified app to expose some private data.

This manual guides you to set up nginx as non-transparent SSL proxy, which just subsitutes strings in the server responses (i.e. man-in-the-middle attack ourself). For both server-side (their API servers) and client-side (your device), the whole process is almost transparent.

@patbonecrusher
patbonecrusher / nugetclear.sh
Created April 3, 2017 02:06
nuget clear cache
nuget locals all -clear
@patbonecrusher
patbonecrusher / RunningInNUnit
Last active August 1, 2017 03:47
To know if running inside nunit #dotnet #tdd
public static readonly bool IsRunningFromNUnit =
AppDomain.CurrentDomain.GetAssemblies().Any(
a => a.FullName.ToLowerInvariant().StartsWith("nunit.framework", StringComparison.Ordinal));
@patbonecrusher
patbonecrusher / better-nodejs-require-paths.md
Created May 9, 2017 01:28 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

var Article = require('../../../models/article');

Those suck for maintenance and they're ugly.

Possible solutions

public class TextMediaTypeFormatter : MediaTypeFormatter
{
public TextMediaTypeFormatter()
{
SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/plain"));
}
public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
{
var taskCompletionSource = new TaskCompletionSource<object>();