Skip to content

Instantly share code, notes, and snippets.

View lukevanin's full-sized avatar

Luke Van In lukevanin

View GitHub Profile
if (new URLSearchParams(window.location.search).get('portal')) {
// <create start portal>
// Create portal group to contain all portal elements
const startPortalGroup = new THREE.Group();
startPortalGroup.position.set(SPAWN_POINT_X, SPAWN_POINT_Y, SPAWN_POINT_Z);
startPortalGroup.rotation.x = 0.35;
startPortalGroup.rotation.y = 0;
// Create portal effect
private func createTexture(sampleBuffer: CMSampleBuffer, planeIndex: Int, pixelFormat: MTLPixelFormat) throws -> MTLTexture {
guard let cvImageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else {
throw MyError.normal
}
let isPlanar = CVPixelBufferIsPlanar(cvImageBuffer)
let width = isPlanar ? CVPixelBufferGetWidthOfPlane(cvImageBuffer, planeIndex) : CVPixelBufferGetWidth(cvImageBuffer)
let height = isPlanar ? CVPixelBufferGetHeightOfPlane(cvImageBuffer, planeIndex) : CVPixelBufferGetHeight(cvImageBuffer)
var cvMetalTexture: CVMetalTexture?
CVMetalTextureCacheCreateTextureFromImage(nil, _textureCache!, cvImageBuffer, nil, pixelFormat, width, height, planeIndex, &cvMetalTexture)
@bricklife
bricklife / LEGO SPIKE Prime JSON command examples.md
Last active February 9, 2025 14:35
LEGO SPIKE Prime JSON command examples

System

{"i":"EMWW","m":"get_firmware_info","p":{}}
{"m":"trigger_current_state","p":{}}
{"m":"program_modechange","p":{"mode":"play"}} // "mode": "play" or "download"
{"i":"ESGe","m":"set_hub_name","p":{"name":"U1BJS0U="}} // "name": Base64 string

Motor

@mikhailov-work
mikhailov-work / turbo_colormap.glsl
Last active April 8, 2025 19:03
Turbo Colormap Polynomial Approximation in GLSL
// Copyright 2019 Google LLC.
// SPDX-License-Identifier: Apache-2.0
// Polynomial approximation in GLSL for the Turbo colormap
// Original LUT: https://gist.github.com/mikhailov-work/ee72ba4191942acecc03fe6da94fc73f
// Authors:
// Colormap Design: Anton Mikhailov ([email protected])
// GLSL Approximation: Ruofei Du ([email protected])
@numist
numist / Main.swift
Last active May 27, 2022 06:54
A rough Swift implementation of the Vose alias method
// What is an alias method?
// If we have a list of elements with different frequencies,
// like the letters in the English language…
let frequencies = [
("a", 8.167), ("b", 1.492), ("c", 2.782), ("d", 4.253), ("e", 12.702),
("f", 2.228), ("g", 2.015), ("h", 6.094), ("i", 6.966), ("j", 0.153),
("k", 0.772), ("l", 4.025), ("m", 2.406), ("n", 6.749), ("o", 7.507),
("p", 1.929), ("q", 0.095), ("r", 5.987), ("s", 6.327), ("t", 9.056),
("u", 2.758), ("v", 0.978), ("w", 2.360), ("x", 0.150), ("y", 1.974),
@yohhoy
yohhoy / yuvrgb.md
Last active April 2, 2025 23:15
RGB <=> YCbCr(YPbPr) color space conversion
Y  = a * R + b * G + c * B
Cb = (B - Y) / d
Cr = (R - Y) / e
BT.601 BT.709 BT.2020
a 0.299 0.2126 0.2627
b 0.587 0.7152 0.6780
@mayoff
mayoff / !README.md
Last active August 14, 2023 15:09
Debugging Objective-C blocks in lldb

The attached lldb command pblock command lets you peek inside an Objective-C block. It tries to tell you where to find the source code for the block, and the values captured by the block when it was created.

Consider this example program:

#import <Foundation/Foundation.h>

@interface Foo: NSObject
@end

@implementation Foo

@NSProgrammer
NSProgrammer / Overview.md
Last active March 7, 2023 08:06
Comparing modern vs legacy graphics context rendering on iOS

legacy = UIGraphicsBeginImageContextWithOptions + UIGraphicsEndImageContext

modern = UIGraphicsImageRendererFormat + UIGraphicsImageRenderer

Take aways:

  • "modern" w/ prefersExtendedRange = NO
    • basically the same perf as "legacy"
    • probably a good idea to adopt since optimizations will likely be in "modern" first
  • "modern" w/ prefersExtendedRange = YES
//
// ============================================================================
//
// Quick sketch / rough idea of a redux store/state/action/reducer pattern.
//
// This works differently to ReduxJS, in that the reducer does not implement a
// switch statement for the action, but instead uses a double-dispatch
// functional call from the action to a factory that produces the redicer.
//. The store also has methods for each action type.
//
@lattner
lattner / TaskConcurrencyManifesto.md
Last active April 19, 2025 04:47
Swift Concurrency Manifesto