Skip to content

Instantly share code, notes, and snippets.

View gabrieljoelc's full-sized avatar

Gabriel Chaney gabrieljoelc

View GitHub Profile
@gabrieljoelc
gabrieljoelc / FindMalformedYaml.rb
Created March 25, 2013 20:44
Script to find malformed YAML files. Ripped off from http://stackoverflow.com/a/9848226.
require 'yaml'
d = Dir["./**/*.yml"]
d.each do |file|
begin
puts "checking : #{file}"
f = YAML.load_file(file)
rescue Exception
puts "failed to read #{file}: #{$!}"
end
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
@gabrieljoelc
gabrieljoelc / PowerShellCheatSheet
Last active December 16, 2015 07:08
PowerShell cheat sheet
# load PATH environment variable
$env:path += ";C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE"
@gabrieljoelc
gabrieljoelc / ClassWithStaticMethodFactory.cs
Last active December 17, 2015 11:19
Here's a static method design that allows method mocking/verification via Daniel Cazzulino here http://blogs.clariusconsulting.net/kzu/making-extension-methods-amenable-to-mocking/.
public static class MessagingExtensions
{
public static IMessaging Messaging(this SomeType target)
{
return MessagingFactory(target);
}
static MessagingExtensions()
{
MessagingFactory = st => new Messaging(st);
@gabrieljoelc
gabrieljoelc / jsBaseMethodExample.js
Created May 21, 2013 17:40
Example of calling a "base" method in JavaScript using Backbone.js.
Backbone.Collection.extend({
add: function(models, options) {
models.doSomethingSpecific();
return Backbone.Collection.prototype.add.call(this, models, options);
}
})
@gabrieljoelc
gabrieljoelc / IsGenericTypeAssignableFromExtension.cs
Created June 4, 2013 13:50
superType#IsAssignableFrom(subType) won't return true when the type on the left side is a generic and the type parameter on the right is its subtype. This extension method does it. I ripped it off of this answer from SO: http://stackoverflow.com/a/1075059/34315.
public static class TypeExtensions
{
public static bool IsGenericTypeAssignableFrom(this Type genericType, Type givenType)
{
var interfaceTypes = givenType.GetInterfaces();
if (interfaceTypes.Any(it => it.IsGenericType && it.GetGenericTypeDefinition() == genericType))
{
return true;
}
@gabrieljoelc
gabrieljoelc / gist:5713807
Last active December 18, 2015 02:49
Generic retry utility ripped off from SO answer http://stackoverflow.com/a/1563234/34315.
public static class RetryUtility
{
public static void RetryAction( Action action, int numRetries, int retryTimeout )
{
if( action == null )
throw new ArgumentNullException("action"); // slightly safer...
do
{
try { action(); return; }
@gabrieljoelc
gabrieljoelc / ParseApiInvoke-RestMethod.ps1
Last active December 20, 2015 15:49
Parse API call with Powershell Invoke-RestMethod and equivalent curl command.
Invoke-RestMethod -Uri https://api.parse.com/restmethodspec `
#-Body (@{} | ConvertTo-Json) ` #empty object
-Body (@{"name"="value"} | ConvertTo-Json) `
-ContentType "application/json" `
-Headers @{ `
"X-Parse-Application-Id"="senstitive"; `
"X-Parse-REST-API-Key"="senstitive" } `
-Method Post
@gabrieljoelc
gabrieljoelc / GuidGenerator.js
Created August 8, 2013 00:13
RFC4122 Version 4 compliant JavaScript GUID generator ripped off from: http://stackoverflow.com/a/2117523/34315.
function guidGen() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}
@gabrieljoelc
gabrieljoelc / ExtractArrayFields.cs
Last active December 20, 2015 18:59
Custom `Microsoft.VisualStudio.TestTools.WebTesting.ExtractionRule` that groups all of the form field `Microsoft.VisualStudio.TestTools.WebTesting.HtmlTag`s for ASP.NET MVC-style view model array form field names.
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.WebTesting;
namespace GabesWebTesting.Extraction
{
public class ExtractArrayFields : ExtractionRule
{
public const string ArrayRootElementPlaceholderName = "root";