Skip to content

Instantly share code, notes, and snippets.

View olchyk98's full-sized avatar
🤍
I make people confused.

oles olchyk98

🤍
I make people confused.
View GitHub Profile
@olchyk98
olchyk98 / glsl-vec.js
Created July 12, 2025 15:43
GLSL Vector Swizzling in Javascript
function vec(...args) {
if (args.length > 4) {
throw new Error('Only vectors with up to 4 elements are supported.')
}
const proxied = new Proxy(args, {
get(t, p) {
if (['x', 'r'].includes(p)) return t[0]
if (['y', 'g'].includes(p)) return t[1]
if (['z', 'b'].includes(p)) return t[2]
if (['w', 'a'].includes(p)) return t[3]
function $iterate (levels, depth = 0, current = {}, acc = []) {
if (depth > levels.length - 1) {
acc.push({ ...current })
return acc
}
for (let x = 0; x < levels[depth].length; ++x) {
const prop = levels[depth][x]
current[prop] = `_${prop}`
$iterate(levels, depth + 1, current, acc)
import mime from 'mime'
import { getSongAudioStream } from '../../../../../_db/song'
import { headers } from 'next/headers'
import { clamp } from '../../../../../../utils/clamp'
export async function GET (
_req: Request,
{ params }: { params: Promise<{ songId: string }> },
) {
const id = (await params).songId
import { Query } from 'mingo'
import { assoc, chain, uniq } from 'ramda'
const entries = {
$collection: [
{},
{
brandId: [ 'A' ],
agencyId: [ 'C', 'D' ],
},
import { MongoClient } from 'mongodb'
import Bluebird from 'bluebird'
import { add, identity, times } from 'ramda'
const client = new MongoClient('<redacted>')
const db = client.db('searchtest')
const limit = 1e6
const runs = 1
const R = require('ramda')
function nativeCycle (k) {
return k.map((k) => k * Math.random())
}
function ramdaCycle (k) {
return R.map((k) => k * Math.random(), k)
}
// env::common.js
const toString = require('./src/toString') // R.string
const maxScore = 100
function memorizeForMe (fn) {
const cache = new Map()
const cacheScore = new Map()
return (...args) => {
@olchyk98
olchyk98 / amend-ast.ts
Created February 3, 2024 21:23
Amend factory dependencies parsing using AST.
import fs from 'fs'
import { parse } from 'acorn'
import { map, pluck, uniq } from 'ramda'
// Acorn has shitty types. Have to use "any". Questioning my life choices at this point.
function createAST (contents: string): acorn.Node {
return parse(contents)
}
import { useState, useRef } from 'react'
function useStateWithCb <T>(initialValue?: T): StateContainer<T> {
const { stateValue, setState } = useState<T>(initialValue)
const nextCallback = useRef<SetStateCallback | null>(null)
const updateState: SetStateCallback = (value, cb) => {
nextCallback.current = cb
setState(value)
}
type Person (initialName: string) =
member this.Name =
initialName
member this.ChangeName (newName: string) =
let nameWithPrefix = "changed" + newName
this
member this.DisplayName () =
let printStr = printfn "%s"