Skip to content

Instantly share code, notes, and snippets.

View ryanashcraft's full-sized avatar

Ryan Ashcraft ryanashcraft

View GitHub Profile
@ryanashcraft
ryanashcraft / DeepDiff.js
Created January 7, 2016 19:37
DeepDiff.js
/*!
* deep-diff.
* Licensed under the MIT License.
*/
;(function(root, factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define([], factory);
} else if (typeof exports === 'object') {
@ryanashcraft
ryanashcraft / HN
Last active September 13, 2016 20:33
https://news.ycombinator.com/
## API
### Top Stories
https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty
### Story
@ryanashcraft
ryanashcraft / Makefile
Last active August 4, 2017 16:07
Ghost on Docker Makefile
DOCKER_IMAGE ?= ryanashcraft/ghost:1.0
DOCKER_CONTAINER ?= ghost
dev:
docker build -f Dockerfile.dev -t $(DOCKER_IMAGE) .
docker rm $(DOCKER_CONTAINER) && docker run \
-p 2368:2368 \
-v ${PWD}/content/data:/var/www/ghost/content/data \
-v ${PWD}/content/images:/var/www/ghost/content/images \
--name $(DOCKER_CONTAINER) \
@ryanashcraft
ryanashcraft / NowPlayingView.jsx
Last active July 5, 2018 18:19
AmpliTunes without react-amplitude
import React, { Fragment } from "react";
class NowPlayingView extends React.Component {
componentDidMount() {
this.props.logViewNowPlayingScreen();
}
componentDidUpdate = prevProps => {
if (prevProps.songId !== this.props.songId) {
this.props.logChangeSong(songId);
@ryanashcraft
ryanashcraft / NowPlayingView.jsx
Last active July 5, 2018 19:59
AmpliTunes with react-amplitude
import React, { Fragment } from "react";
import { Amplitude, LogOnMount } from "@amplitude/react-amplitude";
const NowPlayingView = props => {
return (
<Amplitude
// All events logged in this subtree will include these event properties
eventProperties={inheritedProps => ({
...inheritedProps,
"song id": props.songId,
struct Memoized<A: Equatable, R> {
typealias Value = (_ params: A) -> R
var callback: Value
@XState private var prevParam: A? = nil
@XState private var prevValue: R? = nil
init(_ callback: @escaping Value) {
self.callback = callback
}
@ryanashcraft
ryanashcraft / Using-NavigationDestinationLink.swift
Last active July 11, 2019 04:49
Here's a working implementation of controlled push/pop NavigationView actions in SwiftUI with NavigationDestinationLink.
@ryanashcraft
ryanashcraft / RemoteInspector.swift
Created January 19, 2020 22:35
RemoteInspector.swift
import Foundation
public class RemoteInspector {
private struct UpdateMessage<T: Encodable>: Encodable {
let type = "update"
var id: String
var data: T
}
private struct LogMessage: Encodable {
import SwiftUI
struct WidthPreferenceKey: PreferenceKey {
typealias Value = CGFloat?
static var defaultValue: CGFloat?
static func reduce(value: inout CGFloat?, nextValue: () -> CGFloat?) {
if let nextValue = nextValue(), value != nextValue {
value = nextValue
import SwiftUI
// Models
enum Lyric {
case line(String)
case pause(TimeInterval)
}
class ScrollToModel: ObservableObject {