Skip to content

Instantly share code, notes, and snippets.

import Foundation
struct SampleTurtleProgram {
private var instructions: [Instruction] = {
let getTurtleReady = [
Instruction.Move(0.5),
.Rotate(-M_PI_2),
.Move(0.5),
@jmcd
jmcd / W95Buttons.swift
Created June 5, 2016 19:29
Windows 95 style button on iOS
import UIKit
struct BezelPart {
let color: UIColor
let inset: CGFloat
let kind: BezelPartKind
func draw(c: CGContext, size: CGSize) {
kind.mutateCTM(c, size: size)
@jmcd
jmcd / OmniLiker.cs
Created June 17, 2016 13:30
A robot to like my own posts on Yammer. IDK.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using Nancy;
using Nancy.Helpers;
using Nancy.Hosting.Self;
using RestSharp;
@jmcd
jmcd / ConvertSpecifiedDateTime.cs
Last active June 23, 2016 10:55
Mapping value-object + is-specified flag to nullable via custom type converter
using System;
using AutoMapper;
namespace Some.Namespace
{
public class ConvertSpecifiedDateTime : ITypeConverter<DateTime, DateTime?>
{
public DateTime? Convert(ResolutionContext context)
{
var sourceMember = context.PropertyMap.SourceMember;
@jmcd
jmcd / Program.cs
Last active June 24, 2016 07:49
Take a WSD file and make test data for pasting into SoapUI response templates
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication7
{
internal class Program
@model DateFields
@Html.TextBoxFor(x => x.Day, new {placeholder = "DD", maxlength = 2, @class = "form-control form-control--dob"})
@Html.TextBoxFor(x => x.Month, new {placeholder = "MM", maxlength = 2, @class = "form-control form-control--dob"})
@Html.TextBoxFor(x => x.Year, new {placeholder = "YYYY", maxlength = 4, @class = "form-control form-control--dob"})
@jmcd
jmcd / Foo.swift
Created October 14, 2016 14:06
Swift "any" like in Linq
extension Array {
func any(_ predicate: (Element) throws -> Bool) rethrows -> Bool {
for e in self {
if try predicate(e) {
return true
}
}
return false
@jmcd
jmcd / 99bottles.swift
Created October 31, 2016 18:26
Program to print the lyrics to 99 Bottles of Beer
enum Action {
case tookOne
case wentToStore
}
struct Verse {
let countBeforeAction: Int
let action: Action
let countAfterAction: Int
}
@jmcd
jmcd / Availability.cs
Created November 15, 2016 13:59
Availability bitmaps
using System;
using System.Linq;
using NUnit.Framework;
namespace AvailSpike
{
[TestFixture]
public class UseCase
{
[Test]
@jmcd
jmcd / KeyExchange.swift
Last active April 8, 2022 17:37
Diffie–Hellman key exchange simple implementation
import Foundation
protocol Cipher {
func encrypt(message: String, secret: Int) -> String
func decrypt(message: String, secret: Int) -> String
}
struct XOR: Cipher {
private func impl(message: String, secret: Int) -> String? {