Skip to content

Instantly share code, notes, and snippets.

View jamescrowley's full-sized avatar

James Crowley jamescrowley

View GitHub Profile
@jamescrowley
jamescrowley / main.js
Last active March 31, 2020 03:18
Repro for Jest issue
'use strict';
const firebase = require("firebase-admin");
const serviceAccount = require('./serviceAccountKey.json');
firebase.initializeApp({
credential: firebase.credential.cert(serviceAccount),
databaseURL: `https://${serviceAccount.project_id}.firebaseio.com`
});
@jamescrowley
jamescrowley / JsonValidatingModelBinder.cs
Last active September 29, 2019 09:48
Validating JSON with ASP.NET request validation
public class JsonValidatingModelBinder : DefaultModelBinder
{
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var result = base.BindModel(controllerContext, bindingContext);
if (!IsJsonRequest(controllerContext))
{
return result;
}
if (!bindingContext.ModelMetadata.RequestValidationEnabled)
@jamescrowley
jamescrowley / SharedKeyDictionary.cs
Last active August 18, 2019 20:32
SharedKeyDictionary.cs
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
namespace MemoryOptimisations
{
public sealed class SharedKeyDictionary<TKey, TValue> : IReadOnlyDictionary<TKey, TValue> where TValue : class
{
admin
.auth()
.listUsers()
.then(listUsersResult => {
const selectedUser = listUsersResult.users.filter(
usr => usr.email.toLocaleLowerCase() === testUserEmail
);
if (selectedUser.length > 0) {
return Promise.resolve();
@jamescrowley
jamescrowley / migrate.ps1
Created July 14, 2018 20:47
Migrate to new CS Project format
function Extract-ProjectReferences ($projectFile) {
[regex]::matches((Get-Content $projectFile), '<ProjectReference Include=\"([^"]*)\"') | ForEach-Object { $_.Groups[1].Value }
}
function Extract-NuGetReferences ($nugetFile) {
[regex]::matches((Get-Content $nugetFile), '<package id=\"([^"]*)\" version=\"([^"]*)\"') | ForEach-Object { @{ Name = $_.Groups[1].Value; Version = $_.Groups[2].Value } }
}
function Get-UpgradedProjectFile ($projectFile) {
@jamescrowley
jamescrowley / 01-Startup.cs
Last active July 12, 2016 21:59
Global OWIN handling of errors & page not found
public class Startup
{
public void Configuration(IAppBuilder app)
{
app
.Use<StatusCodeFromExceptionMiddleware>()
.UseNancy();
}
}
@jamescrowley
jamescrowley / gist:7676415
Created November 27, 2013 14:20
Clock for Testing/freezing time
public static class Clock
{
private static DateTime? _frozenTime;
/// <summary>
/// Gets a <see cref="DateTime"/> object that is set to the current date and time on this computer,
/// expressed as the local time.
/// </summary>
public static DateTime Now
{
@jamescrowley
jamescrowley / ZenDeskResponseHandler.py
Last active November 12, 2015 18:47
ZenDesk event handler in Splunk using rest
class ZenDeskEventHandler:
def __init__(self,**args):
pass
#process the received JSON array
def process_automatic_response(self,data):
output = json.loads(data)

2015-01-29 Unofficial Relay FAQ

Compilation of questions and answers about Relay from React.js Conf.

Disclaimer: I work on Relay at Facebook. Relay is a complex system on which we're iterating aggressively. I'll do my best here to provide accurate, useful answers, but the details are subject to change. I may also be wrong. Feedback and additional questions are welcome.

What is Relay?

Relay is a new framework from Facebook that provides data-fetching functionality for React applications. It was announced at React.js Conf (January 2015).

@jamescrowley
jamescrowley / Costs (tab separated).tsv
Last active August 29, 2015 14:13
AWS/Rackspace/Azure SQL Server Licensing
Description Cores Windows VM USD/hr SQL VM USD/hr SQL License USD/hr SQL License USD/mo SQL License USD/core/mo
4 cores
Rackspace - General1-4 (4 cores, 4GB RAM) 4 0.168 0.768 0.600 438.00 109.50
Rackspace - io1-15 (4 cores, 15GB RAM) 4 0.600 1.150 0.550 401.50 100.38
Rackspace - Memory1-30 (4 cores, 30GB RAM) 4 0.480 1.080 0.600 438.00 109.50
Azure - D12 (4 cores, 28 GB RAM) 4 0.732 1.160 0.428 312.51 78.13
AWS - m3.xlarge (4 cores, 15GB RAM) 4 0.532 1.280 0.748 546.04 136.51
AWS - r3.xlarge (4 cores, 30.5gb ram) 4 0.600 1.395 0.795 580.35 145.09
AWS - c4.xlarge (4 cores, 7.5GB RAM) 4 0.430 1.727 1.297 946.81 236.70
8 cores