This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { deflate, inflate } from "pako"; | |
| // import { fromUint8Array, toUint8Array } from 'js-base64'; | |
| interface Serde { | |
| serialize: (state: string) => string; | |
| deserialize: (state: string) => string; | |
| } | |
| const fromUint8Array = (u8a: Uint8Array) => { | |
| const maxargs = 0x10_00; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface HashPasswordParams { | |
| password: string; | |
| providedSalt?: Uint8Array; | |
| } | |
| async function hashPassword({ password, providedSalt }: HashPasswordParams) { | |
| const encoder = new TextEncoder(); | |
| const salt = providedSalt || crypto.getRandomValues(new Uint8Array(16)); | |
| const keyMaterial = await crypto.subtle.importKey( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // /utils/result.ts | |
| export type Failure<E> = { | |
| success: false; | |
| error: E; | |
| }; | |
| function Failure<E>(error: E): Failure<E> { | |
| return { | |
| success: false, | |
| error, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use client'; | |
| import * as React from 'react'; | |
| import { Input } from '@/components/ui/input'; | |
| import { Button } from '@/components/ui/button'; | |
| import { | |
| AlertDialog, | |
| AlertDialogContent, | |
| AlertDialogHeader, | |
| AlertDialogTitle, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| javascript:(function()%7Bfunction%20getSelectedText()%20%7B%0A%20%20if%20(typeof%20window.getSelection%20!%3D%20'undefined')%20%7B%0A%20%20%20%20return%20window.getSelection().toString()%3B%0A%20%20%7D%20else%20if%20(typeof%20document.selection%20!%3D%20'undefined'%20%26%26%20document.selection.type%20%3D%3D%20'Text')%20%7B%0A%20%20%20%20return%20document.selection.createRange().text%3B%0A%20%20%7D%0A%20%20return%20''%3B%0A%7D%0A%0Afunction%20doSomethingWithSelectedText(event)%20%7B%0A%20%20event.stopPropagation()%3B%0A%20%20const%20selectedText%20%3D%20getSelectedText()%3B%0A%20%20if%20(selectedText)%20%7B%0A%20%20%20%20doTranslate(selectedText)%3B%0A%20%20%7D%0A%7D%0Adocument.onmouseup%20%3D%20doSomethingWithSelectedText%3B%0Adocument.onkeyup%20%3D%20doSomethingWithSelectedText%3B%0A%0Aasync%20function%20doTranslate(selectedText)%20%7B%0A%20%20const%20res%20%3D%20await%20fetch(%0A%20%20%20%20%60https%3A%2F%2Ftranslate.googleapis.com%2Ftranslate_a%2Fsingle%3Fclient%3Dgtx%26sl%3Den%26tl%3Dvi%26hl%3Den-US%26dt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [user] | |
| name = Pavan Kumar Sunkara | |
| email = [email protected] | |
| username = pksunkara | |
| [init] | |
| defaultBranch = master | |
| [core] | |
| editor = nvim | |
| whitespace = fix,-indent-with-non-tab,trailing-space,cr-at-eol | |
| pager = delta |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [ | |
| { | |
| "type": "folder", | |
| "addDate": 1718526477999, | |
| "title": "Bookmarks Bar", | |
| "children": [ | |
| { | |
| "type": "link", | |
| "addDate": 1718526687700, | |
| "title": "Google", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useSyncExternalStore } from "react"; | |
| // For more on the useSyncExternalStore hook, see https://react.dev/reference/react/useSyncExternalStore | |
| // The code is almost identical to the source code of zustand, without types and some features stripped out. | |
| // Check the links to see the references in the source code. | |
| // The links are referencing the v5 of the library. If you plan on reading the source code yourself v5 is the best way to start. | |
| // The current v4 version contains lot of deprecated code and extra stuff that makes it hard to reason about if you're new to this. | |
| // https://github.com/pmndrs/zustand/blob/fe47d3e6c6671dbfb9856fda52cb5a3a855d97a6/src/vanilla.ts#L57-L94 | |
| function createStore(createState) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function countShips(B) { | |
| const result = [0, 0, 0]; | |
| const map = B.map(row=>row.split('')); | |
| const n = map.length; | |
| const m = map[0].length; | |
| for (let row = 0; row < n; row++) { | |
| for (let col = 0; col < m; col++) { | |
| if (map[row][col] === '#') { | |
| map[row][col] = '.'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Service-worker demo</title> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <script> | |
| if ( "serviceWorker" in navigator ) { |
NewerOlder