Skip to content

Instantly share code, notes, and snippets.

View dvdsgl's full-sized avatar
🦋
Gliding

David Siegel dvdsgl

🦋
Gliding
View GitHub Profile
@dvdsgl
dvdsgl / schema.json
Created March 30, 2018 20:27
Figma Platform schema
{
"$ref": "#/definitions/FileResponse",
"$schema": "http://json-schema.org/draft-06/schema#",
"definitions": {
"BlendMode": {
"enum": [
"COLOR",
"COLOR_BURN",
"COLOR_DODGE",
"DARKEN",
@dvdsgl
dvdsgl / blocks.json
Last active March 6, 2018 14:54
Examples of maps vs classes classified by quicktype Markov chains
{
"0000000000000000000e222e4e7afc29c49f6398783a94c846dee2e13c6408f5": {
"size": 969709,
"height": 510599,
"difficulty": 3007383866429.732,
"previous": "000000000000000000552a7783efd39eaa1c5ff6789e21a0bbe7547bc454fced"
},
"000000000000000000552a7783efd39eaa1c5ff6789e21a0bbe7547bc454fced": {
"size": 991394,
"height": 510598,
@dvdsgl
dvdsgl / term-schema.json
Last active February 28, 2018 04:34
A languge-independent logic representation (see https://stackoverflow.com/a/49021991/372047)
{
"id": "http://json-schema.org/geo",
"$schema": "http://json-schema.org/draft-06/schema#",
"description": "A languge-independent logic representation",
"$ref": "#/definitions/Term",
"definitions": {
"Term": {
"type": "object",
"additionalProperties": false,
"description": "A logical value",
@dvdsgl
dvdsgl / Imgur API.postman_collection.json
Created February 28, 2018 00:49
Imgur API Postman Collection
{
"info": {
"name": "Imgur API",
"_postman_id": "00eac12b-6725-3a66-b1b2-b242834fae2d",
"description": "![image](https://i.imgur.com/n744BL9.png)\n\n## API Status\nStatus for the API can be found at [status.imgur.com](http://status.imgur.com)!\n\n## Getting Started\nImgur's API exposes the entire Imgur infrastructure via a standardized programmatic interface. Using Imgur's API, you can do just about anything you can do on imgur.com, while using your programming language of choice. The Imgur API is a RESTful API based on HTTP requests and JSON responses.\n\nThis version of the API, version 3, uses OAuth 2.0. This means that all requests will need to be encrypted and sent via HTTPS. It also means that you need to register your application, even if you aren't allowing users to login.\n\nThe easiest way to start using the Imgur API is by clicking the **Run in Postman** button above. [Postman](https://www.getpostman.com/) is a free tool which helps developers run and debug API requests, and is the source of
{
"description": "the description for this gist",
"files": {
"file1.84D9D31B-8AD2-492F-A44D-6407128DAD79.txt": {
"content": "updated file contents"
},
"file2.84D9D31B-8AD2-492F-A44D-6407128DAD79.txt": {
"content": "updated file contents"
}
}
@dvdsgl
dvdsgl / QTPokedex.m
Created January 17, 2018 06:56
quicktype Objective-C enum support prototype sample
// To parse this JSON:
//
// NSError *error;
// QTPokedex *pokedex = [QTPokedex fromJSON:json encoding:NSUTF8Encoding error:&error]
#import <Foundation/Foundation.h>
// MARK: Types
typedef NSNumber NSBoolean;
{
"int or string": [1, "1"],
"nested array": [[false, true]],
"best friend": { "name": "Sue" },
"friends": [{ "name": "Sal" }, { "name": "Sue" }],
"a map": {
"zero": 0, "one": 1, "two": 2, "three": 3,
"four": 4, "five": 5, "six": 6, "seven": 7,
"eight": 8, "nine": 9, "ten": 10, "eleven": 11,
"twelve": 12, "thirteen": 13, "fourteen": 14,
@dvdsgl
dvdsgl / Parsers.purs
Created October 15, 2015 05:49
Unit tests for a stack trace parser
module Test.Parsers (tests) where
import Prelude
import Data.Default
import Test.Prelude
import Test.Data
import Test.Unit (runTest, test, assert)
type ShootOutAnimator(referenceView: UIView) =
let speed = 1300.0f
let animator = UIDynamicAnimator(referenceView)
...
member this.ShootOut(view: UIView, direction: Direction) =
let x, y = direction.UnitVector
let shoot = UIDynamicItemBehavior(view, AngularResistance=2.0f)
shoot.AddLinearVelocityForItem(PointF(x * speed, y * speed), view)
shoot.AddAngularVelocityForItem(x * 3.0f, view)
shoot.Action <- fun () ->
@dvdsgl
dvdsgl / Monads for a C# dev.md
Last active January 8, 2024 06:11
Monads explained (sort of) to a C# developer

A monad is a fancy word for a generic type of the form MyMonad<T> (a generic type of arity 1).

A monad is special because it adds 'special powers' to the T that it wraps. These 'special powers' won't sound very special to an imperative programmer, so you have to squint to see them but bear with me.

  • IEnumerable<T> is a monad that gives values of type T the special power of nondeterminism, or the ability to 'be' multiple values at once.
  • Nullable<T> is a monad that gives values of type T the special power of nullability, or the ability to be absent.
  • Task<T> is a monad that gives values of type T the special power of asynchronicity, or the ability to be used before they are computed.

The trick with monads comes when you want to play with the T values, because they are inside another type. C# introduced language changes to make dealing with values inside these monads easier: