Skip to content

Instantly share code, notes, and snippets.

View st3fan's full-sized avatar

Stefan Arentz st3fan

View GitHub Profile
defmodule WeatherWeb.WeatherLive do
use WeatherWeb, :live_view
@owm_url "https://api.openweathermap.org/data/2.5/weather?units=metric&lat=43.8999464&lon=-78.9408778&appid=XXX"
defmodule WeatherWeb.WeatherLive.WeatherSummary do
defstruct [:temperature, :name, :description, :icon]
end
alias WeatherWeb.WeatherLive.WeatherSummary
takahe-takahe-stator-1 | Traceback (most recent call last):
takahe-takahe-stator-1 | File "/usr/local/lib/python3.11/site-packages/asgiref/sync.py", line 486, in thread_handler
takahe-takahe-stator-1 | raise exc_info[1]
takahe-takahe-stator-1 | File "/takahe/stator/models.py", line 172, in atransition_attempt
takahe-takahe-stator-1 | next_state = await current_state.handler(self) # type: ignore
takahe-takahe-stator-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
takahe-takahe-stator-1 | File "/takahe/users/models/password_reset.py", line 41, in handle_new
takahe-takahe-stator-1 | await sync_to_async(send_mail)(
takahe-takahe-stator-1 | File "/usr/local/lib/python3.11/site-packages/asgiref/sync.py", line 448, in __call__
takahe-takahe-stator-1 | ret = await asyncio.wait_for(future, timeout=None)
@st3fan
st3fan / ivory-check.py
Created December 22, 2022 19:51
Cron job to check if the Ivory TestFlight Beta is available
#!/usr/bin/env python3
import requests
if __name__ == "__main__":
r = requests.get("https://testflight.apple.com/join/2bauS53v")
r.raise_for_status()
if "This beta is full" not in r.text:
r = requests.post("https://api.pushover.net/1/messages.json", data={
"token": "PUSHOVER_TOKEN_HERE",
@st3fan
st3fan / day6.c
Last active December 7, 2022 01:50
char*I="zcncrcnrrlccmhchssgqsqrsstfffnqfnfsswgwjjcmcnnvjvwjvwvfvnvwwhvv"
"wmwhmwwwhbhhldhdmhhdfdbdfbdblllnfllgslllqhlhfhlhqllncnfnsffwmwzzlglzlw"
"lhwwmvmddpvvbrvrdvrdvdhhzdhdpdzzbgbsssrpsrshrshhbqbgbmmtwwcbcrbbvnvhnn"
"cscwcwlcwlwnwswbbnwntthzzdlzdzffvqvdqvvtptdptphpddzzvhzvzwwqgqjjjvsspv"
"spsbsffvpvcvjcvjvrvjjgmjjhrrdhhdvhvttjttzptpssnlnjjlnnhmnndjnjwwtjjtbb"
"fflwfwgwvvpjpwpcwcgglmgmdmnmbbqtqctcwcmwwvmvlmvmdvdvhvlhlzhzttghttnvnj"
"ntnqqtmtwwhvhrhfhchqchhdrdllnwnfwfjjmsmmnhhshnhpptstjjpnpzzhmmpssgrsrz"
"srrffzjjhvjhjcjcpcvpccfnfjnfjfllssrdsdnnmffldldppcctcmtctffprpsrrrfhfm"
"flldccnpppvsswppdgpgjpgpqgpqpjppclcjczcnzzzqvzzwlzzqfzffsqqphqhvqqbccc"
"stsdttwcwcvvmjjhqqmllpglgtgwgnnbnrbnnjdndhhbrbvrvwwwblwwwppmdmttztqzqr"
class _NoPadding: pass
_Chunk_T = TypeVar("_Chunk_T")
def _windowed(iterable: Iterable[_Chunk_T], size: int, step: int = 1, padding: _NoPadding|Any = _NoPadding()) -> Iterable[Iterable[_Chunk_T|None]]:
it = iter(iterable)
chunk: List[_Chunk_T|Any] = []
while True:
# Pop step items from the buffer
if chunk:
#[cfg(test)]
mod tests {
use std::convert::TryInto;
use std::num::TryFromIntError;
#[test]
fn it_works() {
let a = 1i16;
let b: Result<i8, TryFromIntError> = a.try_into();
assert!(b.is_ok());
// Random code from https://docs.microsoft.com/en-ca/learn/paths/rust-first-steps/
use std::fmt;
trait Distance<T> {
fn distance(&self) -> T;
}
#[derive(Debug, PartialEq)]
struct Point<T> {
@st3fan
st3fan / day20.c
Created November 14, 2021 23:20
Advent of Code - 2015 Day 20
/* Advent of Code - 2015 Day 20 */
#include <stdio.h>
#include <dispatch/dispatch.h>
int number_of_presents(int house) {
int n = 0;
for (int elf = 1; elf <= house; elf++) {
if ((house % elf) == 0) {
n += (10 * elf);