Skip to content

Instantly share code, notes, and snippets.

@JayPeet
JayPeet / OpenAI_Nginx_DenyList
Created September 4, 2024 20:48
Nginx OpenAI Deny List
# IPs taken from:
# https://openai.com/searchbot.json
# https://openai.com/chatgpt-user.json
# https://openai.com/gptbot.json
# And presumably could change.
location /
{
#deny OAI-SearchBot
deny 20.42.10.176/28;
@okikio
okikio / constrain-transform-stream-queues.md
Created September 1, 2024 03:21
Queue's via TransformStreams

Using TransformStream in place of traditional queue implementations is an interesting approach that leverages the stream API's natural queuing and backpressure features. Below is a breakdown of how you might implement each queue type using TransformStream, adhering to the constraint of using no more than 2 TransformStreams per queue, and addressing any limitations that arise.

1. Simple Queue (FIFO Queue)

  • Implementation:
    • TransformStream 1: This stream simply passes data from the writable side to the readable side in FIFO order.
    • TransformStream 2: Not necessary in this case, as one TransformStream is sufficient to maintain the FIFO order.
const fifoQueue = new TransformStream({
transform(chunk, controller) {
@hanxiao
hanxiao / testRegex.js
Last active November 18, 2024 06:50
Regex for chunking by using all semantic cues
// Updated: Aug. 20, 2024
// Run: node testRegex.js whatever.txt
// Live demo: https://jina.ai/tokenizer
// LICENSE: Apache-2.0 (https://www.apache.org/licenses/LICENSE-2.0)
// COPYRIGHT: Jina AI
const fs = require('fs');
const util = require('util');
// Define variables for magic numbers
const MAX_HEADING_LENGTH = 7;
@astuyve
astuyve / deny_snippet.json
Created January 17, 2024 15:00
Deny cloudwatch permissions from Lambda to save money
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Deny",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
@mitchellh
mitchellh / merge_vs_rebase_vs_squash.md
Last active November 18, 2024 22:48
Merge vs. Rebase vs. Squash

I get asked pretty regularly what my opinion is on merge commits vs rebasing vs squashing. I've typed up this response so many times that I've decided to just put it in a gist so I can reference it whenever it comes up again.

I use merge, squash, rebase all situationally. I believe they all have their merits but their usage depends on the context. I think anyone who says any particular strategy is the right answer 100% of the time is wrong, but I think there is considerable acceptable leeway in when you use each. What follows is my personal and professional opinion:

class PathMe {
moves: string[] = [];
constructor() {
this.moves = [];
return this;
}
moveTo(x: number, y: number) {
@shanecelis
shanecelis / DragManipulator.cs
Last active October 4, 2024 09:18
This manipulator makes a visual element draggable at runtime in Unity's UIToolkit.
/* Original code[1] Copyright (c) 2022 Shane Celis[2]
Licensed under the MIT License[3]
[1]: https://gist.github.com/shanecelis/b6fb3fe8ed5356be1a3aeeb9e7d2c145
[2]: https://twitter.com/shanecelis
[3]: https://opensource.org/licenses/MIT
*/
using UnityEngine;
using UnityEngine.UIElements;
@shanecelis
shanecelis / ChildAnnotator.cs
Last active October 30, 2024 20:14
Fake CSS pseudo classes :first-child and :last-child in Unity's UIToolkit with regular USS classes .first-child and .last-child.
/* Original code[1] Copyright (c) 2022 Shane Celis[1]
Licensed under the MIT License[1]
[1]: https://gist.github.com/shanecelis/1ab175c46313da401138ccacceeb0c90
[1]: https://twitter.com/shanecelis
[1]: https://opensource.org/licenses/MIT
*/
using UnityEngine.Scripting;
using UnityEngine.UIElements;
@alexanderameye
alexanderameye / SceneSwitcherToolbarOverlay.cs
Last active December 1, 2023 22:37
A small scene switcher utility for Unity
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEditor.Overlays;
using UnityEditor.SceneManagement;
using UnityEditor.Toolbars;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UIElements;
@staggartcreations
staggartcreations / GlobalShaderParams.cs
Last active January 18, 2024 08:40
Component for passing values through Shader.SetGlobalXXX
using System;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
[ExecuteInEditMode]
public class GlobalShaderParams : MonoBehaviour
{