Skip to content

Instantly share code, notes, and snippets.

View theodrosyimer's full-sized avatar

Theodros Yimer theodrosyimer

  • France
View GitHub Profile
@theodrosyimer
theodrosyimer / combinators.js
Created November 19, 2021 12:42 — forked from Avaq/combinators.js
Common combinators in JavaScript
const I = x => x
const K = x => y => x
const A = f => x => f (x)
const T = x => f => f (x)
const W = f => x => f (x) (x)
const C = f => y => x => f (x) (y)
const B = f => g => x => f (g (x))
const S = f => g => x => f (x) (g (x))
const S_ = f => g => x => f (g (x)) (x)
const S2 = f => g => h => x => f (g (x)) (h (x))
@theodrosyimer
theodrosyimer / get-youtube-timestamps.js
Last active February 29, 2024 23:54
get-youtube-timestamps
console.log(getYoutubeTimestamps())
// works for videos less than 100 hours (should be enough, but easily extensible)
function getYoutubeTimestamps({withMilliseconds = true} = {}) {
if ($('#right-arrow')) {
$('#right-arrow').click()
}
let chaptersTimestampList = [...$$('[slot="extra-content"] #scroll-container #endpoint > #details:not([hidden]) #time')].map(item => ({
timestamp: item.textContent,
title: item.previousElementSibling.textContent
@theodrosyimer
theodrosyimer / get-video-duration.ts
Last active February 28, 2025 08:15
Get the duration of a video using Node.js and TypeScript
/////////
// Inspired by: https://gist.github.com/Elements-/cf063254730cd754599e
/////////
import type { PathLike } from 'fs'
import { createReadStream } from 'fs'
import { pipeline } from 'stream/promises'
const BUFFER_SIZE = 100
// Define MVHD_HEADER as a Uint8Array directly with the correct bytes
@theodrosyimer
theodrosyimer / A_UUID_v7_for_Postgres.sql
Created March 19, 2025 11:12 — forked from kjmph/A_UUID_v7_for_Postgres.sql
Postgres PL/pgSQL function for UUID v7 and a bonus custom UUID v8 to support microsecond precision as well. Read more here: https://datatracker.ietf.org/doc/rfc9562/
-- Based off IETF draft, https://datatracker.ietf.org/doc/draft-peabody-dispatch-new-uuid-format/
create or replace function uuid_generate_v7()
returns uuid
as $$
begin
-- use random v4 uuid as starting point (which has the same variant we need)
-- then overlay timestamp
-- then set version 7 by flipping the 2 and 1 bit in the version 4 string
return encode(