Skip to content

Instantly share code, notes, and snippets.

View T1T4N's full-sized avatar
👽

Robert Armenski T1T4N

👽
View GitHub Profile
@T1T4N
T1T4N / URLSession+DataTaskProgressPublisher.swift
Last active May 2, 2023 07:39
Emulating a DataTaskPublisher with Progress
#if canImport(Combine)
import Foundation
import Combine
@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension URLSession {
public typealias DataTaskProgressPublisher =
(progress: Progress, publisher: AnyPublisher<DataTaskPublisher.Output, Error>)
@T1T4N
T1T4N / object_hash.js
Created March 28, 2023 10:34
object-hash benchamark
!function(e){var t;"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(e):("undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.objectHash=e())}(function(){return function r(o,i,u){function s(n,e){if(!i[n]){if(!o[n]){var t="function"==typeof require&&require;if(!e&&t)return t(n,!0);if(a)return a(n,!0);throw new Error("Cannot find module '"+n+"'")}e=i[n]={exports:{}};o[n][0].call(e.exports,function(e){var t=o[n][1][e];return s(t||e)},e,e.exports,r,o,i,u)}return i[n].exports}for(var a="function"==typeof require&&require,e=0;e<u.length;e++)s(u[e]);return s}({1:[function(w,b,m){!function(e,n,s,c,d,h,p,g,y){"use strict";var r=w("crypto");function t(e,t){t=u(e,t);var n;return void 0===(n="passthrough"!==t.algorithm?r.createHash(t.algorithm):new l).write&&(n.write=n.update,n.end=n.update),f(t,n).dispatch(e),n.update||n.end(""),n.digest?n.digest("buffer"===t.encoding?void 0:t.encoding):(e=n.read(),"buffer"!==t.encoding?e.toSt
@T1T4N
T1T4N / exportActionsUnionFromSlice.ts
Last active March 27, 2023 10:05
Use Redux Toolkit's createSlice with useReducer + export a type union of all its actions defined in 'reducers'
// https://stackoverflow.com/a/64582352
export type SliceActions<T> = {
[K in keyof T]: T[K] extends (...args: any[]) => infer A ? A : never;
}[keyof T];
// USAGE - NOTE: This doesn't work with `extraReducers` and the builder syntax
export type MySlice = typeof slice;
export type StateAction = SliceActions<MySlice['actions']>;
export type SliceReducer = Reducer<IState, StateAction>;
@T1T4N
T1T4N / zip.ts
Created March 24, 2023 09:11
Typescript implementation of a zip function
// Source: https://stackoverflow.com/a/70192772/6053417
export function zip<T extends unknown[][]>(
...args: T
): { [K in keyof T]: T[K] extends (infer V)[] ? V : never }[] {
const minLength = Math.min(...args.map((arr) => arr.length));
// @ts-expect-error This is too much for ts
return [...Array(minLength).keys()].map((i) => args.map((arr) => arr[i]));
}
@T1T4N
T1T4N / conditional_decorator.py
Last active March 14, 2023 01:09
Python conditional decorator
class conditional_decorator(object):
def __init__(self, dec, condition):
self.decorator = dec
self.condition = condition
def __call__(self, func):
if not self.condition:
# Return the function unchanged, not decorated.
return func
return self.decorator(func)
@T1T4N
T1T4N / gist:46e1d3839786f8977be94d46c69233a8
Created February 6, 2023 13:42
macOS: Hide a custom app's dock icon
# https://apple.stackexchange.com/questions/357109/run-applescript-in-background-without-showing-in-app-switcher#comment471468_357109
defaults write '/Applications/AppName.app/Contents/Info.plist' LSUIElement -bool yes
@T1T4N
T1T4N / run_whisper.sh
Created October 10, 2022 14:47
Run OpenAI Whisper on M1 MacBook Pro
# Original author: https://twitter.com/esizkur/status/1579207536812904448
git clone https://github.com/ggerganov/whisper.cpp
cd whisper.cpp
make
./download-ggml-model.sh large
ffmpeg -i recording.m4a -acodec pcm_s16le -ar 16000 recording.wav
./main -m models/ggml-large.bin -l de -f recording.wav | tee transcript.log
@T1T4N
T1T4N / primes.py
Created December 14, 2022 12:26
Python one liner - first 10 primes
print(list(filter(lambda x: all(x%d for d in range (2,x)), range(2, 3**10)))[:10])
Never set WKWebView as the top view in a XIB, otherwise:
WKWebView: configuration cannot be nil
Correct approach: Add it as a subview with correct constraints
@T1T4N
T1T4N / gist:a77ddb077469e3a05a29241db6dbe73d
Created October 24, 2022 12:19
Xcode 12+ - Sane navigation flow for editor tabs
⌘ + ⇧ + O - Open in temporary Tab
⌘ + ⌥ + O - Make tab permanent