Skip to content

Instantly share code, notes, and snippets.

View libsteve's full-sized avatar

Steven Brunwasser libsteve

View GitHub Profile
@libsteve
libsteve / Zip3Sequence.swift
Created April 15, 2018 06:19
An implementation of zip that combines the elements of three sequences.
import Foundation
struct Zip3Sequence<Sequence1, Sequence2, Sequence3>: Sequence
where Sequence1: Sequence, Sequence2: Sequence, Sequence3: Sequence {
typealias Element = Iterator.Element
typealias Iterator = Zip3Iterator<Sequence1.Iterator, Sequence2.Iterator, Sequence3.Iterator>
private var s1: Sequence1
private var s2: Sequence2
private var s3: Sequence3
@libsteve
libsteve / CycleIterator.swift
Created April 17, 2018 04:58
An iterator to endlessly iterate over the same sequence.
struct CycleIterator<Element>: IteratorProtocol, ExpressibleByArrayLiteral {
private var elements: [Element]
private var offset: Int = 0
init(_ elements: [Element]) {
self.elements = elements
}
init(arrayLiteral elements: Element...) {
self.init(elements)

Keybase proof

I hereby claim:

  • I am stevebrun on github.
  • I am sbrun (https://keybase.io/sbrun) on keybase.
  • I have a public key ASDdAuz7l8NXr4dTieWLCCHVHVrxezxED0cYXn5kPvymyAo

To claim this, I am signing this object:

@libsteve
libsteve / slideslive-dl.swift
Last active November 28, 2021 19:38
Download the HOPL IV sessions from SlidesLive
#!/usr/bin/env swift
//
// Copyright 2021 Steven Brunwasser
//
// 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 to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
// Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
@libsteve
libsteve / desktopmode.sh
Last active January 28, 2025 01:51
Launch Steam Desk's "Desktop Mode" from within "Gaming Mode"
#!/bin/bash
#
# Launch Steam Desk's "Desktop Mode" from within "Gaming Mode".
# https://www.reddit.com/r/SteamDeck/comments/wycp1r/comment/ilw1cov/
# https://www.reddit.com/user/FineWolf/
# Friday, August 26, 2022
#
# Commented by Steven Brunwasser
# Sunday, October 23, 2022
#
@libsteve
libsteve / firefox.sh
Last active April 14, 2024 10:18
Launch Firefox from Steam Deck's "Gaming Mode".
#!/bin/bash
##
## Launch Firefox from Steam Deck's "Gaming Mode".
##
## Although it doesn't provide a perfect browsing experience, this script
## at least makes sure that menus and windows appear as they're supposed to.
##
## INSTRUCTIONS:
##
## - Save this file to the ~/.local/bin directory.
@libsteve
libsteve / ConstantClass.m
Last active September 19, 2024 20:25
Compile-time constant classes in Objective-C
//
// ConstantClass.m
//
// An example for how to create compile-time constant Objective-C objects that
// can be assigned to any static const variable.
//
// Compile with -fno-objc-arc to allow overriding of retain/release methods.
//
#import <Foundation/Foundation.h>
@libsteve
libsteve / iexp.c
Last active January 7, 2024 06:24
Get an integer mantissa for floating-point values in C
#include "iexp.h"
#include <float.h>
#include <math.h>
#include <stddef.h>
// https://stackoverflow.com/questions/7812044/finding-trailing-0s-in-a-binary-number/36791297#36791297
// Manually get two's compliment with (~integer + 1) instead of arithmatic
// negation because signed integer representation is implementation-defined
// behavior, so we can't always assume that negative integers are represented
// with two's complement instead of one's complement or signed magnitude.
@libsteve
libsteve / let_if.h
Last active May 5, 2024 15:19
A control-flow construct in C for scoped variable declarations that satisfy a follow-up conditional expression.
//
// let_if.h
//
// A control-flow construct in C for scoped variable declarations that satisfy
// a follow-up conditional expression.
//
// let_if (<declaration>; <condition>) {
// <code-block>
// }
//
@libsteve
libsteve / Toggle Comments in C.md
Created May 12, 2024 21:40
Toggle Comments in C

Toggle Comments in C

There are special combinations of inline and multiline comments in C that you abuse exploit take advantage of utilize to comment out one of two mutually-exclusive code blocks, and then easily swap between them.

Toggling Multiline Comments

In this example, the first main function is compiled, while the second is commented out.