Skip to content

Instantly share code, notes, and snippets.

//
// OCXML.swift
// Created by Marco Arment on 9/23/24.
//
// Released into the public domain. Do whatever you'd like with this.
// No guarantees that it'll do anything, or do it correctly. Good luck!
//
import Foundation
javascript:(function()%7Bwindow.location.href%3D'https%3A%2F%2F12ft.io%2F'%2Bwindow.location.href%3B%7D)()
@jasonsnell
jasonsnell / weather graph.js
Created July 4, 2024 19:45
Weather graph widget for Scriptable
// Based on code by Efrén Gámez <https://gist.github.com/ImGamez/a8f9d77bf660d7703cc96fee87cdc4b0>
// and modified by Max Zeryck <https://talk.automators.fm/t/widget-examples/7994/217>
// this version by Jason Snell. parsing weatherkit data directly is beyond the scope of this widget;
// it loads a dumped weatherkit JSON from a remote server. Supply your own.
// This widget also loads live data from a weather station, again in a custom format.
// You will need to replace both of these data sources in order to get weather other than mine.
const highTemps = [ ]
const dailyConditions = [ ]
@christianselig
christianselig / LongPressButton.swift
Last active November 4, 2024 06:52
How to accomplish a long-pressable button in SwiftUI with two different techniques. The first just uses SwiftUI but due to the simultaneous gesture requirement you also have to ensure both don't fire concurrently. The second uses UIKit and wraps UIButton and UILongPressGestureRecognizer which natively handles this behavior.
import SwiftUI
// PURE SwiftUI way with State tracking to prevent double events
struct ContentView: View {
@State private var ignoreTapEvent = false
var body: some View {
Button {
guard !ignoreTapEvent else {
@rickosborne
rickosborne / mastodon-thread-to-json.js
Last active April 23, 2023 23:45
Bookmarklet to extract a Mastodon thread into JSON
javascript:(function () {
/* ========================================
Mastodon thread scraper, by Rick Osborne.
Copy this entire file, from the opening "javascript:" to the last "();".
Create a new bookmark in your browser, using the copied text as the URL.
When you are on a Mastodon thread page, activate this bookmark.
======================================== */
function findOne(parent, selector, block) {
if (parent == null) {
return undefined;
// Before 😕
let doingSomethingToOptionalView1: CGFloat? = {
guard let firstSubview = subviews.first else { return nil }
return (firstSubview.bounds.width / 2.0) + otherView.bounds.width
}()
// After 😊
let doingSomethingToOptionalView2 = subviews.first.useIfNotNil { ($0.bounds.width / 2.0) + otherView.bounds.width }
@marcoarment
marcoarment / S3.php
Last active June 18, 2024 14:15
A simple PHP class to perform basic operations against Amazon S3 and compatible services.
<?php
/*
A simple PHP class to perform basic operations against Amazon S3 and compatible
services. Requires modern PHP (7+, probably) with curl, dom, and iconv modules.
Copyright 2022 Marco Arment. Released under the 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
in the Software without restriction, including without limitation the rights
@kingkool68
kingkool68 / examples.php
Created June 23, 2022 20:45
Helper functions to make generating WordPress post type labels and taxonomy labels easier
<?php
// Register a Book post type
$args = array(
'labels' => generate_post_type_labels( 'book', 'books' ),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
@scottbez1
scottbez1 / PumpkinEye.ino
Last active September 27, 2024 21:31
Example code to animate the eye movements of a pumpkin Halloween decoration. See https://youtu.be/tyLo3LW5UCo for the full build video! Consider sponsoring me on github to support projects like this: https://github.com/sponsors/scottbez1
#include <Servo.h>
Servo s;
int pos[] = { 90, 80, 65, 120, 105, 110, 98, 68, 84, 74};
int d[] = {3000, 500, 1200, 1530, 700, 200, 800, 450, 300, 670};
void setup() {
s.attach(6); // <---- Change 6 to the pin you're using
}
@kingfisher1234
kingfisher1234 / gist:caf351bed786f9050e1fa28c3352ded9
Last active January 12, 2022 18:11
Physical mute button for Zoom using an ATTiny85/Digispark and the Micronucleus bootloader to allow programming with the Arduino IDE - Mac Version
/*
Thanks to Elliotmade for the inspiration on this project
https://elliotmade.com/2020/04/23/physical-mute-button-for-zoom-meetings/
Refactored by HaxNobody to extend functionalty
https://gist.github.com/HaxNobody/7bde369d7a41348b8b91c1a4f358ea4a#file-zoommutebutton-ino
This program will send USB HID keyboard presses to bring the Zoom window into
the foreground and activate microphone and video functions.
* A momentary press on button 1 will toggle mute on or off.
* Press and hold button 1 to close zoom (Zoom Needs to be in focus on a Mac (Or you will close a different window)).
*/