Skip to content

Instantly share code, notes, and snippets.

View hjerpbakk's full-sized avatar
🌝
Full-stack TypeScript 

Runar Ovesen Hjerpbakk hjerpbakk

🌝
Full-stack TypeScript 
View GitHub Profile
@hjerpbakk
hjerpbakk / UITableVIew.html
Created July 22, 2014 19:50
UITableView from iOS re-created using CSS and HTML
<!DOCTYPE html>
<html>
<head>
<meta content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0" name="viewport" />
<style type="text/css">
* {
box-sizing:border-box;
@hjerpbakk
hjerpbakk / BindablePicker.cs
Created July 17, 2014 19:26
A Picker-control for Xamarin.Forms which enables data binding through an ItemsSource and the SelectedItem.
using System;
using Xamarin.Forms;
using System.Collections;
namespace YourNamespace.Views.Controls {
public class BindablePicker : Picker
{
public BindablePicker()
{
this.SelectedIndexChanged += OnSelectedIndexChanged;
@hjerpbakk
hjerpbakk / TimePicker24HRenderer.cs
Last active June 15, 2017 16:51
Custom renderer for Xamarin.Forms TimePicker on iOS. This will make the TimePicker always show time using 24H format (aka no AM or PM).
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using PersonalTrainer.iOS.View.Controls;
[assembly: ExportRenderer (typeof (TimePicker), typeof (TimePicker24HRenderer))]
namespace YourNamespace.iOS.View.Controls {
public class TimePicker24HRenderer : TimePickerRenderer {
@hjerpbakk
hjerpbakk / LocalizationTests.cs
Created May 29, 2014 19:12
Example using LocalizationTester to verify iOS localizations using Xamarin.iOS
[Test]
public void VerifyLocalizations() {
const string Path = "/Users/hjerpbakk/Code/BookScanner/BookScanner/BookScanner.iOS";
var localizationTester = new LocalizationTester(Path);
localizationTester.VerifyLocalizations("no", "en");
}
public class ViewModelWithAsyncMethodCaller {
private readonly AsyncMethodCaller asyncMethodCaller;
public ViewModelWithAsyncMethodCaller(AsyncMethodCaller asyncMethodCaller) {
this.asyncMethodCaller = asyncMethodCaller ?? new AsyncMethodCaller();
}
public string Message { get; set; }
public string Result { get; set; }
public class ViewModelWithBackgroundWorker {
private readonly BackgroundWorker worker;
public ViewModelWithBackgroundWorker() {
worker = new BackgroundWorker();
worker.DoWork += DoSomething;
worker.RunWorkerCompleted += WorkCompleted;
}
public string Message { get; set; }
@hjerpbakk
hjerpbakk / GoodTest.cs
Last active December 23, 2015 20:29
A well designed unit test example where the current day is hidden behind an abstraction. From: http://hjerpbakk.com/blog/2013/9/24/the-little-test-that-could-not.html
[TestFixture]
public class GoodUnitTestExample {
[Test]
public void AgeMustReturnCorrectAge() {
IClock clock = new StubClock(new DateTime(2013, 9, 2));
var aPerson = new PersonGood(clock) { TimeOfBirth = new DateTime(1983, 9, 8) };
Assert.AreEqual(29, aPerson.Age);
}
@hjerpbakk
hjerpbakk / BadTest.cs
Last active December 23, 2015 20:29
A unit test that will periodically fail as the current day changes. From: http://hjerpbakk.com/blog/2013/9/24/the-little-test-that-could-not.html
[TestFixture]
public class BadUnitTestExample {
[Test]
public void AgeMustReturnCorrectAge_Bad() {
var aPerson = new PersonBad { TimeOfBirth = new DateTime(1983, 9, 25) };
Assert.AreEqual(29, aPerson.Age);
}
}
title AsyncMethodCaller
participant "View Model" as vm
participant "Service" as service
vm -> service: CallMethodAndContinue
activate vm
activate service
alt Work completed
@hjerpbakk
hjerpbakk / GoodAndBadMocks.cs
Last active December 18, 2015 19:29
Use mocks sparingly and keep them simple! Never make a mock more complex. From http://hjerpbakk.com/blog/2013/6/21/ndc-2013-day-3.html
[TestClass]
public class MockExample
{
/// <summary>
/// An interface for an imaginary stock service.
/// </summary>
public interface IStockService
{
double QuoteForTicker(string ticker);
}