Skip to content

Instantly share code, notes, and snippets.

View MariusBongarts's full-sized avatar

Marius Bongarts MariusBongarts

View GitHub Profile
type LabeledTuple = [first: string, second: string];
@MariusBongarts
MariusBongarts / read-file.ts
Last active August 2, 2023 06:21
Read file with new "using" keyword
import fs from "fs/promises";
const getFileResource = async (path: string) => {
const fileResource = await fs.open(path, "r");
return {
fileResource,
[Symbol.asyncDispose]: async () => {
await fileResource?.close();
console.log("Cleanup done");
},
@MariusBongarts
MariusBongarts / read-file.ts
Last active August 2, 2023 06:20
Node file reading (old)
(async () => {
let fileResource;
try {
fileResource = await fs.open("file.txt", "r");
// Do stuff with fileResource
} finally {
await fileResource?.close();
console.log("Cleanup done");
}
})();
@MariusBongarts
MariusBongarts / index.ts
Last active July 31, 2023 07:45
Using keyword example
{
const getResource = () => {
return {
[Symbol.dispose]: () => {
console.log('Clean up done!')
}
}
}
using resource = getResource();
} // 'Clean up done!' logged to console because `resource` left the scope
@MariusBongarts
MariusBongarts / stabilo-colors.md
Last active March 24, 2024 14:32
stabilo-colors.md

NEON COLORS:

  • Neon Orange: #ffad2a (RGB: 255, 173, 42) Neon Orange
  • Neon Red: #f887f (RGB: 248, 135, 127) Neon Red
  • Neon Yellow: #f8fc46 (RGB: 248, 252, 70) Neon Yellow
  • Neon Green: #77e68a (RGB: 119, 230, 138) Neon Green
  • Olive Green: #00c87a (RGB: 0, 200, 122) Olive Green
  • Neon Blue: #3cbefc (RGB: 60, 190, 252) Neon Blue
  • Neon Violet: #9d64e2 (RGB: 157, 100, 226) Neon Violet
  • Neon Pink: #fb83b3 (RGB: 251, 131, 179) Neon Pink
  • Lilac: #f447d1 (RGB: 244, 71, 209) Lilac
type HistoryItem = chrome.history.HistoryItem;
export const useChromeHistorySearch = (
query: chrome.history.HistoryQuery
): HistoryItem[] => {
const [historyItems, setHistoryItems] = useState<HistoryItem[]>([]);
useEffect(() => {
chrome.history
.search(query)
.then((historyItems) => setHistoryItems(historyItems))
.catch(() => setHistoryItems([]));
import React from "react";
import { truncateString, urlWithoutSchema } from "../services/helper";
import {
StyledInfo,
StyledHistoryItem,
StyledItemLink,
StyledTitle,
StyledTime,
} from "./HistoryItem.styled";
export const StyledInfo = styled.div`
flex: 1;
display: flex;
flex-wrap: wrap;
row-gap: 2px;
padding: 4px;
`;
export const StyledItemLink = styled.a`
color: var(--light-grey);
import React from "react";
import { truncateString, urlWithoutSchema } from "../services/helper";
import {
StyledInfo,
StyledHistoryItem,
StyledItemLink,
StyledTitle,
StyledTime,
} from "./HistoryItem.styled";
useEffect(() => {
chrome.history.search({ text: "", maxResults: 10 }, (data) => {
console.log(data);
});
}, []);