Skip to content

Instantly share code, notes, and snippets.

View dgellow's full-sized avatar
🐢
Pulu pulu 🏳️‍🌈

Sam El-Borai dgellow

🐢
Pulu pulu 🏳️‍🌈
View GitHub Profile
const w32 = @import("vendor/zigwin32/win32.zig").everything;
const TRUE: w32.BOOL = 1;
const FALSE: w32.BOOL = 0;
fn windowProc(handle: w32.HWND, msg: u32, wparam: w32.WPARAM, lparam: w32.LPARAM) callconv(.C) w32.LRESULT {
switch (msg) {
w32.WM_DESTROY => {
w32.PostQuitMessage(0);
return 0;
@dgellow
dgellow / pulumi-github-app-webhook.ts
Last active September 26, 2023 10:02
Pulumi dynamic provider to set/update the Webhook config of a GitHub App
import * as pulumi from '@pulumi/pulumi';
import { Octokit } from '@octokit/core';
import { AppAuthentication, createAppAuth } from '@octokit/auth-app';
export interface ConfigurationResourceInputs {
appId: pulumi.Input<string>;
privateKey: pulumi.Input<string>;
clientId: pulumi.Input<string>;
clientSecret: pulumi.Input<string>;
url: pulumi.Input<string>;
@dgellow
dgellow / app_theme_settings.rs
Created January 18, 2022 10:54
Check if light theme enabled for applications via Windows registry key
use windows::Win32::System::Registry::{RegGetValueW, HKEY_CURRENT_USER, RRF_RT_REG_DWORD};
use crate::{
assert::{assert_eq, Result},
wide_string::ToWide,
};
pub enum Theme {
Light,
Dark,
@dgellow
dgellow / wide_string.rs
Created January 18, 2022 10:26
Convert rust strings to win32 PWSTR type
use windows::Win32::Foundation::PWSTR;
#[derive(Default)]
pub struct WideString(pub Vec<u16>);
pub trait ToWide {
fn to_wide(&self) -> WideString;
}
impl ToWide for &str {
@dgellow
dgellow / impl_ops_for_all.rs
Created January 13, 2022 09:34
Rust macro implementing BitOr trait for multiple struct
pub struct ClassStyle(pub WNDCLASS_STYLES);
pub struct WindowStyle(pub WINDOW_STYLE);
macro_rules! impl_ops_for_all {
($($t:ty),+) => {
$(impl std::ops::BitOr for $t {
type Output = Self;
fn bitor(self, rhs: Self) -> Self::Output {
Self(self.0 | rhs.0)
}
@dgellow
dgellow / display.rs
Last active January 10, 2022 11:03
A simple Rust macro display!() that combines println!() and std::io::stdout::flush()
#[macro_export]
macro_rules! display {
( $($t:tt)* ) => {
{
use std::io::Write;
let mut out = std::io::stdout();
write!(out, $($t)* ).unwrap();
write!(out, "\n").unwrap();
out.flush().unwrap();
}
@dgellow
dgellow / Dockerfile
Last active June 9, 2021 16:46
Idris2 dockerfile to target Game Boy Advance arch
#
# GBA development kit
#
FROM devkitpro/devkitarm:latest as devkit
#
# Idris build process
#
FROM dgellow/idris2:v0.3.0 as base
#include "main.h"
#include <windows.h>
#include <stdio.h>
#include "RemoteThread.h"
#include "ProcessInfo.h"
#include "Hidden.h"
/* Hidden contains things like:
// ReadProcessMemory
@dgellow
dgellow / gsl_defer.cpp
Last active February 9, 2020 06:15
C++ equivalent to Go's defer keyword. Extracted from GSL, see final_action and finally at https://github.com/microsoft/GSL/blob/master/include/gsl/gsl_util
#include <iostream>
#include <utility>
// Deferred allows you to ensure something gets run at the end of a scope
template <class F>
class Deferred {
public:
explicit Deferred(F f) noexcept : fn(std::move(f)) {}
Deferred(Deferred&& other) noexcept : fn(std::move(other.fn)), called(std::exchange(other.called, false)) {}
Deferred(const Deferred&) = delete;
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
const char* ssid = "<REDACTED>";
const char* password = "<REDACTED>";
auto port = 80;
ESP8266WebServer server(port);