Skip to content

Instantly share code, notes, and snippets.

View westonal's full-sized avatar

Alan Evans westonal

View GitHub Profile
@westonal
westonal / HackerRankLargestSlice.cs
Last active May 3, 2016 09:09
Largest Slice solution
namespace HackerRankChallenge
{
[TestFixture]
public class CalculateLargestSliceTests
{
[Test]
public void empty()
{
Assert.AreEqual(0, CalculateLargestSlice(new int[0]));
}
@westonal
westonal / ViewModelBase.cs
Created May 27, 2016 13:04
WPF ViewModelBase with async support
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
namespace WPF
{
public abstract class ViewModelBase : INotifyPropertyChanged
{
@westonal
westonal / ChildContainersDemo.cs
Created July 6, 2016 09:02
Demo of Child containers and hierarchical lifetimes
using System;
using Microsoft.Practices.Unity;
using NUnit.Framework;
namespace UnityDemo
{
[TestFixture]
public sealed class ChildContainers
{
[Test]
@westonal
westonal / newsystem.bat
Created July 14, 2016 13:59
Choco install script
::Ensure choco up-to date
choco upgrade chocolatey -y
::Graphics
choco install paint.net -y
::System maintainance
choco install windirstat -y
public static int average(int argb1, int argb2){
return (((argb1 & 0xFF) + (argb2 & 0xFF)) >> 1) | //b
(((argb1 >> 8 & 0xFF) + (argb2 >> 8 & 0xFF)) >> 1) << 8 | //g
(((argb1 >> 16 & 0xFF) + (argb2 >> 16 & 0xFF)) >> 1) << 16 | //r
(((argb1 >> 24 & 0xFF) + (argb2 >> 24 & 0xFF)) >> 1) << 24; //a
}
overflow issues:
public static int average2(int argb1, int argb2){
@westonal
westonal / build.gradle
Created October 4, 2016 19:51
Modifications to gradle file for publish to bintray
plugins {
id "com.jfrog.bintray" version "1.7"
}
apply plugin: 'com.android.library'
apply plugin: 'maven'
apply plugin: 'maven-publish'
publishing {
@westonal
westonal / CustomClassInitialization.cs
Created December 14, 2016 14:57
Use the feature of calling .Add during initialization
using System;
using System.Collections;
public class Test
{
public static void Main()
{
new MyClass{1, "a", {2, "b"}}; //calls Add(1), Add("a"), Add(2, "a")
}
}
@westonal
westonal / tis-100-arduino-sketch.c
Last active January 21, 2017 23:34
TIS-100 arduino
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
setProgram();
compile();
lcd.setCursor(0,1);
@westonal
westonal / AutoReverseInterpolator.java
Created February 26, 2017 01:06
Auto reverse interpolator
import android.animation.TimeInterpolator;
import android.view.animation.LinearInterpolator;
/**
* Maps time into another interpolator so that the animation plays, and then reverses.
* i.e. time maps like so:
* [0..0.5, 0.5..1] maps to [0..1, 1..0]
*/
public final class AutoReverseInterpolator implements TimeInterpolator {
@westonal
westonal / Filter.java
Created February 28, 2017 15:37
Potential non-stream filter
package com.vmn.android.me.mappings;
import com.google.common.base.Objects;
import java.util.ArrayList;
import java.util.Iterator;
public final class Filter<T> implements Iterable<T> {
private final Iterable<T> original;