Skip to content

Instantly share code, notes, and snippets.

@thebluefish
thebluefish / discord_logger.py
Created August 23, 2018 02:46
Basic discord.py-based logger wrapped in a class, runs in separate thread, provides thread-safe logging helpers, locks interactions to single whitelisted guild for security
import discord
from discord.ext import commands
from threading import Thread
import asyncio
import sys
import traceback
import datetime
TOKEN = ''
# Expects the following to contain IDs pulled from discord
@thebluefish
thebluefish / gsm.rs
Last active October 6, 2020 02:07
bevy game state manager prototype
use super::states;
use bevy::{prelude::*, ecs::{Schedule, ThreadLocalExecution, SystemId, TypeAccess, ArchetypeAccess, ParallelExecutor}};
use std::borrow::Cow;
pub struct GamePlugin;
impl Plugin for GamePlugin {
fn build(&self, app: &mut AppBuilder) {
app
.add_resource(GameState::Stage1(SubState::Done))
@thebluefish
thebluefish / logging.rs
Last active November 3, 2020 03:39
A simple fern-based logging implementation demonstrating formatting for multiple outputs
use colored::*;
use log::*;
use std::{fs, thread::ThreadId};
/// Please ignore the evil that is parsing debug output
fn parse_thread_id(id: &ThreadId) -> String {
let id_str = format!("{:?}", id);
let parsed = (|| {
let start_idx = id_str.find('(')?;
@thebluefish
thebluefish / bevy_ex_asset_loading
Created November 26, 2020 02:22
Demonstrates waiting for assets to load asynchronously
use bevy::{prelude::*, asset::LoadState};
fn main() {
App::build()
.add_resource(GameState::Loading)
.add_resource(PendingAssets(Vec::new()))
.add_plugins(DefaultPlugins)
.add_startup_system(load_some_assets.system())
.add_system(loading.system())
.add_system(loaded.system())
@thebluefish
thebluefish / windows_hotplug.rs
Created May 25, 2021 19:22
first-draft windows hotplug support using subclass.
use bevy::prelude::*;
use bevy::{input::keyboard::KeyboardInput, prelude::*};
use bevy::winit::WinitWindows;
use winit::platform::windows::WindowExtWindows;
use bevy::window::WindowCreated;
use bevy::app::{Events, ManualEventReader};
use winapi::{
DEFINE_GUID,
ctypes::c_void,
shared::{
@thebluefish
thebluefish / TitleBarElectron.vue
Created October 22, 2021 22:36
An Electron 11 titlebar demo using Vue, HTML, SCSS
<template>
<header class="titlebar">
<div class="spacer">
<div :class="maximized ? 'drag drag-max' : 'drag drag-min'"/>
</div>
<div class="system-bar">
<button class="sys-btn" @click.stop="onMinimize()">
<img src="/caption-buttons.svg#minimize">
</button>
<button class="sys-btn" @click.stop="onMaximize()">
use bevy::prelude::*;
use bevy_inspector_egui::quick::WorldInspectorPlugin;
use std::{env, fs};
use std::path::Path;
fn main() {
App::new()
.add_plugin(DevAssetPlugin::default())
.add_plugins(DefaultPlugins)
.add_plugin(WorldInspectorPlugin::new())
@thebluefish
thebluefish / tsync_serde_test.rs
Created May 11, 2023 17:07
Tests serializing tsync example types to and from strings using serde
use chrono::{NaiveDate, NaiveDateTime};
use serde::{Deserialize, Serialize};
use tsync::tsync;
fn main() {
let msg = serde_json::to_string(&Message::Response(Response {
id: "Foo".into(),
result: NaiveDate::from_ymd(2016, 7, 8).and_hms(9, 10, 11),
})).unwrap();
//! A shader that uses "shaders defs", which selectively toggle parts of a shader.
use std::time::Duration;
use bevy::{
pbr::{MaterialPipeline, MaterialPipelineKey},
prelude::*,
reflect::{TypePath, TypeUuid},
render::{
mesh::MeshVertexBufferLayout,
render_resource::{
<!-- Avilable under MIT, Apache-2.0, The Unlicense, or the WTFPL at your choice -->
<svg class="eye" class:eye-open={$is_connected} viewBox="0 -150 400 300" width="80" xmlns="http://www.w3.org/2000/svg">
<g stroke-width="32" fill="none">
<path d={top_path} stroke="currentColor">
<animate bind:this={eyecon_close_top_anim} dur="0.2s" attributeName="d" from={top_path} to={path_closed} fill="freeze" begin="indefinite" />
<animate bind:this={eyecon_open_top_anim} dur="0.2s" attributeName="d" from={path_closed} to={top_path} fill="freeze" begin="indefinite" />
</path>
<path d={bottom_path} stroke="currentColor">
<animate bind:this={eyecon_close_bottom_anim} dur="0.2s" attributeName="d" from={bottom_path} to={path_closed} fill="freeze" begin="indefinite" />
<animate bind:this={eyecon_open_bottom_anim} dur="0.2s" attributeName="d" from={path_closed} to={bottom_path} fill="freeze" begin="indefinite" />