Skip to content

Instantly share code, notes, and snippets.

@realvjy
realvjy / ChoasLinesShader.metal
Last active July 18, 2026 20:41
Choas Lines - Metal Shader
// Lines
float hash( float n ) {
return fract(sin(n)*753.5453123);
}
// Slight modification of iq's noise function.
float noise(vector_float2 x )
{
vector_float2 p = floor(x);
vector_float2 f = fract(x);
@JohnSundell
JohnSundell / ContentViewWithCollapsableHeader.swift
Last active January 2, 2025 18:40
A content view which renders a collapsable header that adapts to the current scroll position. Based on OffsetObservingScrollView from https://swiftbysundell.com/articles/observing-swiftui-scrollview-content-offset.
import SwiftUI
/// View that observes its position within a given coordinate space,
/// and assigns that position to the specified Binding.
struct PositionObservingView<Content: View>: View {
var coordinateSpace: CoordinateSpace
@Binding var position: CGPoint
@ViewBuilder var content: () -> Content
var body: some View {
@joshdholtz
joshdholtz / ATinySampleApp.swift
Last active February 12, 2025 13:48
Super basic SwiftUI app (70 lines of code) with paywall using RevenueCat
import SwiftUI
import RevenueCat
struct Constants {
static let apiKey = "<your_api_key>" // Will look like: appl_bunchofotherstuffhere
static let entitlementName = "<your_entitlement_name>" // I use something like "pro"
}
@main
struct ATinySampleApp: App {
@egzonpllana
egzonpllana / IAPService.swift
Last active May 19, 2021 12:25
StoreKit iOS Swift InAppPurchase Process SKPayment
// Created on 7/9/2020.
//
// Developed by: Kilo Loco
// Improved by Egzon Pllana
import Foundation
import StoreKit
protocol IAPServiceDelegate: class {
@xtabbas
xtabbas / SnapCarousel.swift
Created May 10, 2020 18:13
A carousel that snap items in place build on top of SwiftUI
//
// SnapCarousel.swift
// prototype5
//
// Created by xtabbas on 5/7/20.
// Copyright © 2020 xtadevs. All rights reserved.
//
import SwiftUI
@theothernt
theothernt / apple-tv-screen-saver-feeds.txt
Last active September 28, 2026 15:40
A list of the feeds Apple uses for its video screensavers
tvOS 10: 1080p + H.264
http://a1.phobos.apple.com/us/r1000/000/Features/atv/AutumnResources/videos/entries.json
tvOS 11: 1080p/4K + SDR/HDR + HEVC
https://sylvan.apple.com/Aerials/2x/entries.json
https://t27q97zg19.execute-api.us-east-1.amazonaws.com/prod/aerialAltJSON/4kEntites.json
tvOS 12: 4K + SDR/HDR + HEVC, 1080p + H.264, localised descriptions
https://sylvan.apple.com/Aerials/resources.tar
@SaganRitual
SaganRitual / Box.swift
Created February 4, 2019 14:37
SpriteKit starter, draw grid, detect touches on sprites, cause neighboring sprites to react
import Foundation
import SpriteKit
class Box {
let sprite: SKShapeNode
let cellAddress: XYPair
var position: CGPoint {
get { return sprite.position }
set { sprite.position = newValue }
@otiai10
otiai10 / my-nice-editor.js
Created February 7, 2017 16:02
Editable Component with also rendering Emoji inside
import React from 'react';
import {Editor, EditorState, CompositeDecorator} from 'draft-js';
const getEmojiURL = (key) => {
// TODO: fulfill cases
// TODO: "ReactEmoji.emojify(key, {singleEmoji:true}).props.src" if you prefer.
switch(key) {
case ':smile:': return 'https://twemoji.maxcdn.com/svg/1f603.svg';
case ':shit:': return 'https://twemoji.maxcdn.com/svg/1f4a9.svg';
func imageByAddingBorder(width: CGFloat, color: UIColor) -> UIImage? {
UIGraphicsBeginImageContext(self.size)
let imageRect = CGRect(x: 0, y: 0, width: self.size.width, height: self.size.height)
self.draw(in: imageRect)
let context = UIGraphicsGetCurrentContext()
let borderRect = imageRect.insetBy(dx: width / 2, dy: width / 2)
context?.setStrokeColor(color.cgColor)