Skip to content

Instantly share code, notes, and snippets.

View craigrbruce's full-sized avatar
🏠
Working from home

Craig Bruce craigrbruce

🏠
Working from home
View GitHub Profile
@craigrbruce
craigrbruce / isObjectDirty.js
Created July 7, 2016 05:38
Object property dirty checker with dependency on lodash
/**
* Checks all fields of an object literal for values.
* @param {Object} object - A POJO.
* @param {Array<String>} omitProperies - An array of properties that you wish to omit from the checker e.g. "id".
* @returns {Boolean}
*/
function isObjectDirty(object, omitProperties) {
if(omitProperties) {
object = _.omit(object, omitProperties);
}
<input
value={this.props.complexForm.firstName}
onChange={this.onPropertyChanged}
/>
@craigrbruce
craigrbruce / module_3.fs
Created October 26, 2015 09:56
Module 3 Assignment
let calculateRatio x = x * goldenRatio
let getValue (index: int32) =
Console.WriteLine("Enter value " + index.ToString());
Console.ReadLine()
let getValues count =
let result =
[ for i in 1 .. count -> float(getValue(i))]
result
open System
let getUserInput message predicate =
let mutable loop = true
let mutable userInput = "";
while loop do
printf "%s" message;
userInput <- Console.ReadLine();
let isValid = predicate(userInput)
if isValid = true then loop <- false
@craigrbruce
craigrbruce / packages.cson
Created September 6, 2015 22:51
atom package list
packages: [
"atom-beautify"
"emmet"
"git-blame"
"git-plus"
"highlight-selected"
"language-babel"
"linter"
"linter-eslint"
"monokai-seti"
@craigrbruce
craigrbruce / Query a repo
Last active August 29, 2015 14:15
Using LibGit2Sharp without the pain
#r "/Users/craig/Projects/gitsharp/LibGit2Sharp.0.21.0.176/lib/net40/LibGit2Sharp.dll"
open LibGit2Sharp
//plonk the native dll here
System.Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
let printer (c: Commit) =
sprintf "User %s" c.Author.Email |> ignore
let filter = new CommitFilter();
filter.Since <- "Tag1";
@Test
public void test() {
running(testServer(3333, fakeApplication(inMemoryDatabase())), org.openqa.selenium.phantomjs.PhantomJSDriver.class, new Callback<TestBrowser>() {
public void invoke(TestBrowser browser) {
browser.goTo("http://www.google.com");
//test presence of stuff.
browser.takeScreenShot("/tmp/screenshot.jpg");//could be stored in a doco db
}
});
}
@craigrbruce
craigrbruce / taskHelper.m
Created August 14, 2013 01:00
Helper class in obj-c to encapsulate bg tasks
@implementation taskHelper {
}
+ (void)runTaskInBackground:(void (^)())backgroundTask
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), backgroundTask);
}
+ (void)runTaskInForeground:(void (^)())foregroundTask
@craigrbruce
craigrbruce / ApiClient.cs
Last active April 26, 2022 23:06
An example REST API client for C#
/*
Call the api client like this:
var client = new ApiClient<SEnvelope>("https://baseurl.com/api/v1");
//you would overload and add an auth_token param here
client.GetDtoAsync("envelopes", "object_id", (response) => //callback
{
this.SEnvelope = response.Data;//should be an envelope from the server
});
@craigrbruce
craigrbruce / gist:5384753
Created April 14, 2013 23:52
Create Nested Namespace from String in JavaScript
function createNamespace(fromString){
var split = fromString.split('.');
var parent = window;
var current = '';
var length = split.length;
for(var i = 0; i < length; i++){
current = split[i];
parent[current] = parent[current] || {};
parent = parent[current];