Skip to content

Instantly share code, notes, and snippets.

View asci's full-sized avatar
🍊

Artem Riasnianskyi asci

🍊
View GitHub Profile
@asci
asci / fetchHighlightsFromAppleBooks.js
Last active March 29, 2024 12:08
Export Highlights from Apple Books
const fs = require("fs");
const sqlite3 = require("sqlite3");
const glob = require("glob");
const os = require("os");
const { open } = require("sqlite");
const username = os.userInfo().username;
const ANNOTATION_DB_PATH = `/users/${username}/Library/Containers/com.apple.iBooksX/Data/Documents/AEAnnotation/`;
const BOOK_DB_PATH = `/users/${username}/Library/Containers/com.apple.iBooksX/Data/Documents/BKLibrary/`;
const annotationsFiles = glob.sync(`${ANNOTATION_DB_PATH}/*.sqlite`);
@asci
asci / merged.sh
Created November 19, 2021 10:29
Get list of PRs merged in a timeframe
gh pr list --state merged --json mergedAt,title,url --limit 100 | jq --arg s $1 --arg e $2 '
[($s, $e) | strptime("%Y-%m-%d")[0:3]] as $r
| map(select(
(.mergedAt[:19] | strptime("%Y-%m-%dT%H:%M:%S")[0:3]) as $d
| $d >= $r[0] and $d <= $r[1]
))
'
@asci
asci / scrollYPosition.js
Last active November 18, 2021 16:00
Setting scroll progress to CSS variable
(() => {
const rootStyle = document.querySelector(":root").style;
const scrollMaxY = window.scrollMaxY || (document.documentElement.scrollHeight - document.documentElement.clientHeight);
rootStyle.setProperty("--scroll-y-max-position", scrollMaxY)
rootStyle.setProperty("--scroll-y-position", window.scrollY)
rootStyle.setProperty("--scroll-y-progress", scrollMaxY ? window.scrollY / scrollMaxY : 1)
document.addEventListener("scroll", () => {
rootStyle.setProperty("--scroll-y-position", window.scrollY)
rootStyle.setProperty("--scroll-y-progress", window.scrollY / scrollMaxY)
})
@asci
asci / array-as-union.ts
Created April 30, 2021 12:15
Typescript snippets
const fruits = ["apple", "banana", "cherry", "orange"] as const
type Fruit = typeof fruits[number]
const myFruit: Fruit = "cherry"
function isFruit(some: unknown): some is Fruit {
return fruits.includes(some as any)
}
@asci
asci / Makefile
Last active May 8, 2021 09:14
Web App Setup
# Defining variables
OUT_DIR := build
BIN := node_modules/.bin
ESBUILD_WATCH :=
define TS_CONFIG
{
"compilerOptions": {
"strict": true,
"module": "commonjs",
@asci
asci / module.js
Created January 19, 2021 09:27
ES module from Data URL
// Async variant
const m = { myModule: undefined }
;(async () => {
const myModule = await import(
URL.createObjectURL(
new Blob(
[
`export let Value = 123
`,
],
@asci
asci / index.rb
Created December 23, 2019 20:52
PotatoSong01
use_bpm 55
live_loop :snare do
sample :bd_haus, pitch: 12
sleep 0.5
end
live_loop :bam do
sleep 0.5
sample :bd_haus
end
@asci
asci / data.ts
Created September 8, 2019 15:17
data
const items = [
{ name: "john", fullname: "John Doe" },
{ name: "batman", fullname: "Bryce Wayne" },
]
@asci
asci / fadeInWhenShown.tsx
Created September 6, 2019 12:48
Framer X Override for component to fade in when appear on screen
import * as React from "react"
import { useState, useEffect, useRef } from "react"
import { Override, motion } from "framer"
// Override
export function OnScreen(props): Override {
const ref = useRef()
const [wasShown, setWasShown] = useState(false)
const onScreen = useOnScreen(ref)
@asci
asci / init.sh
Last active June 30, 2019 10:10
React TS kit 2019
yarn add @types/react @types/react-dom html-webpack-plugin ts-loader typescript webpack webpack-cli webpack-dev-server --dev