-
-
Save tcodes0/fcd1fac083a9c7f792c70fb49a71177c to your computer and use it in GitHub Desktop.
RTL relay testings | |
https://github.com/facebook/relay/blob/master/packages/relay-test-utils/__tests__/RelayMockEnvironmentWithComponents-test.js | |
https://github.com/entria/entria-fullstack/pull/109/files | |
Very easy native splash screen on Xcode | |
https://medium.com/@kelleyannerose/react-native-ios-splash-screen-in-xcode-bd53b84430ec | |
Init rn app on specific rn version | |
(rn cli 2.0.1+) | |
react-native-cli init --version="[email protected]" my project | |
// correct CRA usage | |
yarn create react-app my-app | |
// mongo regex example | |
db.Event.find({ title: {$regex: new RegExp("tom", "i")} })[0] | |
// rn network debug | |
https://github.com/jhen0409/react-native-debugger/issues/382 | |
``` | |
// add to index.js | |
global.XMLHttpRequest = global.originalXMLHttpRequest || global.XMLHttpRequest; | |
global.FormData = global.originalFormData || global.FormData; | |
if (window.FETCH_SUPPORT) { | |
window.FETCH_SUPPORT.blob = false; | |
} else { | |
global.Blob = global.originalBlob || global.Blob; | |
global.FileReader = global.originalFileReader || global.FileReader; | |
} | |
``` | |
Renato Bohler's tmux config | |
``` | |
set-option -g default-shell /bin/zsh | |
set -g utf8 | |
set-window-option -g utf8 on | |
set -g status off | |
set -g default-terminal "screen-256color" | |
set -g prefix C-a | |
unbind C-b | |
set -sg escape-time 1 | |
set-option -g base-index 1 | |
setw -g pane-base-index 1 | |
bind r source-file ~/.tmux.conf \; display "Reloaded!" | |
bind | split-window -h | |
bind - split-window -v | |
``` | |
// calculate ssh key fingerprint | |
- cat public key, remove leading strings, copy base64payload | |
- echo -n $base64payload | base64 -D | md5 | |
// replaceAtIndex helper | |
export const replaceAtIndex = <Item = any>(array: Item[], index: number, item: Item): Item[] => { | |
return [...array.slice(0, index), item, ...array.slice(index + 1)]; | |
}; | |
export const ONE_SECOND_IN_MILLISECONDS = 1000; | |
export const ONE_MINUTE_IN_MILLISECONDS = 60 * ONE_SECOND_IN_MILLISECONDS; | |
export const ONE_HOUR_IN_MILLISECONDS = 60 * ONE_MINUTE_IN_MILLISECONDS; | |
export const ONE_DAY_IN_MILLISECONDS = 24 * ONE_HOUR_IN_MILLISECONDS; | |
export const SEVEN_DAYS_IN_MILLISECONDS = 7 * ONE_DAY_IN_MILLISECONDS; | |
json to typescript type conversion | |
https://transform.tools/json-to-typescript | |
awesome phone regex | |
https://regex101.com/r/MNWXbW/3 | |
convert salaries between year/hour/month | |
new Array(130).fill(0).map((x, i) => (i+4) * 5000).map(year => ({ year, hour: (year/1920.1755589082431).toFixed(0), month: (year/12).toFixed(0) })) | |
cool thoughts articles tweets ideas | |
https://stopa.io | |
github gif how to | |
![](name-of-giphy.gif) | |
kill branches that have no remotes | |
```bash | |
git branch -vv | grep ': gone]'| grep -v "\*" | awk '{ print $1; }' | xargs -r git branch -D | |
``` | |
twitter bot translation google translate npm library | |
https://github.com/vitalets/google-translate-api | |
how to grep git source code | |
``` | |
git grep <regexp> $(git rev-list --all) | |
``` | |
how to grep git commit msg | |
``` | |
<your fav git log alias> --grep="foo" | |
``` | |
git push a few commits to origin | |
``` | |
git push origin 91143c3:fix-52-2 | |
``` | |
where 91143c3 is the last commit you want to push, and fix-52-2 is the branch on origin to push to. | |
this actually pushes all child commits of 91143c3 to origin because commits are chained together. | |
so, if you'd like to push a range, push the head commit with this technique. | |
when doing complex stuff, find the simples code that works and build from there |
Typescript
extract type from relay type
type FragmentRefs<T extends string> = T
type FeedList_query = {
readonly posts: {
readonly endCursorOffset: number;
readonly startCursorOffset: number;
readonly count: number | null;
readonly pageInfo: {
readonly hasNextPage: boolean;
readonly hasPreviousPage: boolean;
readonly startCursor: string | null;
readonly endCursor: string | null;
};
readonly edges: ReadonlyArray<{
readonly node: {
readonly id: string;
readonly " $fragmentRefs": FragmentRefs<"Post_post">;
} | null;
} | null>;
};
readonly me: {
readonly " $fragmentRefs": FragmentRefs<"Post_me">;
} | null;
readonly " $refType": "FeedList_query";
};
type ExtractNode<T extends {edges: any}> = NonNullable<NonNullable<T['edges'][number]>['node']>
type Post = ExtractNode<FeedList_query['posts']>
tsconfig.json typeroots needs to manually add node_modules/@types, like a default that is lost when you specify manually another path
"typeRoots": ["src/types", "node_modules/@types"]
https://stackoverflow.com/questions/39040108/import-class-in-definition-file-d-ts
ambinet vs local type declarations and different syntax to import in them
declare module 'repl.history' {
// import some types from node
type AddHistory = (repl: import('repl').REPLServer, file: import('fs').PathLike) => void
declare const def: AddHistory
export default def
}
type Primitive =
| string
| boolean
| number
| bigint
| symbol
| null
| undefined;
type object = any non primitive.
Sql and psql with docker
connect to posgress using psql inside docker
sudo docker-compose exec postgres psql -U postgres -d hub
describe table
\d table
connect to db
\c
quit
\q
list all tables
\dt
list all dbs
\l
delete row
DELETE FROM table_name WHERE condition;
clone db
create database new_database_name (Name of new database which we have cloning from another database) WITH TEMPLATE old_database_name
kill off containers and volumes using docker-compose
docker-compose down --rmi all -v
if fail, you may need to docker ps -a
and remove any images that errored with docker rm <image id>
dump docker dp to local file
sudo docker-compose exec postgres pg_dump -h localhost -U "postgres" "hub" --format plain > "hub.dump.sql"
to restore
psql -d hub -f hub.dump.sql
docker cp from container to local fs
use sudo docker cp 5810d91ee2e5:/out.txt $PWD/out.txt
where
postgres is the container for docker-compose, and 5810d91ee2e5 is the container for docker
5810d91ee2e5
is from sudo docker ps
/out.txt
is from sudo docker-compose exec postgres pwd
which replies with /
and out.txt
is the file I want. exec postgres ls
also works btw!
docker nuke
removecontainers() {
docker stop $(docker ps -aq)
docker rm $(docker ps -aq)
}
armageddon() {
removecontainers
docker network prune -f
docker rmi -f $(docker images --filter dangling=true -qa)
docker volume rm $(docker volume ls --filter dangling=true -q)
docker rmi -f $(docker images -qa)
}
postgres
-- seq error fix
SELECT MAX(the_primary_key) FROM the_table;
SELECT nextval('the_primary_key_sequence');
-- nextval needs to be hight than tha table
SELECT setval('the_primary_key_sequence', (SELECT MAX(the_primary_key) FROM the_table)+1);
-- just getting the value fixes, or set it with setval
-- drop all tables quickly
DROP SCHEMA public CASCADE;
CREATE SCHEMA public;
GRANT ALL ON SCHEMA public TO postgres;
GRANT ALL ON SCHEMA public TO public;
psql
psql -U postgres -d db-name-here
\dt
to list definitions
psql -U hub-server -W -d hub -h /home/vacation/eleanor_sql_sockets/ele-qa-436057:us-east1:eleanor-postgres
-U user
-W prompt pass
-d dbname
-h host/socket
column information
SELECT column_name, is_nullable, data_type, column_default FROM information_schema.columns WHERE table_name = 'foo';
postgres upgrade
systemctl stop postgresql
sudo -i
mv /var/lib/postgres/data /var/lib/postgres/olddata
mkdir /var/lib/postgres/data /var/lib/postgres/tmp
chown postgres:postgres /var/lib/postgres/data /var/lib/postgres/tmp
exit
sudo -iu postgres
cd /var/lib/postgres/tmp
initdb -D /var/lib/postgres/data --encoding=UTF8
# it is the old version upgrading from, ls /opt might reveal it
pg_upgrade -b /opt/pgsql-14/bin -B /usr/bin -d /var/lib/postgres/olddata -D /var/lib/postgres/data
exit
systemctl start postgresql
# 6 is number of cores
sudo -u postgres vacuumdb --all --analyze-in-stages --jobs=6
echo echoing cleanup commands
echo sudo -i
echo rm -fr /var/lib/postgres/olddata
echo rm -fr /var/lib/postgres/tmp
echo exit
x-work
get list from website
// do not use really sucks. need to concat with paragraphs and titles
re = []
sel = ".JobOpeningListItem_JobDescription__1DPoi''
document.querySelectorAll(sel).forEach(x => re.push(x.innerText))
('vaga: ' + re.join('\n\n vaga: ')).replace(/Learn more >>/g, '')
// real dolar
var makeBrlToUsd = rate => brl => Math.round(brl*rate)
High level
speed
In posts talking about how someone made something fast, I see the same idea repeat time after time: it has linear time complexity, has great cache locality, and saturates all available processors.
Interview questions
technical, high-level
How do you handle the diversity of patterns within the JS ecosystem? maybe follow-up: What are some good solutions or patterns you have used that worked for you?
What's your thoughts on JS itself and it's current direction?
execution and team work
Have you worked with designers? what were some highlights there?
We all know it's very hard to give estimates, how to do you approach that? what's your attitude?
What is a big mistake in product process you've seen or committed yourself?
Your favorite meeting and why?
Tell me a good idea for a project that your company should take on, but will not. Explain from both sides, even if they are wrong.
Walk me through a project you enjoyed start to finish. Explain design decisions (why x and not y?)
code review
https://www.michaelagreiler.com/respectful-constructive-code-review-feedback/
https://phauer.com/2018/code-review-guidelines/
https://mtlynch.io/code-review-love/
Datadog
APM traces
query samples
Service:hub-server @url:*drivers-license*
trace_id:2934837843
tricks
search for logs using kubectl, find trace id, then do https://app.datadoghq.com/apm/trace/{id}
if code looks like this
infra.Logger.Info().Str("event", "message.new")
query to find field would be @event:message.new
RUM custom actions
find with @action.target.name:foobar
Cookie cliker
// node
prestigeLvls = Math.cbrt((allTimeCookies + popingWrinklers + sellingBuildings + difference) * 10 ** 18 /* 18 for quintilion cookies*/)/10000
// load cookie monster into cookie clicker
Game.LoadMod('https://cookiemonsterteam.github.io/CookieMonster/dist/CookieMonster.js');
Go
Installing private repos as packages
update ~/.gitconfig
with
[url "ssh://[email protected]/"]
insteadOf = https://github.com/
run go env -w GOPRIVATE=github.com/eleanorhealth/*
and add to shell init file export GOPRIVATE=github.com/eleanorhealth/*
run ssh-keyscan github.com > ~/.ssh/known_hosts
try to run go mod download "github.com/eleanorhealth/member-server@<latest commit on main>"
and see if you get no errors, if so, run go get "github.com/eleanorhealth/member-server@<latest commit on main>"
to add the package
notes
omitting the commit hash doesn't work
ssh-key add may be needed on mac, it will prompt you for password
code must be merged to main
coverage unit
go get golang.org/x/tools/cmd/cover
go test -race -coverprofile .coverage ./svc/server/application/application/...
go tool cover -html=.coverage
/**
* Maybe captures the result of some operation that may fail.
* If there is an non null error, attempting to retrieve result will throw.
*/
export class Maybe<T> {
#result: T | null
#error: Error | null
// constructor(data: Data | null, error: Error | null) {
constructor() {
this.#result = null
this.#error = null
}
/**
* throws unless error() returns null.
*/
result(): T {
if (this.#error) {
throw this.#error
}
if (this.#result === null) {
throw new Error("null data")
}
return this.#result
}
/**
* if null, result() is safe to call
*/
error() {
return this.#error
}
/**
* error must be null for result to be read
*/
setResult(data: T) {
this.#result = data
}
/**
* blocks result from being read
*/
setError(message: string) {
this.#error = new Error(message)
}
}
AI
52.7k words on member-server codebase
244 non mock non test files
find . -type f -name *.go | grep -Ev test.go | grep -Ev mock
avg 314 words per file (handlers)
avg 215 word per file (codebase)
say 5k words for a massive conversation context with ai
have 59k words of context to use with ai
Infra
AWS
samples
https://github.com/aws-samples
cdk
https://github.com/aws-samples/aws-cdk-examples/tree/master/typescript
K8S
exec command in pod
psql
get secrets
k8s scheduling/cron scheduling syntax helper comment
k8s jobs and crons
# job from cron kubectl create job --from=cronjob/hub-server-sync-athena-ticklers my-job
gcloud install
link
plugin update
gcloud components install gke-gcloud-auth-plugin export USE_GKE_GCLOUD_AUTH_PLUGIN=True gcloud components update gcloud --project=ele-qa-436057 container clusters --region=us-east1 get-credentials cluster
pod details
kubectl get pod hub-server-insurance-cleanup-4wb86-9nw44 --output=yaml