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 BluebirdPromise from 'bluebird' | |
| import { Readable } from 'node:stream' | |
| // Simulate async operation (e.g., database query) | |
| const asyncOperation = async (item: number): Promise<number> => { | |
| // Simulate I/O delay | |
| await new Promise((resolve) => setTimeout(resolve, 10)) | |
| return item * 2 | |
| } |
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 { useState } from "react"; | |
| let initialCounters = [0, 0, 0]; | |
| export default function CounterList() { | |
| const [counters, setCounters] = useState(initialCounters); | |
| function handleIncrementClick(index: number) { | |
| const nextCounters = counters.map((c, i) => { | |
| if (i === index) { |
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 { useState } from "react"; | |
| let nextId = 3; | |
| interface ArtWork { | |
| id: number; | |
| title: string; | |
| seen: boolean; | |
| } |
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
| package main | |
| import ( | |
| "encoding/base64" | |
| "fmt" | |
| ) | |
| func main() { | |
| secret := "aWFuZ25vVzpOQU06RU5JTDp0YTpzdTpuaW9K" | |
| sd, _ := base64.StdEncoding.DecodeString(secret) |
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 fiboLoop(n) { | |
| let a = 0, b = 1; | |
| if (n == 0) return 0; | |
| for (let i = 2; i < n; i++) { | |
| [a, b] = [b, a + b]; | |
| } | |
| return a + b; | |
| } |
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 {useCallback, useEffect, useState, useSyncExternalStore} from 'react' | |
| function createStore(initialState) { | |
| let state = initialState | |
| const getState = () => state; | |
| const listeners = new Set() | |
| const setState = (fn) => { | |
| state = fn(state) | |
| listeners.forEach((l) => l()) | |
| } |
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
| public class ThreadSafeDemo { | |
| static StringBuilder sb1 = new StringBuilder(); | |
| static StringBuffer sb2 = new StringBuffer(); | |
| public static void main(String[] args) { | |
| int iteration = 10000; | |
| Runnable r = () -> { | |
| for (int i = 0; i < iteration; i++) { | |
| String w = "w"; | |
| sb1.append(w); |
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
| public class StringBufferAndBuilder { | |
| static final long ITERATION = 1_000_000_000L; | |
| public static void main(String[] args) throws Exception { | |
| testStringBuffer(); | |
| testStringBuilder(); | |
| } | |
| public static void testStringBuilder() { |
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
| public class HelloThread extends Thread { | |
| public void run() { | |
| System.out.println("Hello from a thread!"); | |
| } | |
| public static void main(String args[]) { | |
| (new HelloThread()).start(); | |
| } |
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
| public class HelloRunnable implements Runnable { | |
| public void run() { | |
| System.out.println("Hello from a thread!"); | |
| } | |
| public static void main(String args[]) { | |
| (new Thread(new HelloRunnable())).start(); | |
| } |
NewerOlder