Skip to content

Instantly share code, notes, and snippets.

@tvler
tvler / getLinkifiedString.tsx
Last active October 29, 2022 01:04
Turn a string into JSX with autolinks
type LinkifiedString = Array<string | JSX.Element> | string | null | undefined
/**
* Turn a string into JSX with autolinks
*/
export function getLinkifiedString(str: string | null | undefined): LinkifiedString {
try {
// Group by whitespace (wrapping regex in parens keeps matched results in the array)
const substrings = str?.split(/(\s+)/g)
import * as React from 'react'
import { SpringValue, easings, useSpring } from 'react-spring'
/**
* Hook that animates height when args.animationKey changes
*
* Ex:
* const animatedBlock = useAnimatedHeight({
* animationKey: key,
* })
@onlurking
onlurking / programming-as-theory-building.md
Last active June 5, 2024 04:46
Programming as Theory Building - Peter Naur

Programming as Theory Building

Peter Naur

Peter Naur's classic 1985 essay "Programming as Theory Building" argues that a program is not its source code. A program is a shared mental construct (he uses the word theory) that lives in the minds of the people who work on it. If you lose the people, you lose the program. The code is merely a written representation of the program, and it's lossy, so you can't reconstruct

@slava-vishnyakov
slava-vishnyakov / readme.md
Last active June 24, 2024 12:42
How to upload images with TipTap editor
  1. Create a file Image.js from the source below (it is almost a copy of Image.js from tiptap-extensions except that it has a constructor that accepts uploadFunc (function to be called with image being uploaded) and additional logic if(upload) { ... } else { ... previous base64 logic .. } in the new Plugin section.
import {Node, Plugin} from 'tiptap'
import {nodeInputRule} from 'tiptap-commands'

/**
 * Matches following attributes in Markdown-typed image: [, alt, src, title]
 *
@timothycosta
timothycosta / UIViewController+SwiftUI.swift
Last active April 28, 2023 07:00
Using UIViewController via the SwiftUI Environment
struct ViewControllerHolder {
weak var value: UIViewController?
init(_ value: UIViewController?) {
self.value = value
}
}
struct ViewControllerKey: EnvironmentKey {
static var defaultValue: ViewControllerHolder { return ViewControllerHolder(UIApplication.shared.windows.first?.rootViewController ) }
@chriseidhof
chriseidhof / swiftui.swift
Last active March 15, 2023 06:53
SwiftUI - iOS
import Combine
import CoreFoundation
import CoreGraphics
import CoreText
import Darwin
import Foundation
import SwiftUI
import UIKit
import os.log
import os
@daz
daz / google-earth-studio-ffmpeg.sh
Created January 23, 2019 06:35
Google Earth Studio stitch image sequence with FFmpeg
ffmpeg -framerate 30 -pattern_type glob -i '*.jpeg' -c:v libx264 -pix_fmt yuv420p output.mp4
// control the session data on your connection
experimental.datPeers.getSessionData()
experimental.datPeers.setSessionData(obj) // obj must be no larger than 255 bytes when JSONified
// manage connected peers
var peers = experimental.datPeers.list() // list all peers connected to the current page's dat
var peer = experimental.datPeers.get(peerId)
await experimental.datPeers.broadcast(data) // send a message to all peers
experimental.datPeers.addEventListener('connect') // new peer
experimental.datPeers.addEventListener('disconnect') // peer closed connection

Peer-to-peer computing: Beaker 0.8 and beyond

There's a somewhat old-fashioned term in computing (old-fashioned being a relative concept) and the term is "live."

Back when Xerox PARC was making the first real GUI and building the first Object-Oriented programming language (Smalltalk) they were building a live environment. And "live" meant that the code was right there, available to the user, ready to edit. If you go back and look at the demos of Smalltalk, you see people jumping into that code and modding the environment on-the-fly, and that's what live meant! It meant you could mess with the code.

There's a complementary term, just as old-fashioned but much more relevant, and that's "dead." That's what cloud computing is: dead computing. It's compiled, packaged, shipped, and completely unchangeable -- a total black box to the user.

Live is vibrant. Live is community-owned. Live means that mods and plugins are going to emerge out of the userbase. Some of the most popular and well-known computer games

@pfrazee
pfrazee / 0.8-new-apis.md
Last active May 4, 2018 17:56
Reference for new APIs in Beaker 0.8

New APIs in Beaker 0.8

This Gist is a quick writeup for devs using the beta or master build. We'll get a more complete writeup in the Beaker site docs on 0.8's final release. Feel free to open issues for discussion.

DatArchive

We've done some work on the DatArchive API to make it easier to use. Prior to 0.8, Dats had a "staging area" folder which you had to commit() to publish. In 0.8, Beaker will automatically sync that folder. As a result, the staging-area methods (diff() commit() and revert()) were deprecated. There are also some new methods, and a few changes to how events work.

Here's a full reference: