Skip to content

Instantly share code, notes, and snippets.

View m1guelpf's full-sized avatar

Miguel Piedrafita m1guelpf

View GitHub Profile
# 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
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
})
@z0r0z
z0r0z / ClubSig.sol
Last active September 24, 2022 19:47
EIP-712-signed multi-signature contract with NFT identifiers for signers and ragequit
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.4;
import "https://github.com/Rari-Capital/solmate/src/tokens/ERC721.sol";
import "https://github.com/kalidao/kali-contracts/blob/main/contracts/utils/NFThelper.sol";
/// @notice Minimal ERC-20 interface.
interface IERC20minimal {
function balanceOf(address account) external view returns (uint256);
@z0r0z
z0r0z / SingleNFT.sol
Last active June 2, 2022 08:20
1-of-1 NFT built on Solmate
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
import "https://github.com/Rari-Capital/solmate/blob/main/src/tokens/ERC721.sol";
/// @notice 1-of-1 NFT.
contract SingleNFT is ERC721 {
string internal URI;
constructor(
@z0r0z
z0r0z / GeneralizedGrimoire.md
Created January 5, 2022 02:15
MCV Grimoire for Investment Clubs, in github markdown with generalized references to allow for more options in chain and code references.

OPERATING AGREEMENT OF [[DAO LLC NAME]]

This Operating Agreement (this “Agreement”) sets forth the rights and obligations among [[DAO LLC NAME]], a Delaware limited liability company (the “Org”) and the members of the Org.

BACKGROUND

A. The Org has been formed for the purposes contemplated by this Agreement by the filing with the Secretary of State of the State of Delaware of a Certificate of Formation (the “Certificate”) in accordance with the Delaware Limited Liability Company Act (the “Delaware LLC Act”).

B. This Agreement is being entered into for the purposes of organizing and establishing the governance and operations of the Org and the rights and obligations of membership in the Org.

@z0r0z
z0r0z / MultiSig.sol
Created December 26, 2021 03:28
EIP-712-signed multi-signature contract
// SPDX-License-Identifier: GPL-3.0-or-later
error NoExecParity();
error NoSigParity();
error NotSigner();
error SigOutOfOrder();
@hrkrshnn
hrkrshnn / generic.org
Last active March 19, 2025 23:52
Some generic writeup about common gas optimizations, etc.

Upgrade to at least 0.8.4

Using newer compiler versions and the optimizer gives gas optimizations and additional safety checks for free!

The advantages of versions 0.8.* over <0.8.0 are:

  • Safemath by default from 0.8.0 (can be more gas efficient than some library based safemath).
  • Low level inliner from 0.8.2, leads to cheaper runtime gas. Especially relevant when the contract has small functions. For
@jonbarrow
jonbarrow / connect.js
Last active October 22, 2023 21:20
Discord remote login script example
/*
Discord is able to log users in by scanning QR codes on the login screen,
these are randomly generated by the server and are sent to the client
over a secure web socket as a fingerprint, which gets scanned in by the app
and then used to login remotely. The QR codes actual contents are just
https://discord.com/ra/FINGERPRINT
This script shows how to connect to Discord and generate these
fingerprints automatically
*/

Twitter abuses all media file uploads, each type in its own way. If we want to upload a good looking animation loop from some low-color, high-detail generative art, we have to game their system's mechanisms.

  • don't upload a video file, they will re-encode it into absolute 💩

  • create a GIF, which they will auto-convert into a video file 😱

  • The frames of the GIF will be resized to an even-sized width using an extremely naive algorithm. Your GIF should be an even size (1000, 2000,

# Go here for the working version: https://gist.github.com/tombulled/d313c54a0681fcf0ba6d8092f11411e6#gistcomment-3069388
import hashlib
from pprint import pprint
import base64
import bytebuffer # https://github.com/alon-sage/python-bytebuffer, pip install bytebuffer
# Other ByteBuffer classes I've found: https://github.com/iGio90/PyByteBuffer, https://github.com/aglyzov/bytebuffer
import secrets
import pyaes # https://github.com/ricmoo/pyaes, pip install pyaes