Skip to content

Instantly share code, notes, and snippets.

View michaelevensen's full-sized avatar

Michael Nino Evensen michaelevensen

View GitHub Profile
var mediaJSON = { "categories" : [ { "name" : "Movies",
"videos" : [
{ "description" : "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\n\nLicensed under the Creative Commons Attribution license\nhttp://www.bigbuckbunny.org",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" ],
"subtitle" : "By Blender Foundation",
"thumb" : "images/BigBuckBunny.jpg",
"title" : "Big Buck Bunny"
},
{ "description" : "The first Blender Open Movie from 2006",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" ],
@michaelevensen
michaelevensen / SlideIn.svelte
Created April 12, 2024 11:20
SlideIn.svelte
import { quintOut } from 'svelte/easing';
/** @param {number | string} value
* @returns {[number, string]}
*/
function split_css_unit(value) {
const split = typeof value === 'string' && value.match(/^\s*(-?[\d.]+)([^\s]*)\s*$/);
return split ? [parseFloat(split[1]), split[2] || 'px'] : [/** @type {number} */ (value), 'px'];
}
export { split_css_unit };
@michaelevensen
michaelevensen / LoadingIndicator.svelte
Created April 8, 2024 08:13
LoadingIndicator.svelte
<script lang="ts">
import { onMount } from 'svelte';
export let colors: string[] = ['#FFF', '#FFF', '#541161', '#8114B0', '#9F46CE', '#FFF'];
interface Options {
cellWidth: number;
cellHeight: number;
cellCount: {
x: number;
@michaelevensen
michaelevensen / DraggableItem.svelte
Last active December 1, 2023 22:46
Wrap anything in this and you get nice spring draggability. Just be aware that the relative positioning is `window`.
<script lang="ts">
import { spring } from 'svelte/motion';
export let position = { x: 0, y: 0 };
let dragging = false;
const start = () => {
dragging = true;
};
@michaelevensen
michaelevensen / & operator.ts
Last active November 30, 2023 14:00
Really nice flexible way of defining types.
type QueueItem<T> =
| { status: 'idle'; }
| { status: 'uploading'; progress: number; }
| { status: 'done'; url: string; file: T; }
| { status: 'error'; error: Error; };
type QueueItem = {
id: number;
} & (QueueItemUpload | QueueItemDone | QueueItemError);
xcrun simctl openurl booted "my.app.com://deeplink"
@michaelevensen
michaelevensen / FontFeatures.swift
Created September 12, 2023 12:17
This is how you can use font features in Swift.
public static let book: Font = {
// Font features
let fontFeatureSettings: [CFDictionary] = [
[
kCTFontFeatureTypeIdentifierKey: kTypographicExtrasType,
kCTFontFeatureSelectorIdentifierKey: kSlashedZeroOnSelector
] as CFDictionary
]
// Font description
@michaelevensen
michaelevensen / Springs.swift
Created August 8, 2023 12:28
A collection of nice spring values.
withAnimation(.interactiveSpring(response: 0.15, dampingFraction: 0.45, blendDuration: 0.5)) {
//
}
withAnimation(.interpolatingSpring(
mass: 1,
stiffness: 200,
damping: 20,
initialVelocity: 20)) {
//
@michaelevensen
michaelevensen / DateFormatting.swift
Created April 17, 2023 12:44
Date / duration formatting with the new `.formatted()` API in Swift.
Text((startDate..<endDate).formatted(.components(style: .wide)).capitalized)
Text(endDate.formatted(.relative(presentation: .numeric, unitsStyle: .spellOut)))
@michaelevensen
michaelevensen / MinMaxClamped.swift
Created April 3, 2023 08:38
Really nice extension for `min(max())`
// Example use:
// let progress = val.clamped(to: 0...1)
extension Comparable {
func clamped(to limits: ClosedRange<Self>) -> Self {
return min(max(self, limits.lowerBound), limits.upperBound)
}
}