Skip to content

Instantly share code, notes, and snippets.

@ScriptRaccoon
ScriptRaccoon / script.js
Last active January 27, 2024 12:00
Add MIT licenses to all your repos
const TOKEN = "...." // your github access token
const owner = "..." // your github name
const blackList = [] // the names of the repos you don't want to process
const { Octokit } = require("@octokit/rest") // install this first
const octokit = new Octokit({ auth: TOKEN })
const fs = require("fs")
@ScriptRaccoon
ScriptRaccoon / open-discussions.js
Last active October 17, 2023 10:53
Script to open all GitHub discussions in a PR. Continuously clicks on the "Load More" buttons.
const loadmore_condition = (button) => button.innerText.includes('Load more');
const status_element = document.createElement('div');
status_element.innerText = 'Opening conversations ...';
status_element.style =
'position: fixed; z-index: 100; top: 1rem; left: 1rem; background-color: white; color: black; border: 1px solid black; padding: 0.5rem 1rem;';
document.body.appendChild(status_element);
async function open_conversations() {
@ScriptRaccoon
ScriptRaccoon / calendar-script.gs
Last active August 12, 2023 07:50
Google Apps Script that copies Google calendar entries to a Google sheet
/*
This Google script needs to be added to a Google spreadsheet.
It lists all calendar entries within one year (that time range is configurable)
and adds them to the first sheet in the spreadsheet. The script also adds
a button 'Update' in the spreadsheet's UI that executes the main update function.
*/
const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
const sheet = spreadsheet.getSheets()[0];
@ScriptRaccoon
ScriptRaccoon / tuple-type.ts
Created July 7, 2023 11:52
Tuple types in TypeScript with fixed length
type Tuple<Length extends number, T, Accumulator extends T[] = []> =
Accumulator["length"] extends Length ?
Accumulator :
Tuple<Length,T,[...Accumulator,T]>;
const example: Tuple<3,string> = ["hi","mom","!"];
@ScriptRaccoon
ScriptRaccoon / generics.ts
Last active June 30, 2023 19:51
Introduction to Generics
// 1. Example: get last element of any array
function last_element<X>(arr: Array<X>): X {
return arr[arr.length - 1];
}
// 2. Example: get id of an object which has an id
type person = {
name: string;
@ScriptRaccoon
ScriptRaccoon / redis-cached.ts
Created June 14, 2023 23:14
This is a general decorator function that caches the return value of a function for a specified amount of time inside of a redis database.
import type { Redis } from "ioredis";
/**
* This is a general decorator function that caches the
* return value of a function for a specified amount of time
* inside of a redis database. This can be used
* to save responses from API requests, for example.
* Caveat: This function is not typesafe, since we don't know
* which type of data is saved in the redis database.
* @param fun any function (without arguments)
@ScriptRaccoon
ScriptRaccoon / cache.ts
Created June 13, 2023 22:14
Cache decorator function
/**
* This is a general decorator function which caches the
* return value of a function for a specified amount of time.
* This can be used to save responses from API requests for example.
* @param fun any function (without arguments)
* @param duration caching duration in milliseconds
* @returns the function return value when the cache is empty or old, or the cache value
*/
export function cached<T>(fun: () => T, duration: number) {
let date: Date | null = null;
@ScriptRaccoon
ScriptRaccoon / index.html
Created May 12, 2023 06:26
SVG with flipped coordinate system
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>SVG with flipped coordinate system</title>
<style>
body {
font-family: Arial, Helvetica, sans-serif;