Skip to content

Instantly share code, notes, and snippets.

View sowbug's full-sized avatar

Mike Tsao sowbug

View GitHub Profile
@sowbug
sowbug / wiggler.ino
Created July 2, 2023 21:16
USB mouse wiggler for Arduinos that can emulate USB devices
#include "Mouse.h"
void setup() {
Mouse.begin();
// Give it a sec to initialise, or we miss the first jiggle when it's plugged in
delay(5000);
}
int shift = 5;
int instdelay = 50;
@sowbug
sowbug / subscription_2.rs
Created December 13, 2022 22:46
Try #2 on threaded subscription, this time with a view() method on the app calling into the background struct's methods to construct the view.
// See https://gist.github.com/sowbug/40148c249136a037cc3b4b814e9de129 for try #1
//
// https://github.com/iced-rs/iced/discussions/1600 for more background
use iced::{
executor, time,
widget::{button, column, container, text},
window, Application, Command, Event as IcedEvent, Settings, Theme,
};
use iced_native::futures::channel::mpsc;
@sowbug
sowbug / subscription_1.rs
Last active December 13, 2022 21:31
One way to wrap an Iced subscription around a long-running task in another CPU thread. Probably wrong. See https://github.com/iced-rs/iced/discussions/1600
use iced::{
executor, time,
widget::{button, column, container, text},
window, Application, Command, Event as IcedEvent, Settings, Theme,
};
use iced_native::futures::channel::mpsc;
use iced_native::subscription::{self, Subscription};
use std::thread::JoinHandle;
enum ThingSubscriptionState {
@sowbug
sowbug / viewer-factory.rs
Created October 20, 2022 16:56
One way to keep iced view()/update() close to the model code that it uses
use iced::Sandbox;
use iced::{button, Alignment, Button, Column, Container, Element, Settings, Text};
use std::cell::RefCell;
use std::rc::{Rc, Weak};
pub fn main() -> iced::Result {
Counter::run(Settings::default())
}
#[derive(Debug, Clone, Copy)]
$ diff ../iced/examples/counter/src/main.rs src/main.rs
1,3c1,4
< use iced::{
< button, Alignment, Button, Column, Element, Sandbox, Settings, Text,
< };
---
> use iced::Sandbox;
> use iced::{button, Alignment, Button, Column, Container, Element, Settings, Text};
> use std::cell::RefCell;
> use std::rc::Rc;
use iced::Sandbox;
use iced::{button, Alignment, Button, Column, Container, Element, Settings, Text};
use std::cell::RefCell;
use std::rc::Rc;
pub fn main() -> iced::Result {
Counter::run(Settings::default())
}
#[derive(Debug, Default)]
@sowbug
sowbug / prompt-generator.py
Last active September 2, 2022 20:17
Stable Diffusion random prompt generator
#!/usr/bin/env python
import random
CONCEPTS = [
'baby',
'bacon',
'cabbage',
'cat',
'cauldron',
@sowbug
sowbug / make-dfplayer-mp3-tree.py
Last active May 22, 2022 17:31
Given a bunch of MP3 files in directories, copies them into a file tree that is compatible with DFPlayer.
#!/usr/bin/env python3
# Given a bunch of MP3 files in directories,
# copies them into a file tree that is
# compatible with DFPlayer.
import os
import shutil
src_dir = './sfx'
@sowbug
sowbug / tracker.ino
Created May 29, 2021 22:42
Bitcoin tracker on ESP8266-based OLED
// For Heltec Wifi Kit 8
// Code stolen/adapted from many sources
#include <U8g2lib.h>
#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <ESP8266HTTPClient.h>
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ 16, /* clock=*/ 5, /* data=*/ 4);
@sowbug
sowbug / 538.py
Last active November 4, 2020 06:40
Make it easier for Python programmers to create FiveThirtyEight simulations on November 3, 2020
#!/bin/env python3
TOSSUP = [
'GA', # Georgia, 16
'NC', # North Carolina, 15
]
DEM_NARROW = [
'AZ', # Arizona, 11
'ME', # Maine Popular Vote, 2