Skip to content

Instantly share code, notes, and snippets.

View seanbecker15's full-sized avatar
🤌
Probably making pasta

Sean Becker seanbecker15

🤌
Probably making pasta
View GitHub Profile
@seanbecker15
seanbecker15 / lg-wake-on-lan.js
Created June 21, 2024 17:25
NodeJS Script to Wake LG on LAN
import dgram from "dgram";
const IP = "192.168.X.X";
const PORT = "9922";
const MAC = "XX:XX:XX:XX:XX:XX";
let sanitizedMac = MAC;
// remove filling from MAC
const CharsToRemove = ["\\.", ":", "-"];
for (let j = 0; j < CharsToRemove.length; j++) {
@seanbecker15
seanbecker15 / chat-gpt-text-completion.tsx
Created December 3, 2023 23:37
Chat-GPT Style Completion Using SSE Streaming API
// Read blog here: https://seanbecker.me/posts/chatgpt-text-completion
import { ChangeEvent, useState } from "react";
import { createParser, ParsedEvent, ReconnectInterval } from "eventsource-parser";
// Assumes that you can already fetch a completion from OpenAI
import { fetchCompletion } from "./api";
// Convert the stream to an async iterator.
// Found here https://jakearchibald.com/2017/async-iterators-and-generators/#making-streams-iterate
@seanbecker15
seanbecker15 / pre-merge-cleanup.md
Last active May 25, 2023 22:33
Cleaning up branches before merging

Overview

Cleaning up branches before merging code on a team can be non-trivial. The goal of this gist is to discuss some of the common scenarios that occur as we are cleaning up our branch in preparation to merge.

Scenarios

Forked off of a branch that was squash merged

In this scenario, imagine that we start with 2 branches: main and a. Branch a has several commits that are not yet in main. We branch off of a to create branch b. Branch a is squash merged into main, leaving b with several commits that no longer need to be merged. When we are ready to merge b, how do we avoid merging all of these commits?

  1. Squash merge b
    • When people review the PR, they will see all of the commits from a while reviewing. This leads to a less than desirable code review experience.
  • Looking at the history of branch b in the future will be quite confusing.
@seanbecker15
seanbecker15 / cherry-pick-range.sh
Created May 25, 2023 22:04
Cherry pick a range of commits
# This command allows you to cherry-pick a range of commits from sha1 (inclusive) to sha2 (inclusive).
# Finding the commit shas can be done using `glog`, `git log`, or by clicking on the history of a branch in github.
git cherry-pick $(git log sha1^..sha2 --reverse --pretty=format:"%h")
# Explanation of this command
# - The caret (^) indicates that we want to include sha1 in our output.
# - `git log` normally outputs commits from most recent to oldest, so --reverse is used to preserve commit order.
# - `--pretty=format:"%h"` indicates that we only want to display commit shas (and no other information).