Skip to content

Instantly share code, notes, and snippets.

View pastelmind's full-sized avatar
🦀

Yehyoung Kang pastelmind

🦀
View GitHub Profile
@pastelmind
pastelmind / report-local-storage-usage-chrome.js
Last active August 14, 2018 06:27
Get amount of local storage used by Chrome/Firefox WebExtensions
//1. Go to Chrome Extensions page
//2. Activate developer mode
//3. Open the background page of any extension
//4. Paste the following code in the DevTools console
chrome.storage.local.getBytesInUse(null, bytesInUse => {
if (chrome.runtime.lastError)
throw chrome.runtime.lastError;
const bytesAvailable = chrome.storage.local.QUOTA_BYTES - bytesInUse;
@pastelmind
pastelmind / make-test-source.js
Created July 23, 2018 09:19
Test which elements can wrap <details> without breaking in Ruliweb
const fs = require('fs');
const path = require('path');
const wrapperHtml = '<p style="text-align: center">&nbsp;&nbsp;</p>';
const contentHtml = '<details style="border: 1px solid blue; WIDTH: 20em"><summary>Test</summary>The quick brown fox jumps over the lazy dog</details>';
const tags = [
//Inline tags
'a',
@pastelmind
pastelmind / 2.bashrc_additions.sh
Last active February 3, 2022 05:23
My ubuntu server post-setup init script
# Add this to TOP of the .bashrc
# This could also be added to bottom, honestly I have no idea
# Configure __git_ps1 (which we'll use later)
GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWSTASHSTATE=1
GIT_PS1_SHOWUNTRACKEDFILES=1
GIT_PS1_SHOWUPSTREAM="auto"
GIT_PS1_SHOWCOLORHINTS=1
@pastelmind
pastelmind / indexed-collection.js
Last active August 3, 2020 00:41
IndexedCollection implementation in TypeScript/JavaScript
/**
* @license MIT
*
* MIT License
*
* Copyright (c) 2020 Yehyoung Kang
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
@pastelmind
pastelmind / README.md
Last active July 14, 2022 08:22
To use observable or plain JS?

StoreItem 클래스에는 두 개의 값(amount, status)이 있습니다. 한 값을 변경했을 때 다른 값을 함께 변경하고 싶다면 어떻게 하는 게 좋을까요?

  • StoreItemA: setAmount() 내에서 변경한다
  • StoreItemB: Observable을 사용해서 업데이트하자
@pastelmind
pastelmind / history-store.ts
Last active November 30, 2023 05:00
Simple Valtio history store (alternative to proxyWithHistory)
// Replace ReadonlyDeep with Readonly if you don't want to use type-fest
import type { ReadonlyDeep } from 'type-fest';
import { proxy } from 'valtio';
/**
* Simple history-keeping store with undo/redo.
* You can also subscribe to the history itself
* (which isn't possible with `proxyWithHistory()`).
*/
interface HistoryStore<T extends object> {