Skip to content

Instantly share code, notes, and snippets.

View philipyoungg's full-sized avatar

Philip Young philipyoungg

View GitHub Profile
//
// ContentView.swift
// ExampleDailyMotion
//
// Created by Philip Young on 2023-05-11.
//
import SwiftUI
import DailymotionPlayerSDK
@philipyoungg
philipyoungg / wontcompilexcode13x3.swift
Created March 24, 2022 09:34
Won't compile on XCode 13.3
//
// ContentView.swift
// Shared
//
// Created by Philip Young on 2022-03-24.
//
import SwiftUI
struct CustomTextField: View, Equatable {
@philipyoungg
philipyoungg / test.swift
Last active April 16, 2021 12:21
Example crash catalina
//
// ContentView.swift
// test
//
// Created by Philip Young on 16/04/21.
//
import SwiftUI
struct Item: Identifiable {
@philipyoungg
philipyoungg / websocket_redis_pubsub.ts
Last active January 2, 2021 12:32
Only support one room—but it's scalable horizontally
import * as redis from "redis";
import * as Websocket from "ws";
import { v4 } from "uuid";
import * as http from "http";
function noop() {}
enum WebsocketSendType {
BROADCAST_EMIT = "BROADCAST_EMIT",
}
@philipyoungg
philipyoungg / json_enum_parser.swift
Last active December 20, 2020 23:10
Parse JSON into safe struct
enum ObjectId {
case Session(SessionType)
case SessionStatus(SessionStatusType)
}
enum SessionType {
case SessionAdd(SessionAddPayload)
case SessionEdit(SessionEditPayload)
}
@philipyoungg
philipyoungg / pg.swift
Created December 16, 2020 21:04
Decodable enumeration
import UIKit
protocol VercelPayload {
var name: String {get}
var id: String {get}
}
struct GitBucket: VercelPayload, Codable {
var name: String
var id: String
@philipyoungg
philipyoungg / useFetch.ts
Last active July 19, 2022 22:00
Typescript useFetch
// mocks
const mockUser = {}
const mockGoals = []
// endpoint
enum ApiEndpoint {
FetchAllGoals = '/goals',
CurrentUser = '/user',
@philipyoungg
philipyoungg / machine.js
Created December 15, 2019 17:11
Generated by XState Viz: https://xstate.js.org/viz
// guards
const gteNewDragIndex = (c, e) => c.snapshot.index >= e.newDragIndex;
const gtNewDragIndex = (c, e) => c.snapshot.index > e.newDragIndex;
const lteNewDragIndex = (c, e) => c.snapshot.index <= e.newDragIndex;
const ltNewDragIndex = (c, e) => c.snapshot.index < e.newDragIndex;
const sameDropId = (c, e) => c.snapshot.dropId === e.destinationDropId;
const mismatchType = (c, e) => e.initialSnapshot.dropType !== c.snapshot.dropType;
@philipyoungg
philipyoungg / machine.js
Last active December 14, 2019 11:28
Generated by XState Viz: https://xstate.js.org/viz
// guards
const gteNewDragIndex = (c, e) => c.snapshot.index >= e.newDragIndex;
const gtNewDragIndex = (c, e) => c.snapshot.index > e.newDragIndex;
const lteNewDragIndex = (c, e) => c.snapshot.index <= e.newDragIndex;
const ltNewDragIndex = (c, e) => c.snapshot.index < e.newDragIndex;
const sameDropId = (c, e) => e.snapshot.dropId === e.destinationDropId;
const mismatchType = (c, e) =>
e.initialSnapshot.dropType !== e.snapshot.dropType;
@philipyoungg
philipyoungg / ramdaLift.js
Last active January 12, 2017 04:22
Understand how lift works on function level
As I have hard time understanding the same issue, I decided to take a peek from Ramda's source code. Will write a blogpost about `this`. Meanwhile—I made a commented gist how Ramda's `lift` work step by step.
from: https://gist.github.com/philipyoungg/a0ab1efff1a9a4e486802a8fb0145d9e
// Let's make an example function that takes an object and return itself.
// 1. Ramda's lift level
lift(zipObj)(keys, values)({a: 1}) // returns {a: 1}
// this is how lift works in the background
module.exports = _curry2(function liftN(arity, fn) {