Skip to content

Instantly share code, notes, and snippets.

import GameKit
public class SeededGenerator: RandomNumberGenerator {
public let seed: UInt64
private let generator: GKMersenneTwisterRandomSource
public convenience init() {
self.init(seed: 0)
}
const uniswapV3PoolABI = [
{
inputs: [],
name: 'slot0',
outputs: [
{ internalType: 'uint160', name: 'sqrtPriceX96', type: 'uint160' },
{ internalType: 'int24', name: 'tick', type: 'int24' },
{ internalType: 'uint16', name: 'observationIndex', type: 'uint16' },
{
internalType: 'uint16',
@malonehedges
malonehedges / useRouteTrap.ts
Last active November 11, 2022 20:04
A hook to easily trap routing on a page for a Next.js app. Use this to prevent routing away from a page while you have pending changes or want to display some confirmation before routing.
import { useRouter } from 'next/router'
import { useCallback, useEffect, useState } from 'react'
/**
* A hook that easily lets you add a route change trap.
* @param shouldTrap Whether or not to trap the route change.
* @returns An object with the following properties:
* - `isTrapped`: Whether or not the route change is currently trapped.
* - `leavePage`: A function that will leave the page.
* - `stayOnPage`: A function that will stay on the page.
#!/bin/bash
# This script
# - takes in a file name from the command line
# - reads the file contents
# - requests from the OpenAI GPT-3 API
# - gets the text of the first suggestion using jq (jq '.choices[0].text' -r)
# - appends the first suggestion to the file
# Usage: ./gpt.sh <file>
import SwiftUI
import AuthenticationServices
final class SignInWithAppleButton: UIViewRepresentable {
let buttonType: ASAuthorizationAppleIDButton.ButtonType
let style: ASAuthorizationAppleIDButton.Style
let cornerRadius: CGFloat?
init(
buttonType: ASAuthorizationAppleIDButton.ButtonType = .signIn,
func isJailbroken() -> Bool {
#if !targetEnvironment(simulator)
if FileManager.default.fileExists(atPath: "/Applications/Cydia.app") ||
FileManager.default.fileExists(atPath: "/Library/MobileSubstrate/MobileSubstrate.dylib") ||
FileManager.default.fileExists(atPath: "/bin/bash") ||
FileManager.default.fileExists(atPath: "/usr/sbin/sshd") ||
FileManager.default.fileExists(atPath: "/etc/apt") ||
FileManager.default.fileExists(atPath: "/private/var/lib/apt/") {
return true
}
@malonehedges
malonehedges / TestVC.swift
Created June 25, 2019 01:17
auto-sizing cells with variable height content
import UIKit
import SnapKit
class TestVC: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
tableView.estimatedRowHeight = 58
tableView.rowHeight = UITableView.automaticDimension
func distributeViewsEvenly(views: [UIView], axis: NSLayoutConstraint.Axis) -> UIView {
let containerView = UIView()
for (index, view) in views.enumerated() {
let previousView = containerView.subviews.last
let isLastView = index == views.endIndex - 1
containerView.addSubview(view)
view.snp.makeConstraints { make in
@malonehedges
malonehedges / moodleAutoLogin.js
Created February 6, 2018 21:35
Moodle Auto-Login
// ==UserScript==
// @name Moodle Auto-Login
// @namespace https://moodle.oxy.edu/
// @version 0.1.0
// @description Automatically redirect to the login page if logged out.
// @author Malone Hedges (https://malone.io)
// @match https://moodle.oxy.edu/*
// @grant none
// ==/UserScript==
@malonehedges
malonehedges / CAH.js
Created November 28, 2017 16:28
Timing of map, reduce, filter
import Game from '../Game'
import cards from './cards'
export default class CAH extends Game {
static getExpansionsPrettyButDumb () {
return cards
.map((card) => card.expansion)
.filter((expansion, index, arr) => arr.indexOf(expansion) === index)
}