Skip to content

Instantly share code, notes, and snippets.

View mgroves's full-sized avatar

Matthew D. Groves mgroves

View GitHub Profile
private bool customPref_PreferenceClick(Preference preference)
{
IEnumerable<char>[] stockItemsDisplay = _stockItemsConfig.OrderBy(i => i.StockDataItem).Select(i => i.StockDataItem.GetStringValue()).ToArray();
bool[] allitemschecked = _stockItemsConfig.OrderBy(i => i.StockDataItem).Select(i => i.IsChecked).ToArray();
var dialog = new AlertDialog.Builder(this);
dialog.SetMultiChoiceItems(stockItemsDisplay, allitemschecked, clickCallback);
dialog.SetTitle("Select columns");
dialog.SetPositiveButton("Save", saveCallback);
dialog.Create().Show();
using System;
using System.Collections.Generic;
using System.Linq;
using Android.App;
using Android.Content;
using Android.Widget;
using Android.OS;
namespace MonoDroidMultiChoice
{
@mgroves
mgroves / gist:857356
Created March 6, 2011 15:28
MVP pattern in MonoDroid
public interface IMainView
{
void RefreshList(IList<string> portfolioNames);
void StartAddPortfolioActivity();
void StartViewPortfolioActivity(long portfolioId);
void StartEditPortfolioActivity(int itemId);
void StartConfigActivity();
void ExitApplication();
}
@mgroves
mgroves / gist:872672
Created March 16, 2011 15:34
threading and unit testing
using System.Threading;
using PostSharp.Aspects;
namespace MonoStockPortfolio.Framework
{
public class OnWorkerThreadAttribute : MethodInterceptionAspect
{
public static IThreadingService ThreadingService;
public override void OnInvoke(MethodInterceptionArgs args)
@mgroves
mgroves / gist:872679
Created March 16, 2011 15:36
do not thread
internal class DoNotThreadService : IThreadingService
{
public void QueueUserWorkItem(WaitCallback func)
{
func.Invoke(null);
}
}
[TestFixture]
public class Class1
{
[Test]
public void test()
{
var result = Harbl(new { foo = "bar"});
Assert.That(result, Is.EqualTo("bar"));
}
[HttpPost]
public ActionResult Edit(int id, MyNameEntity name)
{
if(!ModelState.IsValid)
{
return View(name);
}
return RedirectToAction("Index");
}
@mgroves
mgroves / gist:1061971
Created July 3, 2011 05:15
24 line PHP unit testing framework
<?php
function assertEquals($var1, $var2)
{
if($var1 != $var2) {
throw new Exception("Expected " . $var1 . " but was " . $var2);
}
}
$funcs = get_defined_functions();
@mgroves
mgroves / gist:1062658
Created July 3, 2011 22:02
PHP unit testing framework
<?php
class TestRunner
{
public function Run()
{
$classes = get_declared_classes();
foreach($classes as $class)
{
if(substr($class,0,4) == "Test" && ($class != "TestRunner")) {
$this->RunTests($class);
@mgroves
mgroves / gist:1067692
Created July 6, 2011 16:37
now with html and color!
<?php
class Formatting
{
public static function BeginLine($color = null)
{
if(defined('STDIN') ) {
return "";
}
if($color == null) {
return "<span>";