Skip to content

Instantly share code, notes, and snippets.

View xinmyname's full-sized avatar

Andy Sherwood xinmyname

View GitHub Profile
@xinmyname
xinmyname / fastmidpoint.c
Created December 7, 2022 16:35
Fast integer midpoint
int MidRoundUp(int x, int y) {
return (x | y) - ((x ^ y) >> 1);
}
int MidRoundDown(int x, int y) {
return ((x ^ y) >> 1) + (x & y);
}
/* Source: https://lemire.me/blog/2022/12/06/fast-midpoint-between-two-integers-without-overflow/ */
@xinmyname
xinmyname / coalesce-args.psm1
Created August 8, 2022 17:14
Coalesce PowerShell arguments
function Coalesce-Args {
$result = $null
foreach($arg in $args) {
if ($arg -is [ScriptBlock]) {
$result = & $arg
} else {
$result = $arg
}
if ($result) { break }
}
@xinmyname
xinmyname / unloadadobe.sh
Created January 2, 2022 00:27
Remove Adobe Creative Cloud from launchctl so it won't consume your entire CPU
#!/bin/sh
launchctl unload -w /Library/LaunchAgents/com.adobe.AdobeCreativeCloud.plist
launchctl unload -w /Library/LaunchAgents/com.adobe.ccxprocess.plist
@xinmyname
xinmyname / Kind.swift
Created March 14, 2020 19:42
Enums in Swift
public enum Kind:Int,CustomStringConvertible {
case weapon
case armor
case scroll
case wand
case potion
case ring
public var description:String {

Keybase proof

I hereby claim:

  • I am xinmyname on github.
  • I am xinmyname (https://keybase.io/xinmyname) on keybase.
  • I have a public key ASAoRTJxA5nTit-WADlMp2pUsUXFriwojaWW4YyvcuDBRwo

To claim this, I am signing this object:

@xinmyname
xinmyname / profile.ps1
Created October 7, 2019 15:52
Launch Code
# Launches code correctly, without cmd.exe so it works with UNC paths
function LaunchCode {
PowerShell -Command "& 'C:\Users\sherwooda\AppData\Local\Programs\Microsoft VS Code\Code.exe' $args"
}
New-Alias e LaunchCode
@xinmyname
xinmyname / MessageQueueFactory.cs
Last active April 12, 2018 13:33
MessageQueue extensions for C# that are generic, thread-safe, cancellable and can be timed out.
using System;
using System.Linq;
using System.Messaging;
using System.Threading;
using System.Threading.Tasks;
namespace MessageCore
{
public static class MessageQueueFactory
{
@xinmyname
xinmyname / ProtoBufStreamExtensions.cs
Created April 3, 2018 21:36
C# Stream Extensions for reading/writing protocol buffers
using System;
using System.IO;
using Google.Protobuf;
namespace ProtoCore
{
public static class StreamExtensions
{
public static void Write(this Stream stream, IMessage message)
{
@xinmyname
xinmyname / StringSplitter.swift
Created April 1, 2018 15:52
Split and replace strings in swift
//: Playground - noun: a place where people can play
import Cocoa
extension String {
//
func splitBetween(_ startText:String, and endText:String) -> [String]? {
guard let startIndex = self.range(of: startText)?.upperBound else {
return nil
@xinmyname
xinmyname / SzechuanSauce.txt
Created October 7, 2017 18:21
Szechuan Sauce from Binging with Babish
Szechuan Sauce
1/2 cup water
1/2 cup white vinegar
1/2 cup sugar
1/2 cup soy sauce
1 tbs apple cider vinegar
1/2 tsp sesame seed oil
1/4 tsp garlic powder
1/4 tsp onion powder