Skip to content

Instantly share code, notes, and snippets.

View kanglicheng's full-sized avatar
🦜
LLMs ftw

Kang-Li (Stephen) Cheng kanglicheng

🦜
LLMs ftw
View GitHub Profile
@slikts
slikts / advanced-memo.md
Last active February 25, 2025 15:19
Advanced memoization and effects in React

nelabs.dev

Advanced memoization and effects in React

Memoization is a somewhat fraught topic in the React world, meaning that it's easy to go wrong with it, for example, by [making memo() do nothing][memo-pitfall] by passing in children to a component. The general advice is to avoid memoization until the profiler tells you to optimize, but not all use cases are general, and even in the general use case you can find tricky nuances.

Discussing this topic requires some groundwork about the technical terms, and I'm placing these in once place so that it's easy to skim and skip over:

  • Memoization means caching the output based on the input; in the case of functions, it means caching the return value based on the arguments.
  • Values and references are unfortunately overloaded terms that can refer to the low-level implementation details of assignments in a language like C++, for example, or to memory
@kanglicheng
kanglicheng / amazon.md
Created January 15, 2020 06:22 — forked from terabyte/amazon.md
Amazon's Build System

Prologue

I wrote this answer on stackexchange, here: https://stackoverflow.com/posts/12597919/

It was wrongly deleted for containing "proprietary information" years later. I think that's bullshit so I am posting it here. Come at me.

The Question

Amazon is a SOA system with 100s of services (or so says Amazon Chief Technology Officer Werner Vogels). How do they handle build and release?

@mszymczyk
mszymczyk / aligned_allocator.cpp
Created January 6, 2020 04:16 — forked from donny-dont/aligned_allocator.cpp
An aligned allocator for placing SIMD types in std::vector
#ifdef _WIN32
#include <malloc.h>
#endif
#include <cstdint>
#include <vector>
#include <iostream>
/**
* Allocator for aligned data.
@yitonghe00
yitonghe00 / 1192. Critical Connections in a Network (#1 DFS).java
Last active January 21, 2021 21:29
1192. Critical Connections in a Network (https://leetcode.com/problems/critical-connections-in-a-network/): There are n servers numbered from 0 to n-1 connected by undirected server-to-server connections forming a network where connections[i] = [a, b] represents a connection between servers a and b. Any server can reach any other server directly…
// DFS solution: Tarjan's algorithm
// Refer: https://www.youtube.com/watch?time_continue=771&v=aZXi1unBdJA&feature=emb_title
// Time: O(V + E), 110ms
// Space: O(V + E), 123.4mb
class Solution {
boolean[] visited; // Whether we visited this node before
List<Integer>[] graph; // Adjacent list of the graph
int[] low; // Low value of this node: lowest id this node can reach
int[] ids; // Id of this node
int id; // Current id
@jfo
jfo / foo.diff
Created October 18, 2019 11:55
commit cb1d8f6be35aa0eca9534a979aa1f1f09641f760
Author: Jakob Nielsen <[email protected]>
Date: Fri Oct 18 12:26:32 2019 +0200
Update diversity inclusion questions (#41)
* Update diversity inclusion questions
* release 5.5.1-rc.1 [ci skip]
@rylev
rylev / rust-in-large-organizations-notes.md
Last active June 12, 2025 16:06
Rust in Large Organizations Notes

Rust in Large Organizations

Initially taken by Niko Matsakis and lightly edited by Ryan Levick

Agenda

  • Introductions
  • Cargo inside large build systems
  • FFI
  • Foundations and financial support
@sushant-jadhav
sushant-jadhav / sectionlistview.js
Created July 31, 2019 07:36
Section List View in React Native application with react native elements and react native paper packages
import React, {Fragment,Component} from 'react';
import {
SafeAreaView,
StyleSheet,
ScrollView,
View,
Text,
SectionList,
FlatList,
ActivityIndicator,
@celliott181
celliott181 / todo-list.html
Last active January 5, 2023 05:17
VanillaJS To Do App using LocalStorage to persist data
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>To Do</title>
<style>
body {
font-size: 1rem;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
class Solution:
def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
output= []
self.gen_subsets(sorted(nums),0,[],output)
return output
def gen_subsets(self,a,i,sofar,output):
n = len(a)
if i==n: