Skip to content

Instantly share code, notes, and snippets.

View m1guelpf's full-sized avatar

Miguel Piedrafita m1guelpf

View GitHub Profile
type AnyFunction = (...args: any[]) => any
function useEvent<T extends AnyFunction>(callback?: T) {
const ref = useRef<AnyFunction | undefined>(() => {
throw new Error("Cannot call an event handler while rendering.")
})
// Or useInsertionEffect if it's React 18
useLayoutEffect(() => {
ref.current = callback
})
# Script for converting a HF Diffusers saved pipeline to a Stable Diffusion checkpoint.
# *Only* converts the UNet, VAE, and Text Encoder.
# Does not convert optimizer state or any other thing.
# Written by jachiam
import argparse
import os.path as osp
import torch
@shawwn
shawwn / adam.py
Last active February 15, 2023 19:48
Reformulating Adam optimizer to gain an intuition about what it's doing.
def lerp(a, b, t):
return (b - a) * t + a
def bias(i, x, beta):
return 1 - jnp.asarray(beta, x.dtype) ** (i + 1)
@optimizer
def adam(step_size, b1=0.9, b2=0.999, eps=1e-8) -> OptimizerResult:
"""Construct optimizer triple for Adam.
@stephancasas
stephancasas / skip-forward-45.jxa.js
Created March 29, 2023 17:23
Pocket Casts AppleScript Automation
#!/usr/bin/env osascript -l JavaScript
/**
* ------------------------------------------------------------------------------
* Pocket Casts Automation / Skip Forward
* ------------------------------------------------------------------------------
*
* Skip forward 45 seconds in Pocket Casts for Mac
*
* Note: the window must be open. It may be *hidden*, but it must be open.
@VictorTaelin
VictorTaelin / gpt4_abbreviations.md
Last active April 29, 2025 09:24
Notes on the GPT-4 abbreviations tweet

Notes on this tweet.

  • The screenshots were taken on different sessions.

  • The entire sessions are included on the screenshots.

  • I lost the original prompts, so I had to reconstruct them, and still managed to reproduce.

  • The "compressed" version is actually longer! Emojis and abbreviations use more tokens than common words.

@ald3ns
ald3ns / lockbit_str_decrypt.py
Created April 16, 2023 17:48
Binary Ninja script to decrypt strings from ARM macOS Lockbit sample!
# SHA256: 3e4bbd21756ae30c24ff7d6942656be024139f8180b7bddd4e5c62a9dfbd8c79
# Get the strings from the data section
data_section = bv.get_section_by_name("__data")
symbols = bv.get_symbols(data_section.start, (data_section.end-data_section.start))
xor_val = 0
xor=Transform['XOR']
# Find the _xor_val
@JamesSedlacek
JamesSedlacek / KeyboardToolbar.swift
Last active May 8, 2025 22:33
SwiftUI Keyboard Toolbar Workaround
//
// KeyboardToolbar.swift
//
// Created by James Sedlacek on 9/20/23.
//
import SwiftUI
import Combine
@Observable
@davidsteppenbeck
davidsteppenbeck / AnimatingMeshView.swift
Created June 11, 2024 16:41
Animating mesh gradient for iOS 18 using TimelineView
import SwiftUI
struct AnimatingMeshView: View {
let referenceDate: Date
var body: some View {
TimelineView(.animation) { context in
let t = context.date.timeIntervalSince(referenceDate)
MeshGradient(width: 5, height: 4, points: [
import SwiftUI
// Remember to download FontSettings.swift
struct WWDC24AnimatedTextView: View {
var text = "Hello, World!"
var animation: Animation = .easeInOut
var targetFontSize: CGFloat = 40
var minimumFontSize: CGFloat = 30
var targetFontWeight: Font.Weight = .semibold
@drewolbrich
drewolbrich / InputNotWorkingIndicator.swift
Last active August 11, 2024 03:33
A recreation of the Mac Virtual Display "Input temporarily not working" indicator
//
// InputNotWorkingIndicator.swift
//
// Created by Drew Olbrich on 6/26/24.
// Copyright © 2024 Lunar Skydiving LLC. All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal