Skip to content

Instantly share code, notes, and snippets.

View mxswd's full-sized avatar

Maxwell mxswd

View GitHub Profile
@mxswd
mxswd / ViewController.swift
Created March 10, 2022 07:54
Persisting stuff. In the MyModel.xcdatamodel make an Entity called MyThingEntity, an attribute index with type int32, an attribute data with type Data. Give the entity a constraint on the index.
import UIKit
import CoreData
public struct MyThing: Codable {
var state: Bool? = nil
var value: String? = nil
}
class ViewController: UIViewController, UITextViewDelegate {
@mxswd
mxswd / CloudKit.cs
Created March 6, 2022 02:27
CloudKit Server-to-server API in C#
using System;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace YoApp
{
-- executable awsenv
-- main-is: awsenv.c
-- hs-source-dirs: awsenv
-- default-language: Haskell2010
-- x-exe-type: bash
import Data.Maybe
import Distribution.Simple
import Distribution.Simple.Setup
@mxswd
mxswd / TypeNats.swift
Last active December 12, 2016 19:24
Thanks @robrix and CodaFi_ for the discussion :D
// this is a playground
protocol Nat {
class func construct() -> Self
class func value() -> Int
}
struct Z : Nat {
static func construct() -> Z {
return Z()
}
class F<A> {
}
protocol Functor {
typealias A
typealias B
typealias FA = F<A>
typealias FB = F<B>
func fmap(a: FA, fn: (A -> B)) -> FB
}
sealed trait Shape[P]
case class Void[P]() extends Shape[P]
case class Unit[P]() extends Shape[P]
case class Value[P, A](a: A) extends Shape[P]
case class Meta[P, T <: Tag](shape: Shape[P]) extends Shape[P]
sealed trait Sum[P] extends Shape[P] {
val shape: Shape[P]
}
case class Left[P](shape: Shape[P]) extends Sum[P]
:set -XTemplateHaskell
:set -XOverloadedStrings
:set -XQuasiQuotes
:set -XMultiParamTypeClasses
:set -XFunctionalDependencies
:set -XFlexibleInstances
:set -XUndecidableInstances
:set -XGeneralizedNewtypeDeriving
:set -XFlexibleContexts
:set -XScopedTypeVariables
import TagField
import Data.Text (Text)
import Data.Aeson
data Banana = Banana
{ shape :: Field "banana-shape" Text
, size :: Field "banana size" (Maybe Int)
, name :: Field "banana's name" Text
} deriving Show
{-# LANGUAGE OverloadedStrings, TemplateHaskell, QuasiQuotes #-}
import Data.Aeson
import Data.Monoid
import Data.Text (Text, unpack)
import Control.Monad.Writer
import qualified Data.Map as M
import qualified Data.Vector as V
import qualified Data.HashMap.Strict as H
import Language.Haskell.TH
data EL = O (H.HashMap Text EL)
| V EL
| S | N | B | E
| T | U
deriving Show
instance Monoid EL where
mempty = U
U `mappend` U = U