Skip to content

Instantly share code, notes, and snippets.

View jpreece6's full-sized avatar

Josh Preece jpreece6

  • UK
View GitHub Profile
@jpreece6
jpreece6 / shake.js
Last active August 29, 2015 13:58 — forked from leecrossley/shake.js
Shake.js edited for better error handling. Using a shake.error() function which can be overridden with an external function.
var shake = (function () {
var shake = {},
watchId = null,
options = { frequency: 300 },
previousAcceleration = { x: null, y: null, z: null },
shakeCallBack = null;
// Start watching the accelerometer for a shake gesture
shake.startWatch = function (onShake) {
if (onShake) {
@jpreece6
jpreece6 / ExtensionMethods.cs
Created January 4, 2017 20:15
Best method for easy invoke operations
namespace ExtensionMethods
{
public static class ExtensionMethods
{
public static void InvokeIfRequired<T>(this T obj, Action<T> action) where T : Control
{
if (obj.InvokeRequired)
{
obj.Invoke(new Action(() => action(obj)));
}
@jpreece6
jpreece6 / ExtensionMethods.cs
Created January 10, 2017 08:59
List extension to split lists into chunks (good for batch processing on threads)
public static class ExtensionMethods
{
public static List<List<T>> Split<T>(this IEnumerable<T> collection, int size)
{
var chunks = new List<List<T>>();
var count = 0;
var temp = new List<T>();
foreach (var element in collection)
{
@jpreece6
jpreece6 / ClipboardNotification.cs
Last active April 12, 2017 18:07
Notification class designed to an raise event when the clipboard contents change.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Notifications
{
@jpreece6
jpreece6 / ValidateObjectAttribute.cs
Created January 26, 2018 09:05
Object validation attribute that tells the DataAnnotations validator that we want to validate a child object properties
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Utilities
{
// Credit http://www.technofattie.com/2011/10/05/recursive-validation-using-dataannotations.html
// Usage
//