├── .gitignore ├── All ├── APIS │ ├── Chatwoot.md │ ├── Daily.md │ ├── DuckDuckGo.md │ ├── Facebook.md │ ├── Google.md │ ├── Intercom.md │ ├── Mux.md │ ├── OpenAI.md │ ├── README.md │ ├── Reddit.md │ ├── Segment.md │ ├── Sendgrid.md │ ├── Sentry.md │ ├── Spotify.md │ ├── Stripe.md │ ├── Transloadit.md │ └── Zendesk.md ├── Bash │ ├── IO.md │ ├── Kill.md │ ├── Makefile.md │ ├── README.md │ ├── awk.md │ ├── bash_profile.md │ ├── cron.md │ ├── curl.md │ ├── diff.md │ ├── emacs.md │ ├── find.md │ ├── general.md │ ├── git.md │ ├── grep.md │ ├── installed │ │ ├── asdf.md │ │ ├── bit.md │ │ ├── ffmpeg.md │ │ ├── generact.md │ │ ├── graphite.md │ │ ├── ngrok.md │ │ ├── nvm.md │ │ ├── spell.md │ │ └── tmux.md │ ├── man.md │ ├── metadata.md │ ├── sed.md │ ├── sftp.md │ ├── ssh.md │ ├── vi.md │ ├── zip.md │ └── zsh.md ├── C++ │ └── ptrs.md ├── CS_Fundamentals │ ├── Authentication.md │ ├── Comparisons.md │ ├── Concurrency.md │ ├── Content_Security_Policy.md │ ├── Data_Structures.md │ ├── Editors.md │ ├── Email.md │ ├── Encryption.md │ ├── ErrorHandling.md │ ├── FeatureFlags.md │ ├── HTTP.md │ ├── IDs.md │ ├── LanguageTypes.md │ ├── Microservices.md │ ├── Optimization.md │ ├── Password_Hashing.md │ ├── RTMP.md │ ├── Real-Time.md │ ├── Sorting.md │ ├── StoringSecrets.md │ ├── Testing.md │ ├── WebRTC.md │ └── Webhook.md ├── Databases │ ├── README.md │ ├── SQL │ │ ├── README.md │ │ ├── aggregate.md │ │ ├── foreign_keys.md │ │ ├── joins.md │ │ ├── optimizations.md │ │ └── sqllite.md │ ├── advanced.md │ ├── design.md │ ├── firebase.md │ ├── hosts.md │ ├── libs.md │ ├── mongo.md │ ├── mongo_aggregation.md │ ├── opensearch.md │ ├── postgres.md │ ├── postgres_setup.md │ ├── redis.md │ └── tips.md ├── Dev_Apps │ ├── atom.md │ ├── iterm2.md │ ├── matlab.md │ ├── notion.md │ ├── retool.md │ ├── slack.md │ ├── tableplus.md │ ├── vimium.md │ ├── vscode.md │ ├── warp.md │ └── windows.md ├── Docker │ ├── README.md │ ├── basics.md │ ├── docker-compose.md │ ├── dockerfile.md │ ├── multistage.md │ └── swarm.md ├── Elixir │ ├── OTP.md │ ├── Phoenix │ │ ├── README.md │ │ ├── channels.md │ │ ├── controller_errors.md │ │ ├── controllers.md │ │ ├── db_ecto │ │ │ ├── README.md │ │ │ ├── changesets.md │ │ │ ├── generators.md │ │ │ ├── insert_update.md │ │ │ ├── many_to_many.md │ │ │ ├── migration.md │ │ │ ├── query.md │ │ │ ├── relations.md │ │ │ └── schema.md │ │ ├── deployment.md │ │ ├── file_structure.md │ │ ├── liveview.md │ │ ├── packages │ │ │ ├── corsplug.md │ │ │ ├── ratelimiting.md │ │ │ └── ueberauth.md │ │ ├── plug.md │ │ ├── presence.md │ │ ├── router.md │ │ ├── session.md │ │ ├── setup.md │ │ ├── testing.md │ │ ├── token.md │ │ ├── view_templates.md │ │ └── worker.md │ ├── README.md │ ├── collections │ │ ├── README.md │ │ ├── lists.md │ │ ├── map.md │ │ ├── set.md │ │ ├── strings.md │ │ ├── structs.md │ │ └── tuple.md │ ├── config.md │ ├── datetime.md │ ├── erlang.md │ ├── errors.md │ ├── file.md │ ├── functions.md │ ├── math.md │ ├── modules.md │ ├── packages │ │ ├── README.md │ │ ├── genstage.md │ │ ├── geolix.md │ │ ├── http │ │ │ ├── http.md │ │ │ ├── httpoison.md │ │ │ └── tesla.md │ │ ├── json.md │ │ ├── logger.md │ │ ├── nanoid.md │ │ ├── oban.md │ │ ├── redix.md │ │ ├── sentry.md │ │ ├── stripe.md │ │ ├── swoosh.md │ │ └── timex.md │ ├── process │ │ ├── README.md │ │ ├── agent.md │ │ ├── cron.md │ │ ├── genserver.md │ │ ├── registry.md │ │ ├── supervisor.md │ │ └── tasks.md │ ├── regex.md │ ├── setup.md │ ├── time.md │ └── uri.md ├── Elm.md ├── Go │ ├── .md │ ├── IO.md │ ├── JSON.md │ ├── README.md │ ├── assert.md │ ├── basics.md │ ├── collections │ │ ├── README.md │ │ ├── arrays.md │ │ ├── maps.md │ │ └── strings.md │ ├── control.md │ ├── dep.md │ ├── errors.md │ ├── files.md │ ├── func.md │ ├── goroutine.md │ ├── interfaces.md │ ├── math.md │ ├── request.md │ ├── server.md │ ├── structs.md │ ├── testing.md │ └── time.md ├── HTML │ ├── Forms.md │ ├── Fun.md │ ├── README.md │ ├── SEO.md │ ├── Templating │ │ ├── README.md │ │ ├── handlebars.md │ │ ├── jade&pug.md │ │ └── mustache.md │ ├── favicon.md │ ├── images.md │ ├── optimizations.md │ └── scripts.md ├── HeadlessCMS.md ├── Java.md ├── Php │ ├── AMP.md │ ├── Hack.md │ ├── README.md │ ├── requests.md │ └── setup.md ├── Python │ ├── 2.7v3.5.md │ ├── Django │ │ ├── README.md │ │ ├── db.md │ │ ├── models.md │ │ ├── packages │ │ │ └── django-environ.md │ │ ├── router.md │ │ ├── serializers.md │ │ ├── setup.md │ │ └── views.md │ ├── README.md │ ├── advanced.md │ ├── argparse.md │ ├── async.md │ ├── classes.md │ ├── collections │ │ ├── README.md │ │ ├── dict.md │ │ ├── fancyDicts.md │ │ ├── heap.md │ │ ├── list.md │ │ ├── set.md │ │ └── strings.md │ ├── crypto.md │ ├── environments.md │ ├── flask │ │ ├── README.md │ │ ├── blueprint.md │ │ ├── cli.md │ │ ├── config.md │ │ ├── deploying.md │ │ ├── flash.md │ │ ├── login.md │ │ ├── packages.md │ │ ├── packages │ │ │ ├── cors.md │ │ │ ├── mongoEngine.md │ │ │ └── socketio.md │ │ ├── postgres │ │ │ ├── README.md │ │ │ ├── migrate.md │ │ │ └── sqlalchemy.md │ │ ├── requests.md │ │ ├── response.md │ │ └── templating.md │ ├── importing.md │ ├── json.md │ ├── os&files.md │ ├── packages │ │ ├── aiohttp.md │ │ ├── aws │ │ │ ├── boto3.md │ │ │ └── dynamo.md │ │ ├── celery.md │ │ ├── cython.md │ │ ├── dotenv.md │ │ ├── excel.md │ │ ├── google.md │ │ ├── jupyter.md │ │ ├── langchain.md │ │ ├── matplotlib.md │ │ ├── numpy.md │ │ ├── pandas.md │ │ ├── passwords.md │ │ ├── pillow.md │ │ ├── praw.md │ │ ├── prisma.md │ │ ├── pydub.md │ │ ├── pymongo.md │ │ ├── pyppeteer.md │ │ ├── requests.md │ │ └── sqlalchemy.md │ ├── random.md │ ├── re.md │ ├── testing.md │ └── time.md ├── Scala │ ├── README.md │ ├── class.md │ ├── collections.md │ ├── exceptions.md │ ├── functions.md │ ├── futures.md │ ├── guice.md │ ├── loops.md │ ├── objects.md │ ├── options.md │ ├── packages.md │ ├── pattern&conditional.md │ ├── performance&style.md │ ├── sbt(running).md │ ├── strings.md │ ├── subtyping.md │ └── traits.md ├── Swift.md ├── solana.md └── solidity.md ├── CSS ├── Obscure.md ├── README.md ├── animations.md ├── background.md ├── border.md ├── colors.md ├── cursors.md ├── display.md ├── extras │ └── scss.md ├── fonts.md ├── gradients.md ├── lists.md ├── mediaQueries.md ├── object-fit.md ├── overflow.md ├── placement │ ├── README.md │ ├── box.md │ ├── columns.md │ ├── flexbox.md │ ├── grid.md │ ├── position.md │ └── tables.md ├── pseudoElements.md ├── selectors.md ├── tailwind │ ├── README.md │ ├── animations.md │ ├── general.md │ ├── media_queries.md │ ├── position.md │ ├── setup.md │ ├── size_spacing.md │ ├── text.md │ └── typography.md ├── transforms.md └── transitions.md ├── Deployment ├── AWS │ ├── ACM.md │ ├── Amplify.md │ ├── Cloudfront.md │ ├── Cloudwatch.md │ ├── Codebuild.md │ ├── Codedeploy.md │ ├── Codepipeline.md │ ├── Docker.md │ ├── EB.md │ ├── EC2 │ │ ├── README.md │ │ ├── Scripts.md │ │ ├── Types.md │ │ └── Usage.md │ ├── ELB.md │ ├── IAM.md │ ├── Lambda.md │ ├── README.md │ ├── SES.md │ ├── SQS.md │ ├── Storage │ │ ├── Aurora.md │ │ ├── Autoscaling.md │ │ ├── CustomEC2.md │ │ ├── DynamoDB.md │ │ ├── RDS.md │ │ ├── README.md │ │ └── S3.md │ ├── VPC.md │ ├── serverless.md │ └── zappa.md ├── Cloud GPUS │ ├── Beam.md │ ├── paperspace.md │ └── replicate.md ├── DNS.md ├── DigitalOcean.md ├── GCP │ ├── Compute.md │ ├── Network.md │ └── README.md ├── Github │ └── README.md ├── README.md ├── Render │ └── README.md ├── cloudflare.md ├── heroku.md ├── loadtesting.md ├── nginx.md ├── processManagement.md ├── redis.md ├── sockets.md ├── speed_opt.md ├── surge.md ├── task_queues.md ├── terraform.md └── vercel.md ├── JS ├── All │ ├── Angular │ │ ├── HTML.md │ │ ├── HTTP.md │ │ ├── bash.md │ │ ├── input.md │ │ ├── observable_Subject.md │ │ ├── router.md │ │ └── typescript.md │ ├── Chrome_Plugins │ │ ├── README.md │ │ ├── browser_action.md │ │ ├── config.md │ │ ├── content.md │ │ ├── context_menu.md │ │ ├── deploying.md │ │ ├── desktopcapture.md │ │ ├── events.md │ │ ├── identity.md │ │ ├── manifest.md │ │ ├── messages.md │ │ ├── notifications.md │ │ ├── popup.md │ │ ├── service_workers.md │ │ ├── setup.md │ │ ├── shortcuts.md │ │ ├── storage.md │ │ ├── tabs.md │ │ └── url_match.md │ ├── Electron │ │ ├── README.md │ │ ├── deeplinks.md │ │ ├── deploying.md │ │ ├── desktopCapturer.md │ │ ├── dialog.md │ │ ├── image.md │ │ ├── menu.md │ │ ├── messages.md │ │ ├── multiplatform.md │ │ ├── notarizing.md │ │ ├── notifications.md │ │ ├── packages │ │ │ ├── README.md │ │ │ ├── builder.md │ │ │ ├── electron-is-dev.md │ │ │ ├── electron-log.md │ │ │ ├── electron-store.md │ │ │ ├── forge.md │ │ │ └── sentry.md │ │ ├── renderer.md │ │ ├── screen.md │ │ ├── storage.md │ │ ├── tray.md │ │ └── window.md │ ├── Node │ │ ├── README.md │ │ ├── Routing.md │ │ ├── db │ │ │ ├── Mongoose.md │ │ │ ├── README.md │ │ │ ├── ioredis.md │ │ │ ├── knex.md │ │ │ ├── mongodb.md │ │ │ └── prisma.md │ │ ├── ejs.md │ │ ├── env.md │ │ ├── errors.md │ │ ├── files.md │ │ ├── forms.md │ │ ├── logging.md │ │ ├── middleware.md │ │ ├── packages │ │ │ ├── README.md │ │ │ ├── commander.md │ │ │ ├── config.md │ │ │ ├── crypto.md │ │ │ ├── dotenv.md │ │ │ ├── grant.md │ │ │ ├── helmet.md │ │ │ ├── http-errors.md │ │ │ ├── middleware.md │ │ │ ├── passport.md │ │ │ ├── puppeteer.md │ │ │ └── session.md │ │ ├── req.md │ │ ├── require.md │ │ ├── res.md │ │ └── setup.md │ └── bun.md ├── README.md ├── async&await.md ├── bundlers │ ├── parcel.md │ ├── vite.md │ └── webpack.md ├── closure.md ├── collections │ ├── JSON.md │ ├── README.md │ ├── arrays.md │ ├── blob.md │ ├── classes.md │ ├── map.md │ ├── objects.md │ ├── set.md │ └── string.md ├── dates.md ├── debugging.md ├── errors.md ├── es6.md ├── functions.md ├── importing.md ├── packages │ ├── README.md │ ├── ai.md │ ├── aws.md │ ├── babel.md │ ├── bcrypt.md │ ├── cheerio.md │ ├── concurrently.md │ ├── csv-parser.md │ ├── cypress.md │ ├── eslint.md │ ├── jest.md │ ├── lodash.md │ ├── matter.md │ ├── monaco-editor.md │ ├── node-sass.md │ ├── prettier.md │ ├── query-string.md │ ├── socket.md │ ├── supabase.md │ ├── trpc.md │ └── zod.md ├── promises.md ├── regex.md ├── requests.md ├── timeout.md ├── typescript │ ├── 3rd_party_types.md │ ├── README.md │ ├── classes.md │ ├── enum.md │ ├── generics.md │ ├── interface.md │ ├── migration.md │ ├── narrowing.md │ ├── packages │ │ └── trpc.md │ ├── types.md │ └── utility.md └── webJS │ ├── CORS.md │ ├── DOM.md │ ├── DOMShadow.md │ ├── README.md │ ├── audio.md │ ├── canvas.md │ ├── clipboard.md │ ├── cookies.md │ ├── events.md │ ├── iframe.md │ ├── intersectionobservers.md │ ├── keyboard.md │ ├── media.md │ ├── navigator.md │ ├── packages │ ├── Tabulator.md │ ├── bowser.md │ ├── boxicons.md │ ├── d3.md │ ├── mapbox.md │ ├── mousetrap.md │ └── videojs.md │ ├── scroll.md │ ├── simpleserve.md │ ├── storage.md │ └── worker.md ├── ML ├── .md ├── Deploy │ ├── Beam.md │ └── Paperspace.md ├── NLP │ ├── 1preprocessing.md │ ├── 2vectorizing.md │ ├── 3featureengineering.md │ ├── 4ml.md │ ├── 4ml2.md │ ├── Overview.md │ └── nltk.md ├── embedding.md ├── eval_llm.md ├── lowlevel │ ├── BuzzWordGuide.md │ ├── Regularization.md │ ├── datasets.md │ └── pytorch │ │ ├── README.md │ │ ├── datasets.md │ │ ├── gpu.md │ │ └── nn.md └── vector_store.md ├── README.md ├── React ├── All │ ├── Gatsby │ │ ├── README.md │ │ ├── cli.md │ │ ├── data.md │ │ ├── link.md │ │ ├── packages │ │ │ ├── mdx.md │ │ │ └── tailwindcss.md │ │ ├── pages.md │ │ ├── plugins.md │ │ ├── setup.md │ │ ├── style.md │ │ └── transformer.md │ ├── Prehooks │ │ ├── components.md │ │ ├── ref.md │ │ └── state&lifecycle.md │ └── React_Native │ │ ├── Expo │ │ ├── README.md │ │ ├── development_build.md │ │ ├── env.md │ │ └── setup.md │ │ ├── ListViews.md │ │ ├── README.md │ │ ├── SafeAreaView.md │ │ ├── defaultComponents.md │ │ ├── fetch.md │ │ ├── gestures.md │ │ ├── navigation.md │ │ ├── notification.md │ │ ├── orientation.md │ │ ├── packages │ │ ├── reanimated.md │ │ └── screenshot.md │ │ ├── style.md │ │ └── width_height.md ├── Next │ ├── Image.md │ ├── PreAppRouter │ │ ├── SSR.md │ │ ├── api.md │ │ ├── head.md │ │ ├── layouts.md │ │ └── routing.md │ ├── README.md │ ├── api.md │ ├── app_router.md │ ├── assets.md │ ├── config.md │ ├── css.md │ ├── deploying.md │ ├── layouts.md │ ├── markdown.md │ ├── metadata.md │ ├── packages │ │ ├── contentlayer.md │ │ ├── mdx.md │ │ └── t3-env.md │ ├── routing.md │ ├── server_actions.md │ └── setup.md ├── README.md ├── assets.md ├── children.md ├── context.md ├── data_loading │ ├── README.md │ └── react-query.md ├── deployment.md ├── effect.md ├── errors.md ├── events.md ├── forms.md ├── hooks.md ├── jsx.md ├── lists.md ├── optimization.md ├── packages │ ├── SWR.md │ ├── classnames.md │ ├── color.md │ ├── datepicker.md │ ├── draggable.md │ ├── emotion.md │ ├── feather.md │ ├── fluxible.md │ ├── general.md │ ├── google.md │ ├── intersection-observer.md │ ├── lazyload.md │ ├── load-script.md │ ├── proptypes.md │ ├── react-router.md │ ├── recharts.md │ ├── select.md │ ├── shadcn.md │ ├── slate.md │ ├── table.md │ ├── tanstack-router.md │ ├── telephone.md │ ├── three-fiber.md │ ├── toastify.md │ ├── tooltip.md │ ├── videojs.md │ ├── waypoint.md │ ├── window.md │ └── xstate.md ├── render.md ├── server_components.md ├── setup.md ├── state.md ├── state_management │ ├── README.md │ ├── jotai.md │ ├── mobx.md │ ├── redux │ │ ├── README.md │ │ ├── immer.md │ │ ├── middleware.md │ │ ├── react-redux.md │ │ ├── redux.md │ │ ├── redux_toolkit.md │ │ ├── selectors.md │ │ ├── setup.md │ │ └── thunk.md │ └── zustand.md ├── style.md └── suspense.md ├── Rust ├── Error.md ├── Importing.md ├── Ownership.md └── README.md ├── chrome.md ├── debugging.md ├── google.md ├── graphQL.md ├── mac.md ├── markdown.md ├── regex.md ├── techtotry.md └── typora.md /.gitignore: -------------------------------------------------------------------------------- 1 | Ecstatic/ 2 | .DS_Store 3 | Coursera/ 4 | Facebook/ 5 | Latent/ 6 | latent.md 7 | *~* 8 | -------------------------------------------------------------------------------- /All/APIS/DuckDuckGo.md: -------------------------------------------------------------------------------- 1 | # DuckDuckGo 2 | 3 | Great image search 4 | 5 | ## [Python](https://pypi.org/project/duckduckgo-images-api/) 6 | 7 | ```python 8 | from duckduckgo_images_api import search 9 | results = search("nike") 10 | [result["image"] for result in results["results"]] 11 | ``` 12 | 13 | -------------------------------------------------------------------------------- /All/APIS/README.md: -------------------------------------------------------------------------------- 1 | # APIS 2 | 3 | #### Designing An API 4 | 5 | How to ensure your open api is secures 6 | 7 | https://softwareengineering.stackexchange.com/questions/219028/how-to-safeguard-a-rest-api-for-only-trusted-mobile-applications 8 | 9 | ## Oauth 10 | 11 | Implicit Flow just has one less step so easier, but less secure or something. Doing a get request with access_token lets anyone who can see your history or url gets have it which is less secure than the regular oauth post request. -------------------------------------------------------------------------------- /All/APIS/Stripe.md: -------------------------------------------------------------------------------- 1 | # Stripe 2 | 3 | ## Elixir 4 | 5 | ```elixir 6 | {:stripity_stripe, "~> 2.0"}, 7 | ``` 8 | 9 | https://github.com/code-corps/stripity_stripe 10 | 11 | Stripe.Customer.retrieve("cus_jkldfsajklafjs") -------------------------------------------------------------------------------- /All/Bash/Kill.md: -------------------------------------------------------------------------------- 1 | ## Kills 2 | Ctrl+C Kills SIGINT 3 | Ctrl+Z Suspends with SIGSTOP 4 | Ctrl+/ Is merciless 5 | `ps` 6 | `kill -9 [pid]` 7 | 8 | `lsof -i :3000` to find the process running on port 3000 9 | 10 | - basically looks at lists open files 11 | 12 | -------------------------------------------------------------------------------- /All/Bash/Makefile.md: -------------------------------------------------------------------------------- 1 | # Makefile 2 | 3 | Makefile name 4 | 5 | ```makefile 6 | CC=gcc 7 | CFLAGS=-I. 8 | DEPS = hellomake.h 9 | 10 | %.o: %.c $(DEPS) 11 | $(CC) -c -o $@ $< $(CFLAGS) 12 | 13 | hellomake: hellomake.o hellofunc.o 14 | $(CC) -o hellomake hellomake.o hellofunc.o 15 | ``` 16 | 17 | ## Differences From Bash 18 | 19 | - It seems \$PWD works instead of ​\$(pwd) within a command 20 | - To do command after a cd, use semicolon 21 | 22 | ```makefile 23 | cd ./client; yarn build; 24 | ``` 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /All/Bash/diff.md: -------------------------------------------------------------------------------- 1 | # Diff 2 | 3 | ## Find differences between two folders 4 | 5 | ```bash 6 | diff -bur react_phoenix Phoenix-React-Base 7 | diff -bur --brief react_phoenix Phoenix-React-Base #show summary 8 | diff -bur --brief react_phoenix Phoenix-React-Base -x deps #ignore deps folder 9 | ``` 10 | 11 | -------------------------------------------------------------------------------- /All/Bash/emacs.md: -------------------------------------------------------------------------------- 1 | # Emacs 2 | 3 | If emacs is opening in a window, run `emacs -nw` 4 | 5 | M means Alt 6 | 7 | | Cmd | Effect | 8 | | ----- | ------------------------ | 9 | | C - v | Next Page | 10 | | C - p | Previous Line | 11 | | C - a | Start of Line | 12 | | C - e | End of Line | 13 | | C-x u | Undo | 14 | | C - n | Next Line | 15 | | C - k | Kill(delete? copy?) line | 16 | | | | 17 | | | | 18 | 19 | ## Selecting Text 20 | 21 | Ctrl - Space sets a mark and then move cursor and it will select all the text from the mark to the cursor with wrapping 22 | 23 | | Cmd | Effect | 24 | | ---- | ------ | 25 | | C-w | Cut | 26 | | M-w | Copy | 27 | | C-y | Paste | 28 | 29 | -------------------------------------------------------------------------------- /All/Bash/find.md: -------------------------------------------------------------------------------- 1 | # Find 2 | 3 | recursively descends the directory tree for each path listed, evaluating an expression 4 | 5 | *wont follow soft links* 6 | 7 | ### Find file by name 8 | 9 | ```bash 10 | find . -iname [word] 11 | find . -iname local # => ./Projects/local 12 | ``` 13 | 14 | #### Find some string in all files in cur dir 15 | 16 | ```bash 17 | find . -type f -print0 | xargs -0 18 | # OR 19 | grep "some string" 20 | ``` 21 | 22 | -------------------------------------------------------------------------------- /All/Bash/general.md: -------------------------------------------------------------------------------- 1 | ## Understand Machine 2 | 3 | `top` see mem usage 4 | 5 | `du -sh` to see size of dir 6 | 7 | `du -h --max-depth=1 | sort -hr` to see size of dirs/files in folder 8 | 9 | `tail ` get end of file, `tail -f` to open buffer and show end of file updating 10 | 11 | `head` get start of file 12 | 13 | ## Pbcopy 14 | 15 | `pbcopy < atom.sh` 16 | 17 | ## Word Count(wc) 18 | 19 | `wc -l [filename]` 20 | 21 | #### Find number of lines in a directory 22 | 23 | `find . -name '*' | xargs cat | wc -l` 24 | 25 | ## XARGS 26 | 27 | `cat [filename] | xargs wc -l` => `wc -l [filename]` 28 | 29 | `xargs [utility] [utility args]` 30 | 31 | reads from the standard input 32 | ​ and executes utility 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /All/Bash/installed/generact.md: -------------------------------------------------------------------------------- 1 | # Generact 2 | 3 | Duplicate react components 4 | 5 | ```bash 6 | generact 7 | ``` 8 | 9 | That is it the UI will take it from there -------------------------------------------------------------------------------- /All/Bash/installed/ngrok.md: -------------------------------------------------------------------------------- 1 | # Run a Server From LocalHost to the World 2 | 3 | `ngrok http [THE PORT YOU WANT]` 4 | 5 | Then just go to that url and its exposed to the world ez 6 | 7 | #### Inspect Incoming Request 8 | 9 | http://localhost:4040/inspect/http ez -------------------------------------------------------------------------------- /All/Bash/installed/nvm.md: -------------------------------------------------------------------------------- 1 | # Node Version Manager 2 | 3 | **Use asdf instead cuz its more general** 4 | 5 | ### Setup 6 | 7 | ``` 8 | curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash 9 | ``` 10 | 11 | ### Install Nodes 12 | 13 | ``` 14 | nvm install --lts 15 | nvm --help 16 | ``` 17 | 18 | help gives most of what you need -------------------------------------------------------------------------------- /All/Bash/installed/spell.md: -------------------------------------------------------------------------------- 1 | # Spell 2 | 3 | Run code on GPUS like a god 4 | 5 | ## Setup 6 | 7 | ```bash 8 | spell login 9 | spell whoami 10 | ``` 11 | 12 | ## Usage 13 | 14 | ```bash 15 | # default CPU 16 | spell run "python example.py" 17 | 18 | # Nvidia's Tesla K80 19 | spell run -t K80 "python example.py" 20 | 21 | # Nvidia's Tesla V100 multi-GPU option 22 | spell run -t V100x4 "python multi-example.py" 23 | ``` 24 | 25 | ## Resources 26 | 27 | Store data in resources 28 | 29 | ```bash 30 | spell upload simpleNN/data/ 31 | spell ls 32 | ``` 33 | 34 | ## Workspace 35 | 36 | Create a workspace in the GUI, upload a jupyter file, and goooooo ez. Easily use resources. -------------------------------------------------------------------------------- /All/Bash/man.md: -------------------------------------------------------------------------------- 1 | # Man 2 | 3 | `man ls` will open manual on ls with all options 4 | 5 | ### Searching 6 | 7 | `/` - open find 8 | 9 | `n` - go to next find -------------------------------------------------------------------------------- /All/Bash/metadata.md: -------------------------------------------------------------------------------- 1 | # Editing File Metadata 2 | 3 | Metadata is like where a file was downloaded from and such: 4 | 5 | ## Editing 6 | 7 | ``` 8 | xattr -l file.flv 9 | com.apple.metadata:kMDItemWhereFroms: 10 | 00000000 62 70 6C 69 73 74 30 30 A1 01 5F 11 01 7F 68 74 |bplist00.._...ht| 11 | 00000010 74 70 3A 2F 2F 73 31 73 64 6C 6F 64 30 35 33 2E |tp://s1sdlod053.| 12 | 00000020 62 63 73 74 2E 63 64 6E 2E 73 31 73 2E 79 69 6D |bcst.cdn.s1s.yim| 13 | 00000030 67 2E 63 6F 6D 2F 2F 73 31 73 6E 66 73 30 36 72 |g.com//s1snfs06r| 14 | 00000040 30 35 2F 30 30 35 2F 76 69 64 65 6F 73 65 61 72 |05/005/videosear| 15 | 00000050 63 68 2F 39 30 35 32 32 35 37 37 2E 66 6C 76 3F |ch/90522577.flv?| 16 | 00000060 53 74 72 65 61 6D 49 44 3D 39 30 35 32 32 35 37 |StreamID=9052257| 17 | ... 18 | 19 | xattr -w "com.apple.metadata:kMDItemWhereFroms" 20 | "http://topdocumentaryfilms.com/journey-edge-universe/" file.flv 21 | ``` -------------------------------------------------------------------------------- /All/Bash/sed.md: -------------------------------------------------------------------------------- 1 | # Sed 2 | 3 | Stream editor to do bash text manipulation 4 | 5 | ### String Substituting 6 | 7 | First one hit 8 | 9 | ```bash 10 | sed 's/hello/world/' input.txt > output.txt 11 | ``` 12 | 13 | Translate all 14 | 15 | ```bash 16 | echo "hello hello my world world" | sed 's/hello/world/g' 17 | ``` 18 | 19 | -------------------------------------------------------------------------------- /All/Bash/sftp.md: -------------------------------------------------------------------------------- 1 | # Secure File Transfer Protocol 2 | 3 | ```bash 4 | sftp -i "~/Desktop/pem/Slingshow-1.pem" ec2-user@ec2-54-229-73-137.us-west-1.compute.amazonaws.com 5 | ``` 6 | 7 | Opens a ssh shell on the remote host with limited functionality 8 | 9 | Use regular bash cmds to move around(`ls`, `cd`) 10 | 11 | `help` in sftp shows you the list of acceptable commands(limited bash) 12 | 13 | ### Put in EC2/remote server 14 | 15 | ```bash 16 | put [local_filename] 17 | put -r [local_directory] 18 | ``` 19 | 20 | #### Get from remote 21 | 22 | ```bash 23 | get remoteFile localFile 24 | ``` 25 | 26 | ## Local interaction 27 | 28 | preface commands with l to run them locally i.e 29 | 30 | `lpwd` => local directory 31 | 32 | `lcd`, `lls` etc 33 | 34 | node test_attendee join --host eta-staging.onrender.com -m -h -n 4 HkQm-QyN 35 | -------------------------------------------------------------------------------- /All/Bash/ssh.md: -------------------------------------------------------------------------------- 1 | # SSH 2 | 3 | Secure shell, remote computer access 4 | 5 | ssh [username]@[public-DNS] 6 | 7 | `exit` to close connection 8 | 9 | ## Generate new ssh key 10 | 11 | ```bash 12 | ssh-keygen 13 | 14 | cat ~/.ssh/id_rsa.pub #to see public key 15 | ``` 16 | 17 | -------------------------------------------------------------------------------- /All/Bash/vi.md: -------------------------------------------------------------------------------- 1 | # Vi 2 | 3 | ESC => enter edit mode 4 | 5 | | :wq | Save and quit | 6 | | ------ | -------------- | 7 | | dd | delete line | 8 | | dd2 | delete 2 lines | 9 | | ctrl-f | Forward page | 10 | | ctrl-b | Back page | 11 | | | | 12 | | | | 13 | | | | 14 | | | | 15 | | | | 16 | 17 | i => enter insert mode to type 18 | 19 | -------------------------------------------------------------------------------- /All/C++/ptrs.md: -------------------------------------------------------------------------------- 1 | # Ptrs 2 | 3 | ### Advanced 4 | 5 | Smart ptrs are meant to solve many ptr problems like leaky mem and dangling ptrs by introducing the concept of ownership 6 | 7 | Unique_ptrs are ptrs that can't be copied and delete the underlying mem when the ptr itself is deleted 8 | 9 | Shared ptrs keep track of how many ptrs have access to the underlying object and delete the underlying object when there are no more references 10 | 11 | -------------------------------------------------------------------------------- /All/CS_Fundamentals/Concurrency.md: -------------------------------------------------------------------------------- 1 | ## Semaphore 2 | 3 | tracks only *how many* resources are free; not *which* of the resources are free.To select can use more semaphores or something else 4 | 5 | a **semaphore** is var to control access to multithreaded apps 6 | 7 | Can have int **counting semaphores** or **binary semaphores** 8 | 9 | used to implement locks -------------------------------------------------------------------------------- /All/CS_Fundamentals/Email.md: -------------------------------------------------------------------------------- 1 | # Email 2 | 3 | If email deliverability low, checkout 4 | 5 | [Email Tester]([http://www.mail-tester.com/) 6 | 7 | https://sendgrid.com/blog/how-to-authenticate-your-email-in-5-steps/ 8 | 9 | https://dmarcly.com/blog/how-to-add-spf-record-in-cloudflare-cloudflare-spf-setup-guide 10 | 11 | https://support.google.com/mail/answer/180707?authuser=1 -------------------------------------------------------------------------------- /All/CS_Fundamentals/Encryption.md: -------------------------------------------------------------------------------- 1 | # Encryption 2 | 3 | Good [security resource](https://cheatsheetseries.owasp.org/) 4 | 5 | ## Password 6 | 7 | Don't use MD5, SHA1, SHA2, SHA3, etc 8 | 9 | Instead use something that takes longer like Blowfish with salts 10 | 11 | ### Password Reset 12 | 13 | Tokens should: 14 | 15 | - Expire 16 | - Be unpredicatable 17 | - Encrypted like credientials b/c they can basically be used a password 18 | - Security questions? 19 | 20 | -------------------------------------------------------------------------------- /All/CS_Fundamentals/ErrorHandling.md: -------------------------------------------------------------------------------- 1 | # Errors 2 | 3 | Operational errors must be handled gracefully like: 4 | 5 | - failed to connect to server 6 | - failed to resolve hostname 7 | - invalid user input 8 | - request timeout 9 | - server returned a 500 response 10 | - socket hang-up 11 | - system is out of memory -------------------------------------------------------------------------------- /All/CS_Fundamentals/FeatureFlags.md: -------------------------------------------------------------------------------- 1 | # Feature Flags 2 | 3 | Easily enable or disable features for experimentation or slow rollouts 4 | 5 | - https://www.growthbook.io/) 6 | 7 | https://software.rajivprab.com/2019/12/19/when-feature-flags-do-and-dont-make-sense/ 8 | 9 | ### Simplest 10 | 11 | Store in a db 12 | 13 | name | is_active 14 | 15 | Then write api to fetch is_active for that name before enabling. Or just fetch all feature flags on load and store in cookie or localStorage so persists. Hash user_id and name into % so stable percentage difference. Add custom flagging for user field and add in flags check. 16 | 17 | #### Why feature flag provider? 18 | 19 | A feature flag provider has a seperate db, audit log, user interface, code to automatically keep clientside flags updated(worker with socket), **enable for selective users**, 20 | 21 | Providers: 22 | 23 | - LaunchDarkly 24 | - Posthog 25 | - [Growthbook]( -------------------------------------------------------------------------------- /All/CS_Fundamentals/Microservices.md: -------------------------------------------------------------------------------- 1 | # Microservices 2 | 3 | - increases developer productivity by allowing independent deployment for many people when people step on each others toes 4 | - decreases developer productivity for changes that require many service changes -------------------------------------------------------------------------------- /All/CS_Fundamentals/Optimization.md: -------------------------------------------------------------------------------- 1 | # Optimization 2 | 3 | ## Latency 4 | 5 | - L1 cache reference 0.5 ns 6 | - Branch mispredict 5 ns 7 | - L2 cache reference 7 ns 8 | - Mutex lock/unlock 100 ns 9 | - Main memory reference 100 ns 10 | - Compress 1K bytes with Zippy 10,000 ns 11 | - Send 2K bytes over 1 Gbps network 20,000 ns 12 | - Read 1 MB sequentially from memory 250,000 ns 13 | - Round trip within same datacenter 500,000 ns 14 | - Disk seek 10,000,000 ns 15 | - Read 1 MB sequentially from network 10,000,000 ns 16 | - Read 1 MB sequentially from disk 30,000,000 ns 17 | - Send packet CA->Netherlands->CA 150,000,000 ns 18 | 19 | ## Server 20 | 21 | https://code.tubitv.com/how-we-discovered-a-7-year-old-performance-issue-in-elixir-99080bdce9a1 -------------------------------------------------------------------------------- /All/CS_Fundamentals/Password_Hashing.md: -------------------------------------------------------------------------------- 1 | # Password Hashing 2 | 3 | Recommendation: Argon2, won 2014-2016 password hashing contest 4 | 5 | https://guptadeepak.com/comparative-analysis-of-password-hashing-algorithms-argon2-bcrypt-scrypt-and-pbkdf2/ 6 | 7 | 1. **Argon2**: Likely to see increased adoption as the new standard for password hashing. Its flexibility and security make it well-positioned for future cryptographic needs. 8 | 2. **bcrypt**: Will continue to be widely used due to its established presence and simplicity. However, it may gradually be replaced by Argon2 in high-security applications. 9 | 3. **scrypt**: Will remain relevant, especially in cryptocurrency and other memory-hard applications. However, it may lose ground to Argon2 in general use cases. 10 | 4. **PBKDF2**: Due to its widespread implementation and FIPS compliance, PBKDF2 will continue to be used, but it's likely to be phased out in favor of more secure alternatives for password hashing. -------------------------------------------------------------------------------- /All/CS_Fundamentals/Real-Time.md: -------------------------------------------------------------------------------- 1 | # Real-Time 2 | 3 | How do you do stuff like realtime updates, push changes from server to clients? 4 | 5 | ## Websockets 6 | 7 | [Sockets.io](https://socket.io/) 8 | 9 | - Create a sustained connection that both sides listen to 10 | - Remove work of constantly doing a handshake, creating a connection, and sending headers 11 | 12 | #### Polling 13 | 14 | Client requests updates from server on schedule 15 | 16 | #### Long polling / Server-Sent Events 17 | 18 | The client asks for info and the server keeps the connection open until a response, uses the EventSource API 19 | 20 | ## Kafka 21 | 22 | Heavy duty producer consumer relationship 23 | 24 | All these producers publish to kafka to their own or a common stream, and all these consumers can subscribe to the data streams 25 | 26 | -------------------------------------------------------------------------------- /All/CS_Fundamentals/Sorting.md: -------------------------------------------------------------------------------- 1 | # Sorting 2 | 3 | - Quick Sort: O(nlogn) in practice but O(n²) worst-case, sort around pivot 4 | - Merge Sort, Heap Sort: Consistent O(n log n) 5 | - Bubble Sort, Insertion Sort, Selection Sort: Simple O(n^2) 6 | - Counting Sort, Radix Sort**: Non-comparison sorts, efficient for specific use cases.** 7 | - Tim Sort: Highly optimized for real-world data and widely used in standard libraries including JS and Python, basically combined Merge Sort and Insertion Sort -------------------------------------------------------------------------------- /All/CS_Fundamentals/StoringSecrets.md: -------------------------------------------------------------------------------- 1 | # Storing Secrets 2 | 3 | There are many heavy weight solutions that you should look into if you become a team with many credentials including blackbox, https://www.chef.io/, https://square.github.io/keywhiz/. Can also have files encrypted on github with things like git-crypt 4 | 5 | ## Simple Solutions 6 | 7 | ### Environment Variables 8 | 9 | - easy load from file 10 | - often use env variables for other things too so good to set up 11 | 12 | Cons: 13 | 14 | - According to https://news.ycombinator.com/item?id=9952911, its possible that environment variables are shown in debug output when a server crashes potentially comprising the system 15 | - Can't revoke secrets.json or manage like an expert 16 | 17 | ### Seperate Secrets.json 18 | 19 | - Easiest 20 | 21 | -------------------------------------------------------------------------------- /All/CS_Fundamentals/Testing.md: -------------------------------------------------------------------------------- 1 | # Testing 2 | 3 | Diminishing returns for code coverage given time 4 | 5 | Good Tests: 6 | 7 | - run fast 8 | - doesn't break often 9 | - easy to understand 10 | - catches bugs 11 | - good coverage to effort ratio 12 | 13 | ### Test Strategy 14 | 15 | Need Iteration to find good test strategy 16 | 17 | Mocking too much reduces test quality 18 | 19 | Good ideas: 20 | 21 | - Writing test setup utilities functions 22 | - Categorize types of tests and make templates -------------------------------------------------------------------------------- /All/CS_Fundamentals/WebRTC.md: -------------------------------------------------------------------------------- 1 | # WebRTC 2 | 3 | Google supported standard for easy p2p communication that can then scale to use an intermediate server for > 4 4 | 5 | Handles everything from stabilization, codecs, etc for ez use and multi platform including many browsers and matching native performance 6 | 7 | Beyond about 3/4, probably need a server to communicate because all the devices will connect and send data to every other device 8 | 9 | Need signal server to let the peers communicate session data to begin connection 10 | 11 | Need a hosted STUN / TURN server to handle fallback when because of NAT or other, the p2p connection fails 12 | 13 | ##### Interface 14 | 15 | MediaStreams 16 | 17 | P2P Connections 18 | 19 | ### Debugging 20 | 21 | chrome://media-internals 22 | 23 | -------------------------------------------------------------------------------- /All/CS_Fundamentals/Webhook.md: -------------------------------------------------------------------------------- 1 | # Webhook 2 | 3 | Instead of pulling the data like an API, a webhook is when the provider pushes the data to you by sending a post request. 4 | 5 | Good for: 6 | 7 | - When events can happen at anytime, like payment authorization takes days 8 | 9 | Authentication 10 | 11 | - Stripe signs requests 12 | - Pass secrets or tokens like GitHub 13 | - Api Key stored by provider 14 | 15 | -------------------------------------------------------------------------------- /All/Databases/SQL/aggregate.md: -------------------------------------------------------------------------------- 1 | # Aggregate 2 | 3 | When you use GROUP_BY, you can only select aggregates or columsn in the GROUP_BY 4 | 5 | #### Count 6 | 7 | - `COUNT(*)` /`COUNT(1)`counts all rows 8 | - `COUNT(column)` counts non-NULLs only 9 | 10 | ```sql 11 | SELECT COUNT(*) FROM orders GROUP BY ds; 12 | ``` 13 | 14 | #### Max 15 | 16 | Even works for strings where later in the alphabet is more 17 | 18 | #### Min 19 | 20 | Even works for strings where later in the alphabet is more -------------------------------------------------------------------------------- /All/Databases/SQL/joins.md: -------------------------------------------------------------------------------- 1 | # JOINS 2 | 3 | `:inner_join`, `:left_join`, `:right_join`, `:cross_join`, `:full_join`, `:inner_lateral_join` or `:left_lateral_join`. `:join` is equivalent to `:inner_join`(match both returned) 4 | 5 | ![SQL INNER JOIN](https://www.w3schools.com/sql/img_innerjoin.gif) ![SQL LEFT JOIN](https://www.w3schools.com/sql/img_leftjoin.gif) ![SQL RIGHT JOIN](https://www.w3schools.com/sql/img_rightjoin.gif) ![SQL FULL OUTER JOIN](https://www.w3schools.com/sql/img_fulljoin.gif) 6 | 7 | -------------------------------------------------------------------------------- /All/Databases/SQL/optimizations.md: -------------------------------------------------------------------------------- 1 | # Optimizations 2 | 3 | ### N+1 Queries 4 | 5 | ```php 6 | $cats = load_cats(); 7 | foreach ($cats as $cat) { 8 | $cats_hats = load_hats_for_cat($cat); 9 | // ... 10 | } 11 | ``` 12 | 13 | ``` 14 | SELECT * FROM cat WHERE ... 15 | SELECT * FROM hat WHERE catID = 1 16 | SELECT * FROM hat WHERE catID = 2 17 | SELECT * FROM hat WHERE catID = 3 18 | SELECT * FROM hat WHERE catID = 4 19 | SELECT * FROM hat WHERE catID = 5 20 | ``` 21 | 22 | Instead do 23 | 24 | ```php 25 | $cats = load_cats(); 26 | $hats = load_all_hats_for_these_cats($cats); 27 | foreach ($cats as $cat) { 28 | $cats_hats = $hats[$cat->getID()]; 29 | } 30 | ``` 31 | 32 | ``` 33 | SELECT * FROM cat WHERE ... 34 | SELECT * FROM hat WHERE catID IN (1, 2, 3, 4, 5, ...) 35 | ``` 36 | 37 | -------------------------------------------------------------------------------- /All/Databases/SQL/sqllite.md: -------------------------------------------------------------------------------- 1 | # SQL Lite 2 | 3 | SQL DB stored in a local file and capable of being used in many different device types 4 | 5 | ``` 6 | sqlite dbfile.db 7 | .tables 8 | select * from cards limit 1; 9 | ``` 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /All/Databases/advanced.md: -------------------------------------------------------------------------------- 1 | # Advanced (Postgres?) 2 | 3 | ### Transactions 4 | 5 | Transactions group db commands to be atomic, all or nothing, and permanently recorded to disk(not dirty/in memory) 6 | 7 | Useful for something like bank transfers where you want to ensure an amount is deducted and added or nothing 8 | 9 | ```sql 10 | BEGIN; 11 | UPDATE accounts SET balance = balance - 100.00 12 | WHERE name = 'Alice'; 13 | -- etc etc 14 | COMMIT; 15 | ``` 16 | 17 | -------------------------------------------------------------------------------- /All/Databases/hosts.md: -------------------------------------------------------------------------------- 1 | # Hosts 2 | 3 | ## Mongodb 4 | 5 | - DocumentDB AWS 6 | + Unconfirmed cant use Mongoose 7 | + Steep $200/month start(need I say more) 8 | - Mongodb Atlas 9 | - Free tier of 512 MB -------------------------------------------------------------------------------- /All/Databases/libs.md: -------------------------------------------------------------------------------- 1 | # Code Abstractions 2 | 3 | ## Database Driver 4 | 5 | - raw SQL strings delievered to database with async? Rest 6 | - connection pooling 7 | 8 | ## Query Builder 9 | 10 | - programmatically generate dynamic queries in a much more convenient way 11 | - generate queries for a few different SQL dialects 12 | - **sweetspot of SQL** because clear connection to general SQL, yet dealing with fts instead of strings 13 | 14 | ## ORM 15 | 16 | - map a record in a relational database to an object 17 | - Do object validation on NoSQL and create generated properties and class fields 18 | - Learn a ORM specific interface rather than SQL 19 | - Must update code when you update database slowing down iterations early 20 | - Cant do everything in an ORM meaning you dip into SQL or do some inefficient code 21 | - **sweetspot of NoSQL**, adds needed things like object validation -------------------------------------------------------------------------------- /All/Databases/redis.md: -------------------------------------------------------------------------------- 1 | # [Redis](https://redis.io/docs/install/install-redis/install-redis-on-mac-os/) 2 | 3 | ```bash 4 | brew install redis 5 | ``` 6 | 7 | ## Usage 8 | 9 | ``` 10 | redis-cli 11 | ``` 12 | 13 | -------------------------------------------------------------------------------- /All/Databases/tips.md: -------------------------------------------------------------------------------- 1 | # Tips 2 | 3 | - If the user will submit it via a form, it is best to allow the ids to be client generated so the ids on the client and the server can be the same after a inline/autosave save. -------------------------------------------------------------------------------- /All/Dev_Apps/iterm2.md: -------------------------------------------------------------------------------- 1 | # Iterm2 2 | 3 | The best Mac terminal replacement 4 | 5 | | Command | Effect | 6 | | --------- | ----------------------------------------------------------- | 7 | | Cmd-Opt-A | Alert on Finished Command (will see eyeball in upper right) | 8 | | Cmd-Opt-B | See Terminal History | 9 | | | Multiple Screens | 10 | | Ctrl-U | Delete entire cmd line | 11 | | Ctrl-W | Delete last word | 12 | | | | 13 | | | | 14 | | | | 15 | | | | -------------------------------------------------------------------------------- /All/Dev_Apps/matlab.md: -------------------------------------------------------------------------------- 1 | # Matlab/Octave 2 | 3 | Each file is a function, check console to see output and run functions 4 | 5 | IN other files simply call the function name 6 | 7 | You need to add folders to the load path in octave, type `path` into console to see the current files 8 | 9 | Arrays index from 1 10 | 11 | ```matlab 12 | S[:] #pretty sure this turns matrix into vector? 13 | S' #transpose matrix 14 | size(S) #row, column 15 | fprintf('size(A) is %s\n', mat2str(size(A))) 16 | ``` 17 | 18 | ## Operations 19 | 20 | ```matlab 21 | Z ./ 100 # elementwise 100? 22 | ``` 23 | 24 | ## For loops 25 | 26 | Very slow avoid at all costs 27 | 28 | ```matlab 29 | for n=1:10 30 | experiment() 31 | fprintf('%d-Experiment Complete', n); 32 | end 33 | ``` 34 | 35 | ### Octave 36 | 37 | In console, install pkgs with: 38 | 39 | ```matlab 40 | pkg install --forge [package-name] 41 | ``` 42 | 43 | -------------------------------------------------------------------------------- /All/Dev_Apps/notion.md: -------------------------------------------------------------------------------- 1 | # Notion 2 | 3 | Have one master list of tasks then have relations to project and sprints 4 | 5 | Use formulas to create numbers and conditional numbers, then rollups to sum them in the relationed table 6 | 7 | Use linked database to have many pages with different views of the same data 8 | 9 | ### Templates 10 | 11 | - Open Notion Page where you want to use the template 12 | - Create content you want to create a template of 13 | - On the page, type /template to add a template button to the page 14 | - Clear out the existing content in the Template section of the Configure Template box 15 | - Click and Drag the content you want to add to your template into the “Template” section of the Configure Template box -------------------------------------------------------------------------------- /All/Dev_Apps/retool.md: -------------------------------------------------------------------------------- 1 | # Retool 2 | 3 | Create internal database tools very fast 4 | 5 | Can drag drop tables, charts etc 6 | 7 | double brackets can execute arbitrary js including some libraries like moment 8 | 9 | ## Charts 10 | 11 | Add datasets 12 | 13 | -------------------------------------------------------------------------------- /All/Dev_Apps/slack.md: -------------------------------------------------------------------------------- 1 | # Slack 2 | 3 | ## [Github Bot](https://github.com/integrations/slack#configuration) 4 | 5 | ```bash 6 | /github subscribe jsfuentes/Eta commits:all #this should work 7 | /github subscribe jsfuentes/Pi commits:master #but this actually worked :thinking emoji 8 | ``` 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /All/Dev_Apps/tableplus.md: -------------------------------------------------------------------------------- 1 | # Tableplus 2 | 3 | Awesome SQL Admin Tool 4 | 5 | - Lets you easily import from url and query table 6 | - [Backup and restore to move db](https://tableplus.com/blog/2018/04/postgresql-how-to-copy-database-to-other-server.html) -------------------------------------------------------------------------------- /All/Dev_Apps/warp.md: -------------------------------------------------------------------------------- 1 | # Warp 2 | 3 | - Select, filter blocks of output 4 | - click into text 5 | - natural language to commands 6 | - Easy notifs 7 | 8 | Up to 100 AI requests per user per month 9 | 10 | `# explanation of what you want` 11 | 12 | -------------------------------------------------------------------------------- /All/Dev_Apps/windows.md: -------------------------------------------------------------------------------- 1 | # Windows Terminal 2 | 3 | No multiple tabs 4 | 5 | | Cmd | Action | 6 | | ---- | ------ | 7 | | dir | ls | 8 | | cd | Cd | 9 | | | | 10 | | | | 11 | | | | 12 | | | | 13 | | | | 14 | | | | 15 | | | | 16 | 17 | -------------------------------------------------------------------------------- /All/Docker/README.md: -------------------------------------------------------------------------------- 1 | # Docker 2 | 3 | ## Overview 4 | 5 | Get the same environment everywhere. No installation necessary(no onboarding) 6 | 7 | `docker run hello-world` #lists steps as example 8 | 9 | #### Tech Words 10 | 11 | A **container** is an Linux instance launched by running an image. An **image** is an executable package that includes everything needed to run an application--the code, a runtime, libraries, environment variables, and configuration files. 12 | 13 | ## Docker Info 14 | 15 | `docker` | `docker container --help` | `docker -v` | `docker info` 16 | 17 | #### List Stuff 18 | 19 | `docker image ls` #all images locally 20 | 21 | `docker container ls` #all running 22 | `docker container ls --all` #all ever 23 | 24 | ### Clean Up 25 | 26 | ```bash 27 | # clean up any dangling resources(e.g layers unused now) 28 | docker system prune 29 | docker system prune -a # unused images too 30 | ``` -------------------------------------------------------------------------------- /All/Docker/multistage.md: -------------------------------------------------------------------------------- 1 | # Multistage builds 2 | 3 | Can have multiple `FROM` that start new step of build, cleaner than having multiple Dockerfiles 4 | 5 | ```dockerfile 6 | # Stage 1: Build Client 7 | FROM node:10.11.0-alpine as build 8 | WORKDIR /app 9 | 10 | # Install any needed packages specified 11 | COPY ./client/package.json . 12 | COPY ./client/yarn.lock . 13 | RUN yarn install 14 | 15 | # Copy the client contents into the container at /app 16 | COPY ./client . 17 | 18 | # build app 19 | RUN yarn build 20 | 21 | 22 | # Stage 2: Run backend that serves client statically 23 | FROM node:10.11.0-alpine 24 | WORKDIR /app 25 | 26 | # Copy build from previous container 27 | COPY --from=build /app/build /app/build 28 | 29 | # Install backend packages 30 | COPY ./backend/package.json . 31 | COPY ./backend/yarn.lock . 32 | RUN yarn install 33 | 34 | # Copy the backend contents into the container at /app 35 | COPY ./backend . 36 | 37 | EXPOSE 3001 38 | 39 | # Run yarn prod when container launches 40 | CMD ["yarn", "prod"] 41 | ``` 42 | 43 | -------------------------------------------------------------------------------- /All/Elixir/Phoenix/db_ecto/README.md: -------------------------------------------------------------------------------- 1 | # Ecto 2 | 3 | Data validation and db support for postgreSQL, mySQL, MSSQL 4 | 5 | Natural Elixir DSL/query engine to query abs 6 | 7 | Need to setup credentials in `config/dev.exs` 8 | 9 | -------------------------------------------------------------------------------- /All/Elixir/Phoenix/file_structure.md: -------------------------------------------------------------------------------- 1 | # Default File Structure 2 | 3 | - Can make a plug folder in web and then include in router.ex 4 | - Can import things in discuss_web.ex that will then be available in all views/controllers 5 | 6 | ├── build 7 | ├── assets 8 | ├── config 9 | ├── deps 10 | ├── lib 11 | └── hello 12 | └── hello_web 13 | └── hello.ex 14 | └── hello_web.ex 15 | ├── priv 16 | ├── test 17 | 18 | Lib/hello_web 19 | 20 | ``` 21 | ├── channels 22 | │ └── user_socket.ex 23 | ├── controllers 24 | │ └── page_controller.ex 25 | ├── templates 26 | │ ├── layout 27 | │ │ └── app.html.eex 28 | │ └── page 29 | │ └── index.html.eex 30 | └── views 31 | │ ├── error_helpers.ex 32 | │ ├── error_view.ex 33 | │ ├── layout_view.ex 34 | │ └── page_view.ex 35 | ├── endpoint.ex 36 | ├── gettext.ex 37 | ├── router.ex 38 | ``` 39 | 40 | -------------------------------------------------------------------------------- /All/Elixir/Phoenix/liveview.md: -------------------------------------------------------------------------------- 1 | # LiveView 2 | 3 | Severside rendering of components that uses sockets to automatically push data updates 4 | 5 | ```bash 6 | mix phx.new my_app --live 7 | ``` 8 | 9 | -------------------------------------------------------------------------------- /All/Elixir/Phoenix/packages/corsplug.md: -------------------------------------------------------------------------------- 1 | # CorsPlug 2 | 3 | ```elixir 4 | {:cors_plug, "~> 1.5"}, 5 | ``` 6 | 7 | -------------------------------------------------------------------------------- /All/Elixir/Phoenix/testing.md: -------------------------------------------------------------------------------- 1 | # Testing 2 | 3 | ```elixir 4 | defmodule KVTest do 5 | use ExUnit.Case 6 | doctest KV 7 | 8 | test "greets the world" do 9 | assert KV.hello() == :world 10 | end 11 | end 12 | ``` 13 | 14 | ```bash 15 | mix test 16 | ``` -------------------------------------------------------------------------------- /All/Elixir/Phoenix/token.md: -------------------------------------------------------------------------------- 1 | # [Phoenix.Token](https://hexdocs.pm/phoenix/Phoenix.Token.html) 2 | 3 | Phoenix built-in generate and verify signed tokens(not encrypted, so can verify data was signed not hide data) 4 | 5 | ```elixir 6 | user_id = 1 7 | token = Phoenix.Token.sign(ReactPhoenixWeb.Endpoint, "user auth", user_id) 8 | Phoenix.Token.verify(ReactPhoenixWeb.Endpoint, "user auth", token, max_age: 86400) #{:ok, 1} 9 | ``` 10 | 11 | Arg 1: Uses the secret key base configured in the endpoint 12 | 13 | Arg 2: [cryptographic salt](https://en.wikipedia.org/wiki/Salt_(cryptography)), kinda like a namespace 14 | 15 | ^Must be same in sign and verify 16 | 17 | Arg 3: What to codify in the string 18 | 19 | ## Extra 20 | 21 | Also has `encrypt` and `decrypt` 22 | 23 | -------------------------------------------------------------------------------- /All/Elixir/collections/set.md: -------------------------------------------------------------------------------- 1 | # [Set](https://hexdocs.pm/elixir/1.12/MapSet.html) 2 | 3 | ```elixir 4 | MapSet.new([2]) |> MapSet.put(4) |> MapSet.put(0) 5 | #MapSet<[0, 2, 4]> 6 | 7 | MapSet.member?(MapSet.new([1, 2, 3]), 2) 8 | ``` 9 | 10 | Get unique elements from list 11 | 12 | ```elixir 13 | list |> MapSet.new |> MapSet.to_list 14 | ``` 15 | 16 | -------------------------------------------------------------------------------- /All/Elixir/collections/strings.md: -------------------------------------------------------------------------------- 1 | # [String](https://hexdocs.pm/elixir/String.html#summary) 2 | 3 | ```elixir 4 | "hello" 5 | "string" <> "concat" 6 | 7 | x = 123 8 | x <> "hi" #error 9 | "#{x}hi" #123hi 10 | ``` 11 | 12 | String.reverse(str) 13 | 14 | String.upcase(str) 15 | 16 | String.downcase(str) 17 | 18 | String.capitalize(str) 19 | 20 | String.starts_with?(str) 21 | 22 | String.contains?(str, "search_str") 23 | 24 | String.first(str) 25 | 26 | String.at(str, index) 27 | 28 | String.slice(str, start_index, end_index) 29 | 30 | String.split("foo bar", "") 31 | 32 | String.length("foo bar") 33 | 34 | ### Atoms 35 | 36 | An atom is a constant whose value is its own name 37 | 38 | `true`, `false`, and `nil` are atoms, but can skip `:` 39 | 40 | ```elixir 41 | :apple 42 | :ok != :error 43 | :true == true 44 | is_atom(false) # => true 45 | true and true 46 | false or not true 47 | 1 and true # => raises exception 48 | Atom.to_string(:foo) 49 | ``` 50 | 51 | _Atoms are not garbage collected, so never convert user input to atoms_ 52 | 53 | -------------------------------------------------------------------------------- /All/Elixir/collections/structs.md: -------------------------------------------------------------------------------- 1 | # Structs 2 | 3 | Structs are extensions built on top of maps that provide default values and compile-time guarantees that only the defined fields exist. 4 | 5 | Structs are **bare** maps which means you can't enumerate or [] a struct. But you can use `Map.` functions 6 | 7 | ### Creating 8 | 9 | ```elixir 10 | defmodule User do 11 | defstruct name: "John", age: 27 12 | end 13 | ``` 14 | 15 | ```elixir 16 | iex> %User{} 17 | %User{age: 27, name: "John"} 18 | iex> %User{name: "Jane"} 19 | %User{age: 27, name: "Jane"} 20 | ``` 21 | 22 | -------------------------------------------------------------------------------- /All/Elixir/collections/tuple.md: -------------------------------------------------------------------------------- 1 | # Tuples 2 | 3 | Can hold any value, but not for enumeration 4 | 5 | Arrays continuous in memory, but new ones require new continuous memory. Contents aren't copied, contents are shared 6 | 7 | ```elixir 8 | my_stats = {175, 5.25, :Derek} 9 | IO.puts "Tuple ${is_tuple(my_stats)}" 10 | my_stats2 = Tuple.append(my_stats, 42) 11 | IO.puts "Age: #{elem(my_stats2, 3)}" 12 | IO.puts "Size: #{tuple_size(my_stats2, 3)}" 13 | my_stats3 = Tuple.delete_at(my_stats2, 0) 14 | my_stats4 = Tuple.insert_at(my_stats3, 0, 1974) 15 | many_zeroes = Tuple.duplicate(0, 5) 16 | 17 | {weight, height, name} = {175, 6.25, "Derek"} 18 | IO.puts "Weight: #{weight}" 19 | ``` 20 | 21 | #### Turn List of Tuples Into A Map 22 | 23 | ```elixir 24 | [a: 1, b: 2] |> Enum.into(%{}) #%{a: 1, b: 2} 25 | ``` 26 | 27 | -------------------------------------------------------------------------------- /All/Elixir/config.md: -------------------------------------------------------------------------------- 1 | # Config 2 | 3 | Each application has its own environment. 4 | 5 | `config/config.exs` is base of every project 6 | 7 | config/dev.exs 8 | 9 | ```elixir 10 | import_config "dev.secret.exs" 11 | ``` 12 | 13 | config/dev.secrets.exs 14 | 15 | ```elixir 16 | use Mix.Config 17 | 18 | config :sonar, 19 | google: "fasfdajkl" 20 | ``` 21 | 22 | #### Usage 23 | 24 | ```elixir 25 | Application.fetch_env!(:sonar, :google) 26 | Application.get_env(:sonar, :google, :default) #allows default and no error if key doesn't exist 27 | ``` 28 | 29 | ### Based on env 30 | 31 | ```elixir 32 | if Mix.env() == :dev do 33 | #... can even be in router 34 | end 35 | ``` 36 | 37 | ## Runtime.ex vs Prod.ex 38 | 39 | Simply: 40 | 41 | - `releases.exs` - runtime configuration for `release` **only** 42 | - `#{Mix.env()}.exs` - i.e. `dev.exs`, `prod.exs`, `test.exs` - those are compiletime environment-specific configuration files 43 | - `config.exs` - compiletime generic configuration file 44 | - `releases.exs` - runtime generic configuration file 45 | -------------------------------------------------------------------------------- /All/Elixir/erlang.md: -------------------------------------------------------------------------------- 1 | # Erlang 2 | 3 | Built by telecoms systems(Ericson in 1970s ) and run most of the worlds communications(5 9's more with Erlang) 4 | 5 | Erlang is highly scalable and lightweight, like can be its own OS on very lightweight systems(100x smaller/startup time) 6 | 7 | Very reliablity b/c not general purpose, runs threadlike erlang code only(scales linear up to 50 cores) 8 | 9 | Each process runs 1000 cycles then gives up, processes can't block or anything. So multicores parallelism, balancing across cores, and adding more processes is trivial and automatic. Can take yourself out of rotation while waiting for messages(IO too). And rebooting when process crash is automatic. Low latecny over throughput. 10 | 11 | ### OTP 12 | 13 | Supervisor looks over Genserver 14 | 15 | Erlang used by Heroku, WhatsApp(2 million connections on a single machine); 16 | 17 | -------------------------------------------------------------------------------- /All/Elixir/file.md: -------------------------------------------------------------------------------- 1 | # File 2 | 3 | - Mostly named after UNIX equivalents like rm/1, mkdir/1, mkdir_p/1, cp_r/2, rm_rf/1 4 | - Two variants, one regular and one with trailing bang. Use bang if you don't handle error 5 | 6 | Get raw contents 7 | 8 | ```elixir 9 | case File.read(file) do 10 | {:ok, body} -> # do something with the `body` 11 | {:error, reason} -> # handle the error caused by `reason` 12 | end 13 | File.read!("existing") # "... contents ..." 14 | File.read!("unknown") #**(File.Error) ... 15 | ``` 16 | 17 | Open for read and write 18 | 19 | ```elixir 20 | {:ok, file} = File.open("hello", [:write]) # {:ok, #PID<0.47.0>} 21 | IO.binwrite(file, "world") #:ok 22 | File.close(file) #:ok 23 | File.read("hello") #{:ok, "world"} 24 | ``` 25 | 26 | ## Path 27 | 28 | ```elixir 29 | iex> Path.join("foo", "bar") 30 | "foo/bar" 31 | iex> Path.expand("~/hello") 32 | "/Users/jose/hello" 33 | ``` 34 | 35 | -------------------------------------------------------------------------------- /All/Elixir/math.md: -------------------------------------------------------------------------------- 1 | # Math 2 | 3 | All ops normal, except `/` always returns float 4 | 5 | div(5, 4) is integer division => 1 6 | 7 | rem(5, 4) is modulo => 1 8 | 9 | Float, Integer different and different libs 10 | 11 | Kernel has functions that work on many 12 | 13 | ```elixir 14 | easiness_factor = (card.easiness_factor + (0.1 - (5 - q) * (0.08 + (5 - q) * 0.02))) |> Float.round(3) |> Kernel 15 | ``` 16 | 17 | ## Kernel 18 | 19 | - .min 20 | - .max 21 | - .round - to nearest integer 22 | 23 | Random Number 24 | 25 | ```elixir 26 | :rand.uniform(n) #1-n inclusive 27 | ``` 28 | 29 | -------------------------------------------------------------------------------- /All/Elixir/modules.md: -------------------------------------------------------------------------------- 1 | # [Modules](https://hexdocs.pm/elixir/master/Module.html) 2 | 3 | ```elixir 4 | # Alias the module so it can be called as Bar instead of Foo.Bar 5 | alias Foo.Bar, as: Bar 6 | alias Foo.Bar #defaults to name after .(Bar) 7 | # Require the module in order to use its macros 8 | require Foo 9 | # Import functions from Foo so they can be called without the `Foo.` prefix 10 | import Foo 11 | # Invokes the custom code defined in Foo as an extension point 12 | use Foo 13 | ``` 14 | 15 | ## Attributes 16 | 17 | #### Impl 18 | 19 | When you use a module then want to implement the functions you can use `@impl true` to indicate what you think a callback is, it will do typechecking matching it 20 | 21 | - Will error if you do it once and not every time 22 | 23 | ```elixir 24 | @impl true 25 | def init(state) do 26 | {:ok, state} 27 | end 28 | 29 | @impl true 30 | def start_link do 31 | GenServer.start_link(__MODULE__, 0) 32 | end 33 | ``` 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /All/Elixir/packages/README.md: -------------------------------------------------------------------------------- 1 | # Packages 2 | 3 | To add a package, you need to add a line to 4 | 5 | mix.exs 6 | 7 | ```elixir 8 | defp deps do 9 | [ 10 | #..... 11 | {:plug_cowboy, "~> 2.0"}, 12 | {:httpoison, "~> 1.6"} 13 | ] 14 | end 15 | ``` 16 | 17 | Then run `mix deps.get` 18 | 19 | ### Version 20 | 21 | ```elixir 22 | # Only version 2.0.0 23 | "== 2.0.0" 24 | 25 | # Anything later than 2.0.0 26 | "> 2.0.0" 27 | 28 | # 2.0.0 and later until 2.1.0 29 | ">= 2.0.0 and < 2.1.0" 30 | # Equivalent to 31 | "~> 2.0.0" 32 | ``` 33 | 34 | ### [Updating](https://inquisitivedeveloper.com/lwm-elixir-58/) 35 | 36 | ```bash 37 | mix hex.outdated #to see what packages have newer versions 38 | mix deps.update --all #updates minor versions of all deps 39 | # Need to manually change mix.exs to update major version 40 | ``` 41 | 42 | ### Packages of Interest 43 | 44 | - [guardian](https://github.com/ueberauth/guardian) 45 | - Genstage, broadway 46 | -------------------------------------------------------------------------------- /All/Elixir/packages/geolix.md: -------------------------------------------------------------------------------- 1 | # Geolix 2 | 3 | With geolix you can do ip address to location mapping 4 | 5 | ## Setup 6 | 7 | 1) Get links to mmbd2 database [here](https://www.maxmind.com/en/geolite2/thank-you), you will have to make an account and generate a license link 8 | 9 | 2) Install deps 10 | 11 | ```elixir 12 | {:geolix, "~> 2.0"}, 13 | {:geolix_adapter_mmdb2, "~> 0.6.0"}, 14 | ``` 15 | 16 | 3) Config 17 | 18 | ```elixir 19 | config :geolix, databases: [ 20 | %{ 21 | id: :city, 22 | adapter: Geolix.Adapter.MMDB2, 23 | source: "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=LICEN_SEKY&suffix=tar.gz" 24 | }, 25 | %{ 26 | id: :country, 27 | adapter: Geolix.Adapter.MMDB2, 28 | source: "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=LICEN_SEKY&suffix=tar.gz" 29 | } 30 | ] 31 | ``` 32 | 33 | ## Usage 34 | 35 | ```elixir 36 | Geolix.lookup("45.50.161.38") 37 | ``` 38 | 39 | -------------------------------------------------------------------------------- /All/Elixir/packages/http/http.md: -------------------------------------------------------------------------------- 1 | # HTTP 2 | 3 | Look into [Tesla](https://hexdocs.pm/tesla/readme.html) as its a general wrapper around all these underlying clients 4 | 5 | 6 | 7 | https://elixirforum.com/t/mint-vs-finch-vs-gun-vs-tesla-vs-httpoison-etc/38588/11 -------------------------------------------------------------------------------- /All/Elixir/packages/json.md: -------------------------------------------------------------------------------- 1 | ## Jason 2 | 3 | ```elixir 4 | {:jason, "~> 1.2"} 5 | ``` 6 | 7 | ## Usage 8 | 9 | ```elixir 10 | Jason.encode!(%{"age" => 44, "name" => "Steve Irwin", "nationality" => "Australian"}) 11 | #"{\"age\":44,\"name\":\"Steve Irwin\",\"nationality\":\"Australian\"}" 12 | 13 | Jason.decode!(~s({"age":44,"name":"Steve Irwin","nationality":"Australian"})) 14 | #%{"age" => 44, "name" => "Steve Irwin", "nationality" => "Australian"} 15 | ``` 16 | 17 | ### Worse JSON 18 | 19 | ```elixir 20 | {:json, "~> 1.2"} 21 | ``` 22 | 23 | #### Usage 24 | 25 | ```elixir 26 | {status, result} = JSON.encode(list) 27 | 28 | json_input = "{\"key\":\"this will be a value\"}" 29 | {status, list} = JSON.decode(json_input) 30 | ``` 31 | 32 | -------------------------------------------------------------------------------- /All/Elixir/packages/nanoid.md: -------------------------------------------------------------------------------- 1 | # [Nanoid](https://github.com/railsmechanic/nanoid) 2 | 3 | A port of nodes nano_id which is a small, url safe, id generator that is better than uuid because it uses more letters allowing it to be 21 letters instead of 36. 4 | 5 | ```elixir 6 | {:nanoid, "~> 2.0.2"}, 7 | ``` 8 | 9 | 10 | 11 | ```elixir 12 | Nanoid.generate(12) 13 | ``` 14 | 15 | -------------------------------------------------------------------------------- /All/Elixir/packages/stripe.md: -------------------------------------------------------------------------------- 1 | # Stripe 2 | 3 | ```elixir 4 | {:stripity_stripe, "~> 2.0"} 5 | ``` 6 | 7 | -------------------------------------------------------------------------------- /All/Elixir/packages/swoosh.md: -------------------------------------------------------------------------------- 1 | # Swoosh 2 | 3 | Might come with phoenix now unclear 4 | 5 | Config.exs 6 | 7 | ```elixir 8 | # Configures the mailer 9 | config :react_phoenix, ReactPhoenix.Mailer, 10 | adapter: Swoosh.Adapters.Postmark, 11 | api_key: System.get_env("POSTMARK_API_KEY") 12 | 13 | # Swoosh API client is needed for adapters other than SMTP. 14 | config :swoosh, :api_client, Swoosh.ApiClient.Hackney 15 | ``` 16 | 17 | ReactPhoenix.Mailer 18 | 19 | ```elixir 20 | defmodule ReactPhoenix.Mailer do 21 | use Swoosh.Mailer, otp_app: :react_phoenix 22 | end 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /All/Elixir/time.md: -------------------------------------------------------------------------------- 1 | # Time 2 | 3 | See timex for more advanced stuff 4 | 5 | #### DateTime 6 | 7 | Utc_now is the same type as timestamps from db 8 | 9 | ```elixir  10 | now = DateTime.utc_now() #~U[2020-12-07 01:09:48.868084Z] 11 | nowUTC = DateTime.utc_now() |> DateTime.to_unix() #1607303503 12 | ``` 13 | 14 | Compare 15 | 16 | ```elixir 17 | def is_current_subevent(se) do 18 | now = DateTime.utc_now() 19 | start_cmp = DateTime.compare(now, se.start_time) 20 | end_cmp = DateTime.compare(now, se.end_time) 21 | start_cmp === :gt && end_cmp === :lt 22 | end 23 | ``` 24 | 25 | #### Naive DateTime 26 | 27 | ```elixir  28 | now = NaiveDateTime.utc_now() 29 | # 7 hour diff PST, so 19 30 | tomorrow_noon = 31 | NaiveDateTime.new(now.year, now.month, now.day, 19, 0, 0) 32 | |> (fn {:ok, d} -> d end).() 33 | |> NaiveDateTime.add(60 * 60 * 24, :second) 34 | 35 | tomorrow_one = tomorrow_noon |> NaiveDateTime.add(60 * 60, :second) 36 | ``` 37 | 38 | #### Erlang Standard 39 | 40 | Get current time with `:calendar.universal_time()` or `:calendar.local_time()` 41 | 42 | -------------------------------------------------------------------------------- /All/Elixir/uri.md: -------------------------------------------------------------------------------- 1 | # URI 2 | 3 | ```elixir 4 | uri_string = 5 | base_url 6 | |> URI.parse() 7 | |> Map.put(:query, URI.encode_query(params)) 8 | |> URI.to_string() 9 | ``` 10 | 11 | -------------------------------------------------------------------------------- /All/Go/.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jsfuentes/Code-Cheatsheet/30a9cd5ee04200b17ec711d162d8714bb3b7b550/All/Go/.md -------------------------------------------------------------------------------- /All/Go/assert.md: -------------------------------------------------------------------------------- 1 | # Assert 2 | 3 | `import "github.com/stretchr/testify/assert"` 4 | 5 | ### Basic Example 6 | 7 | ```go 8 | import ( 9 | "testing" 10 | "github.com/stretchr/testify/assert" 11 | ) 12 | 13 | func TestSomething(t *testing.T) { 14 | assert.Equal(t, "Hi", "Hi", "The two words should be the same.") 15 | } 16 | ``` 17 | 18 | ## Common 19 | 20 | - .Equal 21 | - .Error 22 | - .NoError 23 | - .True 24 | - .False -------------------------------------------------------------------------------- /All/Go/collections/README.md: -------------------------------------------------------------------------------- 1 | ## Collections 2 | 3 | len([some col]) 4 | 5 | Go passes a copy of collections by default 6 | 7 | `sort` package has sorting e.g `sort.Strings([collection])` 8 | 9 | ### Iteration 10 | 11 | ```go 12 | for i := range colors { //set i to current index 13 | fmt.Println(colors[i]) 14 | } 15 | ``` 16 | 17 | ## usage 18 | 19 | - `len(colors)` 20 | 21 | -------------------------------------------------------------------------------- /All/Go/collections/maps.md: -------------------------------------------------------------------------------- 1 | ## Maps 2 | 3 | Create 4 | 5 | ```go 6 | var states map[string]string 7 | states := make(map[string]string) 8 | commits := map[string]int{ 9 | "rsc": 3711, 10 | "r": 2138, 11 | "gri": 1908, 12 | "adg": 912, 13 | } 14 | ``` 15 | 16 | Get and set 17 | 18 | ```go 19 | states["CA"] = "California" 20 | california := states["CA"] 21 | cal, ok := s["CCCC"] //opt ok 22 | ``` 23 | 24 | - if the key does not exist, then the zero of the value type is returned(0 for int, "" for string) and ok is false 25 | 26 | Delete 27 | 28 | ```go 29 | delete(states, "CA") //[] 30 | ``` 31 | 32 | Iterate 33 | 34 | ```go 35 | for k, v := range states { 36 | fmt.Printf("%v, %v\n", k, v) 37 | } 38 | ``` 39 | 40 | List 41 | 42 | ```go 43 | key := make([]string, len(states)) 44 | i := 0 45 | for k := range states { 46 | keys[i] = k 47 | i++ 48 | } 49 | ``` 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /All/Go/dep.md: -------------------------------------------------------------------------------- 1 | # Go Get Vs Dep 2 | 3 | - go get more for consumers of go code 4 | - dep for developers to manage version and the like 5 | 6 | ## Go Get 7 | 8 | ### Installation 9 | 10 | `go get github.com/tensorflow/tensorflow/tensorflow/go` 11 | 12 | Fetch, build, and install remote package into workspace defined by $GOPATH \ 13 | 14 | ### Usage 15 | 16 | ```go 17 | package main 18 | 19 | import ( 20 | tf "github.com/tensorflow/tensorflow/tensorflow/go" //access with tf. 21 | "github.com/tensorflow/tensorflow/tensorflow/go/op" //access with op. 22 | "fmt" 23 | ) 24 | 25 | func main() { 26 | // Construct a graph with an operation that produces a string constant. 27 | s := op.NewScope() 28 | c := op.Const(s, "Hello from TensorFlow version " + tf.Version()) 29 | } 30 | ``` 31 | 32 | -------------------------------------------------------------------------------- /All/Go/interfaces.md: -------------------------------------------------------------------------------- 1 | ## Interfaces 2 | 3 | No keyword like extends, if you implement all the methods then you can be that type 4 | 5 | So everything is the empty `interface{}` 6 | 7 | ```go 8 | type Animal interface { 9 | Speak() string 10 | } 11 | ``` 12 | 13 | ### Usage 14 | 15 | ```go 16 | type Dog struct { 17 | //... 18 | } 19 | 20 | func (d Dog) Speak() string { 21 | return "Woof" 22 | } 23 | 24 | func main() { 25 | poodle:= Animal(Dog()) //cast as Animal 26 | } 27 | ``` 28 | 29 | ## The empty interface 30 | 31 | - Specifies no methods 32 | - May hold values of any type like fmt.Println 33 | 34 | ``` 35 | interface{} 36 | ``` 37 | 38 | An empty interface may hold values of any type. (Every type implements at least zero methods.) -------------------------------------------------------------------------------- /All/Go/math.md: -------------------------------------------------------------------------------- 1 | # Math 2 | 3 | common ops 4 | 5 | ```go 6 | var int1 int = 5 7 | var float1 float64 = 42 8 | sum := float64(int1) + float1 9 | ``` 10 | 11 | #### `math` packageeee 12 | 13 | math.Pi 14 | 15 | #### Big Num to get precision 16 | 17 | ```go 18 | import "math/big" 19 | 20 | var b1, b2, b3, bigSum big.Float 21 | b1.SetFloat64(23.5) 22 | b2.SetFloat64(65.1) 23 | b3.SetFloat64(76.3) 24 | 25 | bigSum.Add(&b1, &b2).Add(&bigSum, &b3) 26 | fmt.Printf("BigSum = %.10g\n", &bigSum) 27 | ``` 28 | 29 | ### Converstion 30 | 31 | ```go 32 | price, _, _ := big.ParseFloat(p, 10, 2, big.ToZero) //base 10, precision 2, rounding mode tozero 33 | ``` 34 | 35 | -------------------------------------------------------------------------------- /All/Go/request.md: -------------------------------------------------------------------------------- 1 | # Request 2 | 3 | ```go 4 | import ( 5 | "fmt" 6 | "net/http" 7 | "io/ioutil" 8 | ) 9 | ``` 10 | 11 | Get returns http.Response 12 | 13 | ```go 14 | resp, err := http.Get(url) 15 | checkErr(err) 16 | 17 | fmt.Printf("Response type: %T\n", resp) 18 | ``` 19 | 20 | ### Work with Data 21 | 22 | ```go 23 | resp, err := http.Get(url) 24 | checkErr(err) 25 | 26 | defer resp.Body.Close() 27 | 28 | bytes, err := ioutil.ReadAll(resp.Body) 29 | checkErr(err) 30 | 31 | content := string(bytes) 32 | ``` 33 | 34 | -------------------------------------------------------------------------------- /All/Go/server.md: -------------------------------------------------------------------------------- 1 | # Simple Server 2 | 3 | ```go 4 | import ( 5 | "fmt" 6 | "net/http" 7 | ) 8 | ``` 9 | 10 | 11 | 12 | ## Serving 13 | 14 | Have a struct that has a func, ServeHTTP will be called to service requests 15 | 16 | ```go 17 | type Hello struct {} 18 | 19 | func (h Hello) ServeHTTP(w http.ResponseWriter, r *http.Request) { 20 | fmt.Fprint(w, "

Hello from Go

")//print to writer object 21 | } 22 | ``` 23 | 24 | #### Usage 25 | 26 | ```go 27 | func main() { 28 | var h Hello 29 | err := http.ListenAndServe("localhost:4000", h) 30 | checkError(err) 31 | } 32 | ``` 33 | 34 | -------------------------------------------------------------------------------- /All/Go/structs.md: -------------------------------------------------------------------------------- 1 | # Structs 2 | 3 | No inheritance 4 | 5 | ```go 6 | type Dog struct { 7 | Breed string 8 | Weight int 9 | } 10 | 11 | type Cat struct { 12 | } 13 | ``` 14 | 15 | ##### Creation 16 | 17 | ```go 18 | poodle := Dog{"Poodle", 34} 19 | poodle := Dog{Breed: "Poodle", Weight: 34} 20 | jaguar := Cat{} 21 | ``` 22 | 23 | ##### Printing 24 | 25 | ```go 26 | fmt.Println(poodle) //outputs "Poodle 34" 27 | fmt.Printf("%+v", poodle) //outputs {Breed:Poodle Weight:34} 28 | ``` 29 | 30 | ## Methods 31 | 32 | After declaring a type as above 33 | 34 | ```go 35 | type Dog struct { 36 | Sound string 37 | } 38 | 39 | //recieves Dog;; pass by val 40 | func (d Dog) Speak() { 41 | fmt.Println(d.Sound) 42 | } 43 | 44 | //pass d by ref 45 | func (d *Dog) doubleDog() { 46 | d.Sound = fmt.Sprintf("%v! %v!\n", d.Sound, d.Sound) 47 | fmt.Print(d.Sound) 48 | } 49 | ``` 50 | 51 | -------------------------------------------------------------------------------- /All/Go/testing.md: -------------------------------------------------------------------------------- 1 | # Testing 2 | 3 | ```go 4 | import ( 5 | "testing" 6 | 7 | "assistant/knowledge/data/json" 8 | 9 | "github.com/stretchr/testify/assert" 10 | ) 11 | 12 | func TestTransformHerePhoneNumber(t *testing.T) { 13 | rawNumberOnlyNumbers := "6783108763" 14 | res, err := transformHerePhoneNumber(nil, "", rawNumberOnlyNumbers, "", "", nil, nil, nil) 15 | assert.NoError(t, err) 16 | assert.Equal(t, res, "(678)310-8763") 17 | } 18 | ``` 19 | 20 | -------------------------------------------------------------------------------- /All/Go/time.md: -------------------------------------------------------------------------------- 1 | # Dates 2 | 3 | Time package 4 | 5 | Package 6 | 7 | - `.Now()` 8 | 9 | Object 10 | 11 | - `.Month()`, `.Day()`, `.Weekday()` 12 | - `.addDate(0, 0, 1) 13 | 14 | ```go 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | "time" 20 | ) 21 | 22 | func main() { 23 | t := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC) 24 | fmt.Printf("Go launched at %s\n", t) 25 | 26 | now := time.Now() 27 | 28 | } 29 | ``` 30 | 31 | ## Creating your format 32 | 33 | Based on Jan 2nd 3rd hours 4 minute 5 second and 6 year and -7 Time zone 34 | 35 | ```go 36 | longFormat := "Monday, Janurary 2, 2006" 37 | shortFormat := "1/2/06" 38 | fmt.Println("Tomorrow is", time.Now().Format(longFormat)) 39 | ``` 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /All/HTML/Fun.md: -------------------------------------------------------------------------------- 1 | ## Fun Useless Tags 2 | 3 |
//horizontal line 4 | hi //scrolling line -------------------------------------------------------------------------------- /All/HTML/SEO.md: -------------------------------------------------------------------------------- 1 | # SEO 2 | 3 | In the head tag, good to include a descriptive title and meta description 4 | 5 | ```html 6 | 7 | Modulo - The Publishing Platform for Developers 8 | ``` 9 | 10 | [Special Tags that google understands](https://support.google.com/webmasters/answer/79812) 11 | 12 | ### Dynamically Setting Meta 13 | 14 | Most crawlers just use the server direct meta tag. Can't use something like react helmet here. Should set on server so when pinged directly works. Its fine that react-router redirection doesn't update meta, you care about crawlers accessing directly. 15 | 16 | https://create-react-app.dev/docs/title-and-meta-tags/#generating-dynamic-meta-tags-on-the-server -------------------------------------------------------------------------------- /All/HTML/Templating/README.md: -------------------------------------------------------------------------------- 1 | # TEMPLATING 2 | 3 | ## Intro 4 | 5 | - combination of data and layout 6 | - data and presentation are seperate 7 | - usually used to format repeating item 8 | 9 | ## Before Templating 10 | ```js 11 | var htmlStr = "
" + 12 | "
" + person.Name + "
" + 13 | "
" + person.Phone + "
" + 14 | "
" + person.Address + "
" + 15 | "
"; 16 | ``` 17 | 18 | SPecify placeholders dont worry about syntax 19 | 20 | twitter 21 | 22 | ## Quick Survey of JS Templating 23 | - jQuery Templating 24 | - Mustache 25 | - Handlebars 26 | - Backend Servers often have templating 27 | - ejx, pug, jade and node 28 | - python flask and jinja2 29 | - ruby on rails 30 | - php 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /All/HTML/favicon.md: -------------------------------------------------------------------------------- 1 | # Favicon 2 | 3 | ## Finding a urls favicon 4 | 5 | Simplest, google internal service 6 | 7 | https://www.google.com/s2/favicons?domain=www.stackoverflow.com 8 | 9 | [Manual solution](https://stackoverflow.com/questions/5119041/how-can-i-get-a-web-sites-favicon) 10 | 11 | 1. Look for the `favicon.ico` at the root of the domain 12 | 13 | `www.domain.com/favicon.ico` 14 | 15 | 2. Look for a `` tag with the `rel="shortcut icon"` attribute 16 | 17 | `` 18 | 19 | 3. Look for a `` tag with the `rel="icon"` attribute 20 | 21 | `` 22 | 23 | -------------------------------------------------------------------------------- /All/HTML/optimizations.md: -------------------------------------------------------------------------------- 1 | # Optimizations 2 | 3 | ### Preconnect to Required Origins 4 | 5 | ##### Preconnect 6 | 7 | Easy to manage 8 | 9 | ```html 10 | 11 | ``` 12 | 13 | pretty cheap; should be used within 10 seconds 14 | 15 | Can save like .3ms 16 | 17 | ##### Preload 18 | 19 | `` informs the browser that a resource is needed as part of the current navigation, and that it should start getting fetched as soon as possible. 20 | 21 | Edge cases b/c this isnt a hint it mandates the browser grabs it 22 | 23 | ```html 24 | 25 | 26 | ``` 27 | 28 | Should be used within 3 seconds 29 | 30 | -------------------------------------------------------------------------------- /All/HTML/scripts.md: -------------------------------------------------------------------------------- 1 | # Scripts 2 | 3 | ### defer 4 | 5 | wait to load script until DOM finishes loading, only for external scripts 6 | 7 | ```js 8 | 9 | ``` 10 | 11 | You should defer loading all CSS files that are blocking the rendering of your page. -------------------------------------------------------------------------------- /All/Php/AMP.md: -------------------------------------------------------------------------------- 1 | # AMP 2 | 3 | Apache MySQL and PHP 4 | 5 | #### Apache 6 | - Apache Server `sudo apachectl start` then navigate to localhost:80, 7 | - need to restart everytime `sudo apachectl restart` 8 | - `http -v` 9 | - `cd /etc/apache2` 10 | - use emacs to edit httpd.conf 11 | - `cd /Library/WebServer/Documents` has the index.html.en that is run by default and is locked down 12 | - could edit that default folder if you want, but .... 13 | 14 | 15 | #### Php 16 | - Macs come preinstalled with php and apache 17 | - To just run the php file put `#!/usr/bin/php` at the top of php page, or `#!/usr/local/bin/php -d display_errors=STDOUT` for errors 18 | - Files with extension .php are run through the php processor when run and return a html page 19 | - Put in the preconfigured sites folder for use, navigate with `localhost/~jfuentes/[filename.php]` 20 | 21 | #### SQLite 22 | - Also preinstalled 23 | - `sqlite3` 24 | -------------------------------------------------------------------------------- /All/Php/Hack.md: -------------------------------------------------------------------------------- 1 | # Hack 2 | 3 | Typed PHP 4 | 5 | - explicit and verified typing 6 | - async 7 | - better arrays and memoization 8 | - Memoization - per request, can just add -------------------------------------------------------------------------------- /All/Php/requests.md: -------------------------------------------------------------------------------- 1 | # Handling Requests with PHP 2 | 3 | ### Calling in HTML 4 | ```HTML 5 |
6 | ``` 7 | - `GET` will link to page and pass in url 8 | - `POST` will link to page and pass in request body 9 | 10 | ### Superglobals 11 | - Variables \$\_GET \$\_POST, \$\_REQUEST, $\_COOKIE 12 | - Request is a combo superglobal and gets get and post 13 | - Test with `var_dump($_GET)` 14 | - These are associative arrays so just use ['key'] to access 15 | 16 | ### Returning 17 | - `echo` 18 | 19 | ## Submit to yourself 20 | - Can make form submit to itself `action=""` 21 | - Before processing do, `if(($\_SERVER['REQUEST_METHOD'] == 'POST') && (!empty($\_POST['action'])));` 22 | 23 | ### Validation 24 | - if else preg_match, `preg_match('re', str)` 25 | 26 | ### Form Specifics 27 | - Names must be different 28 | - If you have like a checkbox with the same name, can make `name=music[]` which will make it an array 29 | - echoing `echo checked` at the end of checkbox input tag will check box 30 | -------------------------------------------------------------------------------- /All/Python/Django/db.md: -------------------------------------------------------------------------------- 1 | # Databases 2 | 3 | Default is sqlite3 because it comes with python, but can use postgres and more 4 | 5 | Default installed apps require a db and migrations 6 | 7 | See setup.md for setup instructions 8 | 9 | ```bash 10 | poetry run python manage.py sqlmigrate polls 0001 #to see what SQL will run 11 | poetry run python manage.py check #check for db errors 12 | ``` 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /All/Python/Django/packages/django-environ.md: -------------------------------------------------------------------------------- 1 | # Secrets 2 | 3 | ```bash 4 | poetry add django-environ 5 | ``` 6 | 7 | In `settings.py` 8 | 9 | ```python 10 | import environ 11 | 12 | # Initialise environment variables 13 | env = environ.Env() 14 | environ.Env.read_env() 15 | ``` 16 | 17 | Then make a `.env` 18 | 19 | ```bash 20 | SECRET_KEY=h^z13$qr_s_wd65@gnj7a=xs7t05$w7q8!x_8zsld 21 | DATABASE_NAME=postgresdatabase 22 | DATABASE_USER=alice 23 | DATABASE_PASS=supersecretpassword 24 | ``` 25 | 26 | And finally, replace secretes with `env("SECRET_NAME")` 27 | 28 | ```python 29 | DATABASES = { 30 | ‘default’: { 31 | ‘ENGINE’: ‘django.db.backends.postgresql_psycopg2’, 32 | ‘NAME’: env(‘DATABASE_NAME’), 33 | ‘USER’: env(‘DATABASE_USER’), 34 | ‘PASSWORD’: env(‘DATABASE_PASS’), 35 | } 36 | } 37 | ``` -------------------------------------------------------------------------------- /All/Python/Django/router.md: -------------------------------------------------------------------------------- 1 | # Router 2 | 3 | In the `app/urls.py`, add if it doesn't exist 4 | 5 | ```python 6 | from django.urls import path 7 | 8 | from . import views 9 | 10 | urlpatterns = [ 11 | path('', views.index, name='index'), 12 | path('/results', views.detail, name='detail'), 13 | ] 14 | ``` 15 | 16 | Then in the `project/urls.py`, where polls is the app folder name 17 | 18 | ```python 19 | from django.contrib import admin 20 | from django.urls import include, path 21 | 22 | urlpatterns = [ 23 | path('polls/', include('polls.urls')), #sends remaining url to the includes 24 | path('', admin.site.urls), 25 | ] 26 | ``` 27 | 28 | -------------------------------------------------------------------------------- /All/Python/Django/serializers.md: -------------------------------------------------------------------------------- 1 | # Serializers 2 | 3 | `app/serializers.py` 4 | 5 | ```python 6 | from rest_framework import serializers 7 | from .models import Todo 8 | 9 | class TodoSerializer(serializers.ModelSerializer): 10 | class Meta: 11 | model = Todo 12 | fields = ('id', 'title', 'description', 'completed') 13 | ``` 14 | 15 | `app/views.py` 16 | 17 | ```python 18 | from django.shortcuts import render 19 | from rest_framework import viewsets 20 | from .serializers import TodoSerializer 21 | from .models import Todo 22 | 23 | # Create your views here. 24 | 25 | class TodoView(viewsets.ModelViewSet): 26 | serializer_class = TodoSerializer 27 | queryset = Todo.objects.all() 28 | ``` 29 | 30 | -------------------------------------------------------------------------------- /All/Python/Django/views.md: -------------------------------------------------------------------------------- 1 | # Views 2 | 3 | `app/views.py` 4 | 5 | ```python 6 | from django.http import HttpResponse 7 | from django.http import Http404 8 | from django.shortcuts import render 9 | 10 | from .models import Question 11 | 12 | def index(request): 13 | latest_question_list = Question.objects.order_by('-pub_date')[:5] 14 | context = {'latest_question_list': latest_question_list} 15 | return render(request, 'polls/index.html', context) 16 | 17 | def detail(request, question_id): 18 | return HttpResponse("You're looking at question %s." % question_id) 19 | 20 | def detail(request, question_id): 21 | try: 22 | question = Question.objects.get(pk=question_id) 23 | except Question.DoesNotExist: 24 | raise Http404("Question does not exist") 25 | return render(request, 'polls/detail.html', {'question': question}) 26 | #Equivalent to 27 | def detail(request, question_id): 28 | question = get_object_or_404(Question, pk=question_id) 29 | return render(request, 'polls/detail.html', {'question': question}) 30 | ``` 31 | 32 | -------------------------------------------------------------------------------- /All/Python/advanced.md: -------------------------------------------------------------------------------- 1 | # Advanced Stuff 2 | 3 | - `globals()` *always* returns the dictionary of the *module* namespace 4 | - `locals()` *always* returns *a* dictionary of the *current* namespace 5 | 6 | print(locals()) will let you do some easy debugging (in fts, extra stuff in global namespace) -------------------------------------------------------------------------------- /All/Python/argparse.md: -------------------------------------------------------------------------------- 1 | # Argparse 2 | 3 | For command line stuff 4 | 5 | ```python 6 | import scipy, cv2, os, sys, argparse, audio 7 | 8 | parser = argparse.ArgumentParser(description='Inference code to lip-sync videos in the wild using Wav2Lip models') 9 | 10 | parser.add_argument('--checkpoint_path', type=str, 11 | help='Name of saved checkpoint to load weights from', required=True) 12 | 13 | parser.add_argument('--face', type=str, 14 | help='Filepath of video/image that contains faces to use', required=True) 15 | parser.add_argument('--audio', type=str, 16 | help='Filepath of video/audio file to use as raw audio source', required=True) 17 | parser.add_argument('--outfile', type=str, help='Video path to save result. See default for an e.g.', 18 | default='results/result_voice.mp4') 19 | 20 | args = parser.parse_args() 21 | args.img_size = 96 22 | ``` 23 | 24 | -------------------------------------------------------------------------------- /All/Python/classes.md: -------------------------------------------------------------------------------- 1 | # Classes 2 | 3 | ```python 4 | class Person: 5 | def __init__(self, firstName, lastName): #constructor 6 | self.firstName = firstName 7 | self.lastName = lastName 8 | 9 | def __repr__(self): #how it is printed 10 | return self.firstName + " " + self.lastName 11 | 12 | def __del__(self): #run when last reference to it goes out of scope 13 | print self.id, 'died' 14 | 15 | class Employee(Person): 16 | def __init__(self, firstName, lastName, weekly_salary): 17 | super().__init__(firstName, lastName) 18 | self.weekly_salary = weekly_salary 19 | 20 | def calculate_payroll(self): 21 | return self.weekly_salary 22 | ``` 23 | 24 | No private variables, `self._x` just indicates private not enforced 25 | 26 | ## Usage 27 | 28 | ```python 29 | me = Person('Jorge', 'Fuentes') 30 | ``` -------------------------------------------------------------------------------- /All/Python/collections/README.md: -------------------------------------------------------------------------------- 1 | # General Iterables 2 | 3 | `len(iterable)` 4 | 5 | #### Loop Over Two Iteratables 6 | 7 | ``` 8 | for (f,b) in zip(foo, bar): 9 | print "f: ", f ,"; b: ", b 10 | ``` 11 | 12 | Stops at the shorter of the two and works for an arbitrary number of iterables 13 | 14 | ## Functional 15 | 16 | In python3, map makes an generator object. Wrap with list() to make a list again 17 | 18 | Map 19 | 20 | ```python 21 | outputs = map(function_to_apply, inputs) 22 | 23 | list(outputs) 24 | ``` 25 | 26 | Filter 27 | 28 | ```python 29 | number_list = range(-5, 5) 30 | less_than_zero = list(filter(lambda x: x < 0, number_list)) 31 | ``` 32 | 33 | Reduce 34 | 35 | ```python 36 | from functools import reduce 37 | product = reduce((lambda x, y: x * y), [1, 2, 3, 4]) 38 | ``` -------------------------------------------------------------------------------- /All/Python/collections/dict.md: -------------------------------------------------------------------------------- 1 | # Dictionaries 2 | 3 | ```python 4 | d= {} 5 | d[k] = v 6 | del d[k] 7 | # Will error if doesn't exist 8 | d["key"] 9 | d.get('key', 'defaultValue') 10 | d.pop(k, None) #get and pop, allows you to remove without checking for existence 11 | ``` 12 | 13 | ### Iteration 14 | 15 | ```python 16 | #For Python 2.x 17 | for key, value in d.iteritems(): 18 | 19 | #For Python 3.x: 20 | for k, v in d.items(): 21 | for v in d.values(): 22 | for k in d.keys(): 23 | 24 | lambda x: x.values()[0] 25 | ``` 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /All/Python/collections/fancyDicts.md: -------------------------------------------------------------------------------- 1 | ## OrderedDict 2 | 3 | keeps order of insertion 4 | 5 | ```python 6 | from collections import OrderedDict 7 | ``` 8 | 9 | ## DefaultDict 10 | 11 | Creates default, nonnull value for keys 12 | 13 | ```python 14 | from collections import defaultdict 15 | d = defaultdict(list) 16 | for k, v in somePairs: 17 | d[k].append(v) 18 | ``` 19 | 20 | ## Counter 21 | 22 | Counts elements 23 | 24 | ```python 25 | from collections import Counter 26 | c = Counter("hell") #Counter({'l': 2, 'h': 1, 'e': 1}) 27 | 28 | #Add iterables of values 29 | c.update([1, 3, 4]) 30 | c.most_common(10) # 10 most common 31 | ``` 32 | 33 | -------------------------------------------------------------------------------- /All/Python/collections/heap.md: -------------------------------------------------------------------------------- 1 | # Heap 2 | 3 | Builtin min heap, where you need efficient access to the minimum or maximum element like priority queue 4 | 5 | ```python 6 | import heapq 7 | 8 | # Create an empty heap 9 | heap = [] 10 | 11 | # Insert elements 12 | heapq.heappush(heap, 10) 13 | heapq.heappush(heap, 15) 14 | heapq.heappush(heap, 20) 15 | heapq.heappush(heap, 5) 16 | 17 | print("Heap:", heap) 18 | 19 | # Peek (get the smallest element without removing it) 20 | min_element = heap[0] 21 | print("Min element:", min_element) 22 | 23 | # Extract the smallest element 24 | min_element = heapq.heappop(heap) 25 | print("Extracted min element:", min_element) 26 | print("Heap after extraction:", heap) 27 | 28 | # Heapify an existing list 29 | nums = [30, 10, 20, 5, 40, 25] 30 | heapq.heapify(nums) 31 | print("Heapified list:", nums) 32 | ``` 33 | 34 | -------------------------------------------------------------------------------- /All/Python/collections/list.md: -------------------------------------------------------------------------------- 1 | # List 2 | 3 | ```python 4 | l = [] 5 | l = [x for x in range(10) if x%2 == 0] 6 | l.append(1) 7 | l.extend([1,2,3]) 8 | l.remove(2) 9 | del l[0] 10 | l.pop() #remove and return 11 | ``` 12 | 13 | *Unhashable so can't be keys/in set, but tuples can be...* 14 | 15 | ## Iterate 16 | 17 | ```python 18 | for v in l: 19 | for reverseV in reversed(l): #reversed returns iterator 20 | for i in range(len(l)): 21 | for x in range(len(s) - 1, -1, -1): #reversed is more clear 22 | for reverseI in reversed(range(len(l))): 23 | for i, v in enumerate(l): 24 | ``` 25 | 26 | ## Helpers 27 | 28 | ```python 29 | l.reverse() 30 | reversed(l) #returns an iterator over 31 | copyOfL = l[:] 32 | ``` 33 | 34 | ### Sorting 35 | 36 | ascending is default 37 | 38 | ```python 39 | sorted(l) # return new 40 | sorted(l, reverse=True) # return new 41 | l.sort(key=[ft to call], reverse=False) #in place 42 | l.sort(key=lambda x: x[1], reverse=True) 43 | ``` 44 | 45 | -------------------------------------------------------------------------------- /All/Python/collections/set.md: -------------------------------------------------------------------------------- 1 | # Set 2 | 3 | ```python 4 | new_set = set() 5 | tags_set = {"apple", "banana", "cherry"} 6 | 7 | thisset.remove("banana") 8 | thisset.add("orange") 9 | 10 | z = x.intersection(y) 11 | set3 = set1.union(set2) 12 | ``` 13 | 14 | 15 | 16 | ```ts 17 | const uniqueContactOwners = new Set(); 18 | 19 | for (let uid in uniqueContactOwners) { 20 | //....... 21 | } 22 | 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /All/Python/crypto.md: -------------------------------------------------------------------------------- 1 | # Secrets 2 | 3 | Python 3.6 and up, default 4 | 5 | used for generating cryptographically strong random numbers suitable for managing data such as passwords, account authentication, security tokens, and related secrets. 6 | 7 | ```python 8 | import secrets 9 | ``` 10 | 11 | ```python 12 | >> secrets.token_hex(nbytes=16) 13 | '17adbcf543e851aa9216acc9d7206b96' 14 | 15 | >>> secrets.token_urlsafe(16) 16 | 'X7NYIolv893DXLunTzeTIQ' 17 | 18 | >>> secrets.token_bytes(128 // 8) 19 | b'\x0b\xdcA\xc0.\x0e\x87\x9b`\x93\\Ev\x1a|u' 20 | ``` 21 | 22 | -------------------------------------------------------------------------------- /All/Python/flask/README.md: -------------------------------------------------------------------------------- 1 | # Flask 2 | 3 | ## Most basic 4 | 5 | ```python 6 | from flask import Flask 7 | app = Flask(__name__) 8 | 9 | @app.route('/') 10 | def hello_world(): 11 | return 'Hello, World!' 12 | ``` 13 | 14 | ### Flask Run 15 | 16 | Flask run finds trys to find right file to run and loads .env too 17 | 18 | ```bash 19 | flask run --debug #to run in debug mode 20 | flask run -h 0.0.0.0 -p 80 --debug # to set url 21 | ``` 22 | 23 | *Default of 5000 can cause problems on Mac cuz 5000 is used for control center* 24 | 25 | ### Flask CLI 26 | 27 | ```python 28 | # Run `flask createdb` to run this 29 | @app.cli.command() 30 | def createdb(): 31 | # import logging 32 | # logging.basicConfig() 33 | # logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO) 34 | 35 | from app.models.user import User 36 | from app.models.question import Question 37 | print("Created DBBBB") 38 | db.create_all() 39 | ``` 40 | 41 | -------------------------------------------------------------------------------- /All/Python/flask/blueprint.md: -------------------------------------------------------------------------------- 1 | # Blueprint 2 | 3 | Split up your app routes into separate files and register them at like `/api/v1` 4 | 5 | ## Creation 6 | 7 | simplepage.py 8 | 9 | ```python 10 | from flask import Blueprint 11 | 12 | simple_page = Blueprint('simple_page', __name__, 13 | template_folder='templates') #can leave template_folders out 14 | 15 | @simple_page.route('/') 16 | def index(): 17 | return render_template("hello.html") 18 | ``` 19 | 20 | ## Registering 21 | 22 | app.py 23 | 24 | ```python 25 | from yourapplication.simple_page import simple_page 26 | 27 | app = Flask(__name__) 28 | app.register_blueprint(simple_page) 29 | 30 | app.register_blueprint(user, url_prefix='/user') 31 | ``` 32 | 33 | ## Linking 34 | url_for('admin.index') 35 | -------------------------------------------------------------------------------- /All/Python/flask/cli.md: -------------------------------------------------------------------------------- 1 | # Flask CLI 2 | 3 | Installing Flask install the `flask` command for bash 4 | 5 | Just run `flask` for a good overview of the commands 6 | 7 | Default gets app.py or wsgi.py 8 | 9 | `export FLASK_ENV=development` -------------------------------------------------------------------------------- /All/Python/flask/deploying.md: -------------------------------------------------------------------------------- 1 | # Deploying Options 2 | 3 | ## Simplest 4 | 5 | `ngrok http [THE PORT YOU WANT]` 6 | 7 | ## EC2 8 | 9 | To access over docker or AWS, must run flask development server **which should never be used** like this: 10 | 11 | ` app.run(debug=True, host='0.0.0.0')` 12 | 13 | **never do this**: `sudo pipenv run flask run -h 0.0.0.0 -p 80` 14 | 15 | ## Gunicorn 16 | 17 | WSGI(python web server) recommended version 18 | 19 | `gunicorn [OPTIONS] APP_MODULE` 20 | 21 | APP_MODULE means \$(MODULE_NAME):\$(VARIABLE_NAME) 22 | 23 | ## Heroku 24 | 25 | Make `Procfile` in main folder to tell heroku what to do 26 | 27 | Add line 28 | 29 | -------------------------------------------------------------------------------- /All/Python/flask/flash.md: -------------------------------------------------------------------------------- 1 | # Flash 2 | 3 | .py 4 | 5 | ```python 6 | from flask import flash 7 | 8 | @app.route('/login', methods=['GET', 'POST']) 9 | def login(): 10 | #... 11 | flash('You were successfully logged in') 12 | ``` 13 | 14 | .html 15 | 16 | ```jinja2 17 | {% with messages = get_flashed_messages() %} 18 | {% if messages %} 19 |
    20 | {% for message in messages %} 21 |
  • {{ message }}
  • 22 | {% endfor %} 23 |
24 | {% endif %} 25 | {% endwith %} 26 | ``` 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /All/Python/flask/packages.md: -------------------------------------------------------------------------------- 1 | ## Notable Packages 2 | 3 | ## Bootstrap 4 | Basically provides macros, I would just use regular bootstrap as fun as abstracting away form creation is 5 | ```py 6 | from flask_bootstrap import Bootstrap 7 | ``` 8 | 9 | ```html 10 | {% extends "bootstrap/base.html" %} 11 | {% block title %}This is an example page{% endblock %} 12 | 13 | {% block navbar %} 14 | 17 | {% endblock %} 18 | 19 | {% block content %} 20 |

Hello, Bootstrap

21 | {% endblock %} 22 | ``` 23 | -------------------------------------------------------------------------------- /All/Python/flask/packages/cors.md: -------------------------------------------------------------------------------- 1 | # Cors 2 | 3 | ```bash 4 | pip install flask-cors 5 | ``` 6 | 7 | ## Flask-cors 8 | 9 | ```python 10 | from flask import Flask 11 | from flask_cors import CORS 12 | 13 | app = Flask(__name__) 14 | CORS(app) 15 | 16 | @app.route("/") 17 | def helloWorld(): 18 | return "Hello, cross-origin-world!" 19 | ``` 20 | 21 | -------------------------------------------------------------------------------- /All/Python/flask/postgres/README.md: -------------------------------------------------------------------------------- 1 | # Postgres in Flask 2 | 3 | ```bash 4 | pip install sqlalchemy psycopg2 Flask-Migrate Flask-SQLAlchemy 5 | ``` 6 | 7 | Recommended packages to use to manage a postgres connection: 8 | 9 | - flask-migrate to manage db updates 10 | - Flask-SQLAlchemy to add some 11 | -------------------------------------------------------------------------------- /All/Python/flask/postgres/migrate.md: -------------------------------------------------------------------------------- 1 | # Flask-Migrate 2 | 3 | ```bash 4 | pip install Flask-Migrate 5 | ``` 6 | 7 | Migrations are handle by `flask-migrate/alembic` 8 | 9 | Creates folder for migrations 10 | 11 | ## Setup 12 | 13 | ```python 14 | # extensions.py 15 | from flask_migrate import Migrate 16 | 17 | migrate = Migrate() 18 | 19 | # app.py 20 | from app.extensions import migrate 21 | 22 | #...... 23 | migrate.init_app(app, db) 24 | ``` 25 | 26 | Then run this to create the db tables 27 | 28 | ```bash 29 | flask db init 30 | flask db migrate -m "Message goes here I think" 31 | flask db upgrade 32 | ``` 33 | 34 | ## Generate New Migration Files 35 | 36 | ```bash 37 | flask db migrate -m "Message goes here I think" 38 | flask db upgrade 39 | ``` 40 | -------------------------------------------------------------------------------- /All/Python/flask/response.md: -------------------------------------------------------------------------------- 1 | # RESPONSES 2 | 3 | ```python 4 | from flask import Flask, jsonify, make_response 5 | 6 | def index(): 7 | #auto sets status code to 200 8 | return jsonify(data) 9 | #return 'hi' 10 | #return make_response("Wrong password", 401) 11 | 12 | ``` 13 | 14 | ORRRR 15 | 16 | ```python 17 | resp = Response(js, status=200, mimetype='application/json') 18 | ``` 19 | 20 | ### Render Template 21 | 22 | ```python 23 | from flask import render_template 24 | 25 | @app.route('/hello/') 26 | @app.route('/hello/') 27 | def hello(name=None): 28 | return render_template('hello.html', name=name) 29 | ``` 30 | 31 | Default is template folder 32 | 33 | #### Send File 34 | 35 | ```python 36 | return send_file('/var/www/PythonProgramming/PythonProgramming/static/images/python.jpg', attachment_filename='python.jpg') 37 | 38 | ``` 39 | 40 | ## End Early Status Code 41 | 42 | ```python 43 | from flask import abort 44 | abort(404) 45 | 46 | response = jsonify({'message': message}) 47 | response.status_code = 400 48 | return response 49 | ``` -------------------------------------------------------------------------------- /All/Python/json.md: -------------------------------------------------------------------------------- 1 | # JSON 2 | 3 | ```python 4 | import json 5 | ``` 6 | 7 | ## Dump vs Dumps 8 | 9 | `dumps`: returns a string 10 | 11 | `dump`: for printing out to file 12 | 13 | ```python 14 | someJson = {'x': 1, 'y': 57} 15 | print(json.dumps(someJson)) 16 | 17 | f1=open("test.txt", 'w') 18 | json.dump(someJson, f1) 19 | ``` 20 | 21 | ## Loads 22 | 23 | ``` 24 | json.loads(str) 25 | 26 | json.load(file) 27 | ``` 28 | 29 | 30 | 31 | 32 | 33 | ## Object ID 34 | 35 | ```python 36 | import json 37 | from bson import ObjectId 38 | 39 | class JSONEncoder(json.JSONEncoder): 40 | def default(self, o): 41 | if isinstance(o, ObjectId): 42 | return str(o) 43 | return json.JSONEncoder.default(self, o) 44 | 45 | JSONEncoder().encode(analytics) 46 | ``` -------------------------------------------------------------------------------- /All/Python/packages/cython.md: -------------------------------------------------------------------------------- 1 | # Cython 2 | 3 | A superset of python with c data types that compiles to c code 4 | 5 | The c code it compiles to is long as fuck :( 6 | 7 | ## Basic Setup 8 | 9 | 1. Name python file to compile `.pyx` 10 | 11 | 2. In a `setup.py`, 12 | 13 | ```python 14 | from distutils.core import setup 15 | from Cython.Build import cythonize 16 | 17 | setup( 18 | ext_modules = cythonize(".pyx") 19 | ) 20 | ``` 21 | 22 | 3. Run this on the command line: `python setup.py build_ext --inplace` 23 | 24 | 1. This creates a .so and .c file 25 | 26 | 4. To use this in python just `import test` 27 | 28 | ## Variables 29 | 30 | ```python 31 | cdef int n, i, len_p 32 | ``` -------------------------------------------------------------------------------- /All/Python/packages/dotenv.md: -------------------------------------------------------------------------------- 1 | # Environment Variables 2 | 3 | ```bash 4 | pip install python-dotenv 5 | ``` 6 | 7 | `python-dotenv` reads key-value pairs from a `.env` file and sets them as environment variables 8 | 9 | .env (git ignore this) 10 | 11 | ``` 12 | CONFIG_PATH=${HOME}/.config/foo 13 | DOMAIN=example.org 14 | EMAIL=admin@${DOMAIN} 15 | ``` 16 | 17 | script.py 18 | 19 | ```python 20 | from dotenv import load_dotenv 21 | import os 22 | 23 | load_dotenv() 24 | 25 | SECRET_KEY = os.getenv("EMAIL") 26 | DATABASE_PASSWORD = os.getenv("DATABASE_PASSWORD") 27 | ``` 28 | 29 | flask run auto does this -------------------------------------------------------------------------------- /All/Python/packages/excel.md: -------------------------------------------------------------------------------- 1 | # Excel 2 | 3 | Read with pandas 4 | 5 | ## Throw Pandas DF into Excel File 6 | 7 | `pip install XlsxWriter` 8 | 9 | ```python 10 | 11 | # Specify a writer 12 | writer = pd.ExcelWriter('example.xlsx', engine='xlsxwriter') 13 | 14 | # Write your DataFrame to a file 15 | yourData.to_excel(writer, 'Sheet1') 16 | 17 | # Save the result 18 | writer.save() 19 | ``` 20 | 21 | -------------------------------------------------------------------------------- /All/Python/packages/jupyter.md: -------------------------------------------------------------------------------- 1 | # Jupyter Notebook 2 | 3 | ### Setup 4 | 5 | ```bash 6 | pip install jupyter 7 | ``` 8 | 9 | ### Usage 10 | 11 | ```bash 12 | jupyter notebook 13 | ``` 14 | 15 | #### Magic Functions 16 | 17 | `%matplotlib inline` [sets the backend of matplotlib to the 'inline' backend](http://ipython.readthedocs.io/en/stable/interactive/plotting.html): 18 | 19 | > With this backend, the output of plotting commands is displayed inline within frontends like the Jupyter notebook, directly below the code cell that produced it. The resulting plots will then also be stored in the notebook document. 20 | 21 | ## Multiple Kernels/Environments 22 | 23 | In the environment, run `pip install ipykernel` 24 | 25 | -------------------------------------------------------------------------------- /All/Python/packages/matplotlib.md: -------------------------------------------------------------------------------- 1 | # MatplotLib 2 | 3 | ## Simplest 4 | 5 | ```python 6 | import matplotlib.pyplot as plt 7 | plt.plot([1,4,9,16]) # y with x = [0, 1,2,3] 8 | plt.plot([1,2,3,4], [1,4,9,16], 'ro') # x y color 9 | plt.axis([0, 6, 0, 20]) #xmin xmax ymin ymax 10 | plt.show() 11 | ``` 12 | 13 | ## Simple Example 14 | 15 | ```python 16 | import matplotlib.pyplot as plt 17 | import numpy as np 18 | 19 | # Data for plotting 20 | t = np.arange(0.0, 2.0, 0.01) 21 | s = 1 + np.sin(2 * np.pi * t) 22 | 23 | # Note that using plt.subplots below is equivalent to using 24 | # fig = plt.figure() and then ax = fig.add_subplot(111) 25 | fig, ax = plt.subplots() 26 | ax.plot(t, s) 27 | 28 | ax.set(xlabel='time (s)', ylabel='voltage (mV)', 29 | title='About as simple as it gets, folks') 30 | ax.grid() 31 | 32 | fig.savefig("test.png") 33 | plt.show() 34 | ``` 35 | 36 | -------------------------------------------------------------------------------- /All/Python/packages/pandas.md: -------------------------------------------------------------------------------- 1 | # Pandas 2 | 3 | ```python 4 | import pandas as pd 5 | 6 | fullCorpus = pd.DataFrame({ 7 | 'label': labelList, 8 | 'body_list': textList 9 | }) 10 | 11 | fullCorpus.head() #print first 5 rows 12 | ``` 13 | ## Access 14 | 15 | ```python 16 | df['date'] #just date column 17 | df[df['date'] > '2017-03-20'] # just date columns that meet criteria 18 | ``` 19 | 20 | ### Filter 21 | 22 | ```python 23 | df = df.drop(['high','low','close','volume'], axis=1) #get rid of columns 24 | ``` 25 | 26 | ### Indexing 27 | 28 | Use `X.iloc[0]` instead of `X[0]` 29 | 30 | ## Read in seperated data 31 | 32 | ```python 33 | fullCorpus = pd.read_csv("file.tsv", sep="\t", header=None) 34 | # header default assumes first row is the column names 35 | fullsCorpus.columns = ['label', 'body_text'] # add columns 36 | ``` 37 | 38 | ## Create New Column 39 | `pdData['clean_text'] = data['body_text'].apply(lambda x: remove_punct(x))` -------------------------------------------------------------------------------- /All/Python/packages/passwords.md: -------------------------------------------------------------------------------- 1 | # PassLib 2 | 3 | - Supports many hashing types with simple interface 4 | 5 | `pip install passlib` 6 | 7 | ```python 8 | from passlib.hash import pbkdf2_sha256 9 | 10 | # generate new salt, and hash a password 11 | hash = pbkdf2_sha256.hash("toomanysecrets") 12 | #hash '$pbkdf2-sha256$29000$N2YMIWQsBWBMae09x1jrPQ$1t8iyB2A.WF/Z5JZv.lfCIhXXN33N23OSgQYThBYRfk' 13 | 14 | pbkdf2_sha256.verify("toomanysecrets", hash) 15 | #True 16 | pbkdf2_sha256.verify("joshua", hash) 17 | #False 18 | ``` 19 | 20 | ## Alternatives 21 | 22 | - Werkzeug.security 23 | - Bcrypt 24 | -------------------------------------------------------------------------------- /All/Python/packages/pillow.md: -------------------------------------------------------------------------------- 1 | # PIL 2 | 3 | Python Image Library 4 | 5 | ```python 6 | from PIL import Image 7 | import requests 8 | from io import BytesIO 9 | 10 | response = requests.get(url) 11 | img = Image.open(BytesIO(response.content)) 12 | ``` 13 | 14 | -------------------------------------------------------------------------------- /All/Python/packages/prisma.md: -------------------------------------------------------------------------------- 1 | # [Prisma*](https://prisma-client-py.readthedocs.io/) 2 | 3 | Uses async-io, dont forget to add client generator 4 | 5 | ``` 6 | generator client_py { 7 | provider = "prisma-client-py" 8 | recursive_type_depth = 5 9 | } 10 | ``` 11 | 12 | ## Setup 13 | 14 | ```bash 15 | pip install prisma 16 | ``` 17 | 18 | ## Usage 19 | 20 | ```python 21 | from prisma import Prisma 22 | 23 | db = Prisma() 24 | await db.connect() 25 | 26 | # CRUD operations 27 | user = await db.user.create(data={"name": "Alice"}) 28 | users = await db.user.find_many() 29 | updated = await db.user.update(where={"id": 1}, data={"name": "Bob"}) 30 | deleted = await db.user.delete(where={"id": 1}) 31 | 32 | await db.disconnect() 33 | ``` -------------------------------------------------------------------------------- /All/Python/packages/pydub.md: -------------------------------------------------------------------------------- 1 | # Pydub 2 | 3 | Manipulate Audio 4 | 5 | ## Split 6 | 7 | ```python 8 | from pydub import AudioSegment 9 | sound = AudioSegment.from_file("./Community.mp3") 10 | 11 | halfway_point = len(sound) // 2 12 | print(len(sound)) 13 | first_half = sound[:halfway_point] 14 | 15 | # create a new file "first_half.mp3": 16 | first_half.export("./Com.mp3", format="mp3") 17 | ``` 18 | 19 | ## Access Raw Data 20 | 21 | ```python 22 | AudioSegment(...).raw_data 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /All/Python/random.md: -------------------------------------------------------------------------------- 1 | # Random 2 | 3 | ```python 4 | import random 5 | random.randint(a, b) 6 | ``` 7 | 8 | 9 | 10 | Return a random integer *N* such that a <= N <= b 11 | 12 | ### Random between 2 floats 13 | 14 | ```python 15 | random.uniform(1.5, 1.9) 16 | ``` 17 | 18 | 1.8733202628557872 19 | 20 | `round(number, ndigits)` - #rounds floating pt to n digits -------------------------------------------------------------------------------- /All/Python/re.md: -------------------------------------------------------------------------------- 1 | # Regular Expression 2 | ```python 3 | import re 4 | regex = r"([a-zA-Z]+) (\d+)" 5 | match = re.search(regex, "I was born on June 24") 6 | ``` 7 | 8 | # Splitting String to List 9 | 10 | Re.split([reExpression], [string]) 11 | OR Re.findall([reExpression], [string]) 12 | 13 | - '\s' #single white space 14 | - '\s+' #split on one or more whitespace 15 | - '\S+' #one or more non whitespace character 16 | - '\w+') #one or more words 17 | - '\W+' #any non word character 18 | 19 | # Replace 20 | ``` 21 | regex = r"[0-9+\. *]" 22 | re.sub(regex, "", '1. Interdimensional \n2. Aliens') 23 | ``` 24 | 25 | '\\\\' as the pattern string, because the regular expression must be \\, and each backslash must be expressed as \\ inside a regular Python string literal. 26 | 27 | The solution is to use Python’s raw string notation for regular expression patterns; backslashes are not handled in any special way in a string literal prefixed with 'r' -------------------------------------------------------------------------------- /All/Python/testing.md: -------------------------------------------------------------------------------- 1 | # Testing 2 | Start test names with test_ and use the self defined asserts 3 | 4 | ```python 5 | import unittest 6 | 7 | class TestStringMethods(unittest.TestCase): 8 | 9 | def test_upper(self): 10 | self.assertEqual('foo'.upper(), 'FOO') 11 | 12 | def test_isupper(self): 13 | self.assertTrue('FOO'.isupper()) 14 | self.assertFalse('Foo'.isupper()) 15 | 16 | def test_split(self): 17 | s = 'hello world' 18 | self.assertEqual(s.split(), ['hello', 'world']) 19 | # check that s.split fails when the separator is not a string 20 | with self.assertRaises(TypeError): 21 | s.split(2) 22 | 23 | if __name__ == '__main__': 24 | unittest.main() 25 | ``` 26 | 27 | ## Pre&Post Work 28 | ```python 29 | Class widget: 30 | def setUp(self): 31 | self.widget = Widget('The widget') 32 | ``` 33 | 34 | - Can make this class the parent of other widgets 35 | - exectued before and after each test 36 | -------------------------------------------------------------------------------- /All/Scala/exceptions.md: -------------------------------------------------------------------------------- 1 | # Exceptions 2 | 3 | ```scala 4 | def error(msg: String) = throw new Error(msg) 5 | // (msg: String) => Nothing 6 | throw Exc 7 | 8 | ``` 9 | 10 | ## Try Catch 11 | 12 | ```scala 13 | //val result: Int = //an expression so can do this 14 | try { 15 | remoteCalculatorService.add(1, 2) 16 | } catch { 17 | case e: ServerIsDownException => log.error(e, "the remote calculator service is unavailable. should have kept your trusty HP.") 18 | } finally { 19 | remoteCalculatorService.close() 20 | } 21 | ``` 22 | -------------------------------------------------------------------------------- /All/Scala/objects.md: -------------------------------------------------------------------------------- 1 | ## Objects 2 | 3 | - Basially singleton class(can have object and class with same name; often for factories) 4 | - Define with `object` instead of `class` and be able to use instantly(can be used within itself) 5 | 6 | ## Companion Object 7 | 8 | Often define companion object with the same name as call 9 | 10 | - can access private members 11 | - like static methods(which uses ClassName.staticmethod() notation) 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /All/Scala/options.md: -------------------------------------------------------------------------------- 1 | ## Option 2 | 3 | may or may not hold something, staticallly enforced to check for emptiness 4 | 5 | Do `var username: Option[String] = None` isntead of `var username = null` 6 | 7 | Basically: 8 | 9 | ```scala 10 | trait Option[T] { 11 | def isDefined: Boolean 12 | def get: T 13 | def getOrElse(t: T): T 14 | } 15 | ``` 16 | 17 | Map returns Option 18 | 19 | ```scala 20 | val x = Some("a string") 21 | val result = Res1.getOrElse(0) * 2 //default 0 22 | 23 | val result = res1 match { 24 | case Some(n) => n * 2 25 | case None => 0 26 | } 27 | ``` 28 | 29 | Commonly use map and other such functions 30 | 31 | ```scala 32 | val someInt = Some (2) 33 | val noneInt:Option[Int] = None 34 | val someIntRes = someInt.map (_ * 2) //Some (4) 35 | val noneIntRes = noneInt.map (_ * 2) //None 36 | ``` 37 | 38 | -------------------------------------------------------------------------------- /All/Scala/packages.md: -------------------------------------------------------------------------------- 1 | # Packages 2 | 3 | Place class inside package using package clause at top of source 4 | 5 | ```scala 6 | package progfun.examples 7 | 8 | object Hello { 9 | //... 10 | } 11 | ``` 12 | 13 | Another file:˜ 14 | 15 | ```scala 16 | progfun.examples.Hello 17 | //OR 18 | import progfun.examples.Hello 19 | import progfun.examples._ 20 | 21 | Hello 22 | ``` 23 | 24 | -------------------------------------------------------------------------------- /All/Scala/performance&style.md: -------------------------------------------------------------------------------- 1 | # Performance 2 | 3 | - Prefer Vector over List 4 | - Use a set instead of filtering over everything if you plan on getting more than a couple elements out of a collection. e.g. just because list.filter achieves the same result as set.contains, use a set if appropriate. 5 | - In concurrent programs with a write/read ratio less than 1/10, use an immutable collection and an atomic reference. You get better (and more consistent) performance out of an immutable hash set and an atomic reference for both reads and writes than a ConcurrentHashMap. 6 | 7 | -------------------------------------------------------------------------------- /All/Scala/sbt(running).md: -------------------------------------------------------------------------------- 1 | # sbt 2 | 3 | Simple Build Tool 4 | 5 | ## Creation 6 | 7 | `set new sbt/scala-seed.g8` 8 | 9 | ## Running 10 | 11 | ```bash 12 | sbt 13 | run 14 | ``` 15 | 16 | `exit` quit set 17 | 18 | ## Directory 19 | 20 | ``` 21 | src/ 22 | main/ 23 | resources/ 24 | 25 | scala/ 26 |
27 | java/ 28 |
29 | test/ 30 | resources 31 | 32 | scala/ 33 | 34 | java/ 35 | 36 | ``` 37 | 38 | Build.sbt or *.sbt defines build in base dir 39 | 40 | ## Shell vs CL 41 | 42 | command-line mode and interactive mode 43 | 44 | - command-line mode, you run `sbt`task from your machine terminal. Once the task successfully finishes then `sbt` exits. i.e  `sbt about`  45 | - the interactive mode, you run - `sbt` command and it launches a `sbt` shell 46 | 47 | ## HI 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /All/Scala/subtyping.md: -------------------------------------------------------------------------------- 1 | # Subtyping 2 | 3 | ## Extending Classes 4 | 5 | ```scala 6 | abstract class Base { 7 | def foo = 1 8 | def bar: Int 9 | } 10 | 11 | class Sub extends Base { 12 | override def foo = 2 //must include override if you are ovveriding soething 13 | def bar = 3 //override opt here 14 | } 15 | ``` 16 | 17 | ## Function Bounds 18 | 19 | ``` 20 | def selection[A <: Animal](a1: A, a2: A): A = 21 | if (a1.fitness > a2.fitness) a1 else a2 22 | ``` 23 | 24 | Here, “`<: Animal`” is an *upper bound* of the type parameter `A`. 25 | 26 | It means that `A` can be instantiated only to types that conform to `Animal`. 27 | 28 | Generally, the notation 29 | 30 | - `A <: B` means: *A is a subtype of B*, and(upper bound) 31 | - `A >: B` means: *A is a supertype of B*, or *B is a subtype of A*.(lowerbound) 32 | 33 | -------------------------------------------------------------------------------- /All/Scala/traits.md: -------------------------------------------------------------------------------- 1 | # Traits 2 | 3 | Interface like `traits` are fields and behaviors that you add to classes 4 | 5 | Better than Java interfaces b/c offers value parameters and methods 6 | 7 | ```scala 8 | trait Car { 9 | def two: Int = 1 * 2 10 | val brand: String 11 | } 12 | 13 | trait Shiny { 14 | val shineRefraction: Int 15 | } 16 | ``` 17 | 18 | ### Extending Traits 19 | 20 | ```scala 21 | class BMW extends Car { 22 | val brand = "BMW" 23 | } 24 | ``` 25 | 26 | One class can extend several traits using the `with` keyword: 27 | 28 | ```scala 29 | class BMW extends Car with Shiny { 30 | val brand = "BMW" 31 | val shineRefraction = 12 32 | } 33 | ``` 34 | 35 | -better than abstract classes cuz can extend multiple traits 36 | 37 | - can't have abstract class constructors, or import in Java as easily 38 | 39 | -------------------------------------------------------------------------------- /All/solana.md: -------------------------------------------------------------------------------- 1 | # Solana 2 | 3 | Look at https://solscan.io/ for address/tx info 4 | 5 | ## CLI Tool 6 | 7 | Setup command line tool 8 | 9 | ```bash 10 | sh -c "$(curl -sSfL https://release.solana.com/v1.9.4/install)" 11 | ``` 12 | 13 | Add to path if its not auto 14 | 15 | ```bash 16 | solana --version 17 | solana config get 18 | ``` 19 | 20 | ### Making New CLI Wallet 21 | 22 | ```bash 23 | solana-keygen new -o /Users/jfuentes/.config/solana/id.json 24 | solana address #JIFJSPIOSJOIPJSDIOJ 25 | ``` 26 | 27 | #### Using in dev 28 | 29 | ```bash 30 | solana config set --url https://api.devnet.solana.com 31 | solana airdrop 1 --url https://api.devnet.solana.com #use solana address 32 | ``` 33 | 34 | ## Making an NFT 35 | 36 | Pretty easy actually 37 | 38 | Generate layered art with [HashLips](https://github.com/HashLips/hashlips_art_engine) 39 | 40 | Git clone the [Metaplex](https://github.com/metaplex-foundation/metaplex) repo and use CandyMachine. Edit the json, follow cli commands, and boom -------------------------------------------------------------------------------- /CSS/README.md: -------------------------------------------------------------------------------- 1 | # CSS 2 | 3 | - Mostly from frontend master by estelle.github.com/CSS-Workshop . 4 | - CSS Level 1, 2, 3 broken in modules like 4 5 | - Flexbox is Level 1 6 | - Convention is top, bottom, left, right for ordering 7 | 8 | ## Including css 9 | external is ideal, allows reusability across site 10 | ```html 11 | ` 12 | 13 | 16 | 17 |

Lorem ipsum

18 | ``` 19 | 20 | ## Measurements 21 | 22 | `1em` - Relative to parent's font-size(16px font-size => 1em) 23 | 24 | `1rem` - Relative to root html's font-size 25 | 26 | `50%` - Relative to parent container 27 | 28 | `50vh` - Relative to viewport height (100vh is max) 29 | 30 | `50vw` - Relative to viewport width 31 | 32 | `100px` - Never really use, it doesn't adapt to screen size at all 33 | 34 | `calc(10% - 1em)` - Use calc for simple maths 35 | 36 | ## Prefixes 37 | 38 | Browser add support for CSS features that are experimental with prefixes, used 39 | 40 | Webkit- (chrome/safari) 41 | 42 | Max- 43 | -------------------------------------------------------------------------------- /CSS/colors.md: -------------------------------------------------------------------------------- 1 | # Colors 2 | 3 | ```Css 4 | color: white; 5 | color : #fff; 6 | color: #FFFFFF; 7 | color: transparent; 8 | color: currentColor; 9 | color: rgb(255,255,255); 10 | color: rgb(100%,100%,100%); 11 | color: rgba(255,255,255, 1); 12 | color: hsl(0, 100%, 100%) 13 | ``` 14 | 15 | Border defaults to currentColor which is color of text 16 | 17 | Alpha: 0-1 18 | 19 | HSLAddd(Hue, saturation, lightness, and alphatranspency) 20 | 21 | Transparent == rgba(0, 0, 0, 0); 22 | 23 | ## Opacity vs AlphaTransparent 24 | 25 | Alphatransparent just makes text transparent 26 | 27 | Opacity, text element shadow, everything becomes transparent 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /CSS/cursors.md: -------------------------------------------------------------------------------- 1 | # Cursors 2 | 3 | https://estelle.github.io/cssmastery/other/#slide26 4 | 5 | SO MANY 6 | 7 | ## Click Through 8 | 9 | ```css 10 | Pointer-events: none; 11 | ``` 12 | 13 | -------------------------------------------------------------------------------- /CSS/display.md: -------------------------------------------------------------------------------- 1 | ## Old 2 | 3 | | Value | Effect | 4 | | ------------ | ------------------------------------------------------------ | 5 | | block | Starts on new line, fill width of parent container | 6 | | inline | Remain in line and only take up width of content(height/width have no effect) | 7 | | inline-block | Remain in line, can apply height and width | 8 | | | | 9 | 10 | ## HTML 5 11 | 12 | All elements inline by default 13 | 14 | Div is full width and needed height 15 | 16 | Tables have equal heights 17 | 18 | - -------------------------------------------------------------------------------- /CSS/fonts.md: -------------------------------------------------------------------------------- 1 | # Fonts 2 | 3 | #### Font-weight 4 | 5 | normal | bold => equivalent of 400 | 700 6 | 7 | lighter | bolder => compared to inherited font weight 8 | 9 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 10 | 11 | ## Custom Fonts 12 | 13 | 1) Get the font file 14 | 15 | 2) You need at least the woff2 and woff, [fontsquirrel helps](https://www.fontsquirrel.com/tools/webfont-generator) 16 | 17 | 3) Add the font file to your static website folder 18 | 19 | 4) Add the following to your html somehow 20 | 21 | ```css 22 | @font-face { 23 | font-family: 'wremenabold'; 24 | src: url('app/static/webfontkit-WremenaBold/wremena_bold-webfont.woff2') format('woff2'), 25 | url('app/static/webfontkit-WremenaBold/wremena_bold-webfont.woff') format('woff'); 26 | font-weight: normal; 27 | font-style: normal; 28 | } 29 | ``` 30 | 31 | If you are using scss, you need to only include it once(no variables import to every file) since the url route is a file path 32 | 33 | -------------------------------------------------------------------------------- /CSS/lists.md: -------------------------------------------------------------------------------- 1 | # Lists 2 | 3 | You can style many parts of the list 4 | 5 | ```css 6 | list-style-image: url('sqpurple.gif'); 7 | list-style-position: inside; //default is outside 8 | ``` 9 | 10 | List also comes with default margin and padding if you want to get rid of it 11 | 12 | ```css 13 | ul { 14 | list-style-type: none; 15 | margin: 0; 16 | padding: 0; 17 | } 18 | ``` 19 | 20 | You can't change the size of the image very well so usually just better to use an actual img tag 21 | 22 | ### Getting that last/first element to be properly spaced 23 | 24 | ```scss 25 | .article-list { 26 | margin-bottom: 1rem; 27 | 28 | &:last-child { 29 | margin-bottom: 0; 30 | } 31 | } 32 | ``` 33 | 34 | -------------------------------------------------------------------------------- /CSS/object-fit.md: -------------------------------------------------------------------------------- 1 | # [Object-fit](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit) 2 | 3 | How content should be resized to fit container 4 | 5 | | Prop | Effect | 6 | | ----------------- | -------------------------------------- | 7 | | object-fit: fill; | stretch to fill | 8 | | contaiin | Keep aspect ratio | 9 | | Cover | Cover all of container even if cut off | 10 | | | | 11 | | | | 12 | | | | 13 | | | | 14 | 15 | -------------------------------------------------------------------------------- /CSS/placement/README.md: -------------------------------------------------------------------------------- 1 | # Placing Common Tasks 2 | 3 | ### Centering Div in Another Div 4 | 5 | https://www.w3schools.com/css/css_align.asp 6 | 7 | ##### Way 1 8 | 9 | Margin-auto & position absolute with top, bottom, left, and right 0 10 | 11 | ##### Way 2 12 | 13 | flex justify-center items-center 14 | 15 | ## Keeping Img/Video Aspect Ratio 16 | 17 | #### Based on width 18 | 19 | ```jsx 20 |
25 | 29 |
30 | ``` 31 | 32 | *Can set w-64 on outer div or make it adapt* 33 | 34 | Max Img/Video based on height with cutting off? 35 | 36 | ```jsx 37 |
38 | 41 |
42 | ``` 43 | 44 | -------------------------------------------------------------------------------- /CSS/placement/columns.md: -------------------------------------------------------------------------------- 1 | ## Columns 2 | 3 | ```css 4 | column-count: 6; 5 | column-width: 5em; 6 | column-rule: 1px solid #bbb; 7 | column-gap: 2em; 8 | ``` 9 | 10 | - Max column count and min column width 11 | - If words are too long, then colun gap won't work 12 | - column rule is line between columns 13 | 14 | ## Put Header 15 | 16 | ```css 17 | #content { Columns: 8em 3; } 18 | h1 {column-span: all;} 19 | ``` 20 | 21 | At least 8 em, but not more than 3 cols 22 | 23 | A h1 will span all the columns -------------------------------------------------------------------------------- /CSS/placement/position.md: -------------------------------------------------------------------------------- 1 | # Position 2 | 3 | There are five different position values: 4 | 5 | - `static`(default) 6 | - Width constrained to parents bounding box 7 | - not affected by z-index 8 | 9 | ## Moving 10 | 11 | If not static, elements are then positioned using the top, bottom, left, and right properties 12 | 13 | - `relative` - adjusted away from normal pos, does nothing if t/b/l/r not set 14 | - `fixed` - positioned relative to the viewport(mostly), sticks to position on scroll 15 | - https://n0rush.medium.com/css-position-fixed-is-not-always-relative-to-viewport-ac37d78e2f13 16 | 17 | - `absolute` 18 | - relative to the nearest ancestor with a nonstatic position set or viewport if none 19 | - Removes it from the document flow so other divs will be rendered as if it wasnt there 20 | - `sticky` - relative until it would be out of viewport then fixed 21 | 22 | -------------------------------------------------------------------------------- /CSS/tailwind/media_queries.md: -------------------------------------------------------------------------------- 1 | # Media Queries 2 | 3 | #### Media Queries 4 | 5 | no prefix means mobile 6 | 7 | ``` 8 | sm:inline 9 | md: 10 | lg: 11 | ``` 12 | 13 | ``` 14 | module.exports = { 15 | theme: { 16 | screens: { 17 | 'sm': '640px', 18 | // => @media (min-width: 640px) { ... } 19 | 20 | 'md': '768px', 21 | // => @media (min-width: 768px) { ... } 22 | 23 | 'lg': '1024px', 24 | // => @media (min-width: 1024px) { ... } 25 | 26 | 'xl': '1280px', 27 | // => @media (min-width: 1280px) { ... } 28 | 29 | '2xl': '1536px', 30 | // => @media (min-width: 1536px) { ... } 31 | } 32 | } 33 | } 34 | ``` 35 | 36 | 100% is default 37 | 38 | ### Portrait vs landscape 39 | 40 | ```html 41 |
42 |
43 | ``` 44 | 45 | -------------------------------------------------------------------------------- /CSS/tailwind/position.md: -------------------------------------------------------------------------------- 1 | ## Positioning 2 | 3 | ### Grid 4 | 5 | ```react 6 |
7 |
01
8 | 9 |
09
10 |
11 | ``` 12 | 13 | #### Flex 14 | 15 | ##### Cross-Axis 16 | 17 | .items-stretch (default?) | .items-start | .items-center | .items-end | .items-baseline | 18 | 19 | ##### Main-Axis 20 | 21 | Justify-start | justify-center | justify-end | justify-between | justify-around 22 | 23 | ```html 24 |
25 |
Tails
26 |
Sonic
27 |
28 | ``` 29 | 30 | #### Position 31 | 32 | .static | .fixed | .absolute | .relative | .sticky 33 | 34 | ```html 35 |
36 | 37 |
38 | ``` 39 | 40 | ## -------------------------------------------------------------------------------- /CSS/tailwind/size_spacing.md: -------------------------------------------------------------------------------- 1 | ## Size and Spacing 2 | 3 | Same for margins except m 4 | 5 | | Class | Properties | 6 | | -------------- | ---------------- | 7 | | .p-0 | padding: 0; | 8 | | .p-2 | padding: .5rem; | 9 | | .py-4 | Y-axis: 1rem | 10 | | .px-6 | X-axis: 1.5rem | 11 | | .pb-8 | bottom: 2rem | 12 | | .pl-10 | Left: 2.5rem | 13 | | .pr-12 | Right: 3rem; | 14 | | .pt-16 | Top: 4rem; | 15 | | .w-0 | width:0; | 16 | | .min-w-0 | | 17 | | .max-w-xs | | 18 | | .h-full | height: 100%; | 19 | | .h-screen | height: 100vh; | 20 | | .w-1/2 | width: 50%; // | 21 | | .w-4/5 | width: 80%; | 22 | | //2,3,4,5,6,12 | all fractions of | 23 | 24 | #### -------------------------------------------------------------------------------- /CSS/tailwind/typography.md: -------------------------------------------------------------------------------- 1 | # Typography 2 | 3 | Tailwind CSS Typography plugin, https://github.com/tailwindlabs/tailwindcss-typography 4 | 5 | - Tailwind disables the styles, but maybe you want the

and stuff, to work and look nice out of the box 6 | - https://play.tailwindcss.com/uj1vGACRJA?layout=preview 7 | - Just add `prose` class to your container and

,
    , etc will work beautifully 8 | 9 | | `prose-sm` | 0.875rem *(14px)* | 10 | | ------------------------ | ----------------- | 11 | | `prose-base` *(default)* | 1rem *(16px)* | 12 | | `prose-lg` | 1.125rem *(18px)* | 13 | | `prose-xl` | 1.25rem *(20px)* | 14 | | `prose-2xl` | 1.5rem *(24px)* | -------------------------------------------------------------------------------- /Deployment/AWS/ACM.md: -------------------------------------------------------------------------------- 1 | # Certificate Manager 2 | 3 | Allows https 4 | 5 | Can take up to 30 minutes 6 | 7 | Cant transfer between zones 8 | 9 | Must be in us-east-1 to use for Cloudfront -------------------------------------------------------------------------------- /Deployment/AWS/Cloudfront.md: -------------------------------------------------------------------------------- 1 | # \Cloudfront 2 | 3 | CDN allowing faster responses with global distribution for static content 4 | 5 | Also can be used for EC2 with some sort of API speed up 6 | 7 | Pretty easy to setup with good tool tips 8 | 9 | ### Pricing 10 | 11 | AWS Free Tier includes 50GB data transfer out, 2,000,000 HTTP and HTTPS Requests with Amazon CloudFront. 12 | 13 | you don’t pay for any data transferred between these services and CloudFront 14 | 15 | ### Uses 16 | 17 | - Create a CDN for Amazon S3, Amazon EC2 or Elastic Load Balancing 18 | - Add Https to S3 static site 19 | 20 | Features 21 | 22 | - Restrict content to certain geographic regions 23 | 24 | ## Add To S3 Static Site 25 | 26 | AWS WHY? 27 | 28 | - DONT SELECT THE SUGGESTED BUCKET 29 | - DO NOT SET *Default Root Object* PROPERTY! 30 | - Instead use the actual url of the S3 static site 31 | 32 | ## Using your own domain 33 | 34 | Must have certificate validating you own the domain, ACM offers something, but must be us-east-1 35 | 36 | -------------------------------------------------------------------------------- /Deployment/AWS/Cloudwatch.md: -------------------------------------------------------------------------------- 1 | # Cloudwatch 2 | 3 | Combine data from many sources e.g microservices 4 | 5 | Alarm and stats 6 | 7 | If CPU usage too high, then spin up new EC2 8 | 9 | Create custom metrics 10 | 11 | Log management 12 | 13 | Free tier includes a good amount of logs, dashboards, and metrics don't be too afraid to use very worth -------------------------------------------------------------------------------- /Deployment/AWS/Codepipeline.md: -------------------------------------------------------------------------------- 1 | # Code Pipeline 2 | 3 | Has Input Layer (github, S3) 4 | 5 | Has Build Layer (CodeBuild) 6 | 7 | Has Deploy Layer (EBS, CodeDeploy) 8 | 9 | Each Layer is defined in terms of inputs and outputs which are overriden from the defaults 10 | 11 | ## Notifications 12 | 13 | In Cloudwatch Events, can listen for changes to code pipeline status and send notifications -------------------------------------------------------------------------------- /Deployment/AWS/Docker.md: -------------------------------------------------------------------------------- 1 | # Docker in AWS 2 | 3 | ## EC2 4 | 5 | Instance should be Linux 2 or AMI 6 | 7 | ```bash 8 | sudo yum update -y 9 | 10 | # Linux 2 11 | sudo amazon-linux-extras install docker 12 | #OR Linux 13 | sudo yum install docker 14 | 15 | sudo service docker start 16 | #Adds ec2-user to the docker group to use docker w/out sudo. Need to relog 17 | sudo usermod -a -G docker ec2-user 18 | ``` 19 | 20 | Make sure to expose port 80 and then you can access it through the IP address 21 | 22 | ## See Docker basics for how to use 23 | 24 | -------------------------------------------------------------------------------- /Deployment/AWS/EC2/README.md: -------------------------------------------------------------------------------- 1 | # EC2 2 | 3 | Elastic 4 | 5 | Use elastic IP to stop yourself from changing 6 | 7 | If you have to install boilerplate like Docker and such, you can do so on an EC2 instance. Then create an AMI from an existing EC2 that you can use for future things or future scaling. -------------------------------------------------------------------------------- /Deployment/AWS/ELB.md: -------------------------------------------------------------------------------- 1 | # ELB (Elastic Load Balancing) 2 | 3 | Regional highly available to route traffic to different EC2 or IP address 4 | 5 | ## 3 Types 6 | 7 | **Application Load Balancer** operates at the request level (layer 7), routing based on request contents. Ideal for HTTP/HTTPS load balancing 8 | 9 | **Network Load Balancer** operates at the connection level (Layer 4), routing within Amazon Virtual Private Cloud (Amazon VPC) based on IP protocol data. Ideal for load balancing of both TCP and UDP traffic. Lower level so faster and able to handle sudden and volatile traffic 10 | 11 | **Classic** is for EC2 Classic 12 | 13 | ## Adding HTTPS 14 | 15 | You can add a listener for HTTPS at port 443, must have SSL Certificate in same region 16 | 17 | To make http redirect to HTTPS, need to add a ngnix configuration script to .ebextensions, check out [this for an example](https://github.com/jsfuentes/Node-Base/tree/master/.ebextensions) -------------------------------------------------------------------------------- /Deployment/AWS/IAM.md: -------------------------------------------------------------------------------- 1 | # IAM roles 2 | 3 | IAM roles are a secure way to grant permissions to entities that you trust. Examples of entities include the following: 4 | 5 | - IAM user in another account 6 | - Application code running on an EC2 instance that needs to perform actions on AWS resources 7 | - An AWS service that needs to act on resources in your account to provide its features 8 | - Users from a corporate directory who use identity federation with SAML 9 | 10 | IAM roles issue keys that are valid for short durations, making them a more secure way to grant access. -------------------------------------------------------------------------------- /Deployment/AWS/Lambda.md: -------------------------------------------------------------------------------- 1 | # AWS Lambda (Serverless) 2 | 3 | - run code without provisioning or managing servers 4 | - check out aws toolkit for vscode to more easily connect/test lambda 5 | 6 | Uses: 7 | 8 | - Runs code based on events like S3/DB changes 9 | - ETLs(Extract Transform Load for data analytics) 10 | - Can be used as an API with Amazon API Gateway where you only pay per request (great for small, semi unused projects) 11 | 12 | * See zappa for how to deploy python 13 | -------------------------------------------------------------------------------- /Deployment/AWS/SES.md: -------------------------------------------------------------------------------- 1 | # Simple Email Service 2 | 3 | Cheap at only .1/1000 email and pay as you go 4 | 5 | -------------------------------------------------------------------------------- /Deployment/AWS/SQS.md: -------------------------------------------------------------------------------- 1 | # Simple Queue Service 2 | 3 | **See Deployment/Task_Queues for comparing between services, this is just a stub** 4 | 5 | - Simplest to spin up in AWS with free tier offering 1M free messages 6 | - The service must be long **polled** for messages 7 | - Offers high throughput Standard "at least-once-delievery" which requeues a message if it was consumed from the queue and a visibility timeout passes 8 | - Can also do up to 3k message/sec when order important with SQS FIFO "exactly once delivery" 9 | - Base rate of 20k+/sec with more expensive options to request 10 | - Messages must be less than 256KiB in size, but can turn it into S3 object 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Deployment/AWS/Storage/Autoscaling.md: -------------------------------------------------------------------------------- 1 | # Autoscaling 2 | 3 | Can have autoscaling EC2 react to cloud watch 4 | 5 | ## Creation 6 | 7 | Make a launch configuration 8 | 9 | Autoscaling group: 10 | 11 | 2) Configure scaling policies: when to scale and min and max 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Deployment/AWS/Storage/CustomEC2.md: -------------------------------------------------------------------------------- 1 | # Make DB in EC2 2 | 3 | Just run your custom DB in EC2 4 | 5 | -------------------------------------------------------------------------------- /Deployment/AWS/Storage/DynamoDB.md: -------------------------------------------------------------------------------- 1 | # [DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html) 2 | 3 | - NoSQL, fully managed, on demand autoscale 4 | - Supports document and key-value store models 5 | - Free Tier 6 | - DynamoDB won't let you write a bad query, which means you HAVE to have an index to do many queries 7 | - Query will be same speed at 100X scale unlike SQL 8 | 9 | 10 | ## Indexes 11 | 12 | Primary Keys - determine which partition its stored in, can also have sort key that determines order its in 13 | 14 | Secondary Keys - 15 | 16 | ## Creation 17 | 18 | Create Tables, 3 Options 19 | 20 | They will have items that are rows 21 | 22 | Amazon gives you UI to see it 23 | 24 | -------------------------------------------------------------------------------- /Deployment/AWS/Storage/README.md: -------------------------------------------------------------------------------- 1 | # Storage 2 | 3 | Object level storage(DB) vs block level storage(S3): 4 | 5 | - block level 6 | - allows more fine tuned updates like to contact info 7 | - DB restrictions and organiztion allows complex and faster queries 8 | - object level: 9 | - will update the entire pic 10 | - no restrictions on data, can be huge files(up to 5TB) 11 | 12 | ## Amazon EBS(Elastic Block Storage) 13 | 14 | Block Storage 15 | 16 | Amazon Elastic Block Store (EBS) is an easy to use, high performance block storage service designed for use with Amazon Elastic Compute Cloud (EC2) 17 | 18 | is a general thing like SSD backed for databases form No-SQL to SQL or hard disk backed for throughput intensive 19 | 20 | ## EFS (Elastic File System) 21 | 22 | Can attach massively parallel shared access file system to different EC2s, will be in the same subnet 23 | 24 | Higher throughput and lower latency then S3 -------------------------------------------------------------------------------- /Deployment/AWS/VPC.md: -------------------------------------------------------------------------------- 1 | # Virtual Private Cloud (VPC) 2 | 3 | You control all resources inside VPC, can create subnets that isolate parts 4 | 5 | 10.10.0.0/16 : means first 16 bits are frozen 6 | 7 | Makes this the total VPC 8 | 9 | 10.10.1.0/24 means first 24 bits are frozen 10 | 11 | ## IGW 12 | 13 | All connections with subnet through internet gateway 14 | 15 | Attach it, add route table 16 | 17 | ## Create a private subnet 18 | 19 | Good for databases that shouldn't be accessed by outside 20 | 21 | Inside VPC can access each other 22 | 23 | ### Multiple Zones Elastic Load Blancer 24 | 25 | Launch many private subnets on another zone for high avalibility 26 | 27 | Use elastic load blancer to do it between subnets 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Deployment/AWS/zappa.md: -------------------------------------------------------------------------------- 1 | # Zappa 2 | 3 | Zappa is for deploying serverless python apps to AWS Lambda, 4 | 5 | - Use **Python 3.9.16**, currently only supports 3.6-3.9 6 | 7 | ```bash 8 | pip install zappa 9 | zappa init 10 | zappa deploy 11 | ``` 12 | 13 | To update prod later 14 | 15 | ```bash 16 | zappa update production 17 | ``` 18 | 19 | To check fails and logs 20 | 21 | ``` 22 | zappa tail production 23 | ``` 24 | 25 | *If deploy fails cuz no psycopg2 and its in the requirements.txt try `pip install psycopg2-binary` 26 | 27 | ## Guides 28 | 29 | [Flask](https://medium.com/hacktive-devs/deploy-flask-applications-as-aws-lambda-with-zappa-962409687240) 30 | 31 | ![Screenshot 2023-03-24 at 10.20.59 AM](/Users/jfuentes/Library/Containers/at.EternalStorms.Yoink/Data/Documents/YoinkPromisedFiles/yoinkFilePromiseCreationFolder85557727-3A1F-4D88-B72C-5D66903503C6/add85557727-3A1F-4D88-B72C-5D66903503C6/Screenshot 2023-03-24 at 10.20.59 AM.png) 32 | 33 | -------------------------------------------------------------------------------- /Deployment/Cloud GPUS/paperspace.md: -------------------------------------------------------------------------------- 1 | # Paperspace 2 | 3 | Cloud GPUs that you can spin up and down like a server, saves state for free! 4 | 5 | ssh paperspace@172.83.15.38 6 | 7 | -------------------------------------------------------------------------------- /Deployment/Cloud GPUS/replicate.md: -------------------------------------------------------------------------------- 1 | # Replicate 2 | 3 | ```shell 4 | pip install replicate 5 | ``` 6 | 7 | Next, [copy your API token](https://replicate.com/account) and authenticate by setting it as an environment variable: 8 | 9 | ```console 10 | export REPLICATE_API_TOKEN=[token] 11 | ``` 12 | 13 | Then, run the model: 14 | 15 | ```python 16 | import replicate 17 | output = replicate.run( 18 | "devxpy/cog-wav2lip:8d65e3f4f4298520e079198b493c25adfc43c058ffec924f2aefc8010ed25eef", 19 | input={"face": open("path/to/file", "rb")} 20 | ) 21 | print(output) 22 | ``` 23 | 24 | ### Nodejs 25 | 26 | ``` 27 | ``` 28 | 29 | -------------------------------------------------------------------------------- /Deployment/DigitalOcean.md: -------------------------------------------------------------------------------- 1 | # Digital Ocean 2 | 3 | -------------------------------------------------------------------------------- /Deployment/GCP/Compute.md: -------------------------------------------------------------------------------- 1 | # Compute 2 | 3 | [Setup Postgres on Compute](https://cloud.google.com/community/tutorials/setting-up-postgres) 4 | 5 | 1. In the Cloud Console, go to the [**VM instances**](https://console.cloud.google.com/compute/instances) page. 6 | 2. Click **Create**. 7 | 3. Use General Purpose > N1 > f1-micro 8 | 4. In the **Public images** tab, choose **Ubuntu** for **Operating system**. 9 | 5. In the **Version** dropdown list, choose **Ubuntu 20.04 LTS**. 10 | 6. In the **Boot disk type** section, select **Standard persistent disk**. 11 | 7. Click **Select**. 12 | 8. Click **Create** to create the instance. 13 | 14 | -------------------------------------------------------------------------------- /Deployment/GCP/Network.md: -------------------------------------------------------------------------------- 1 | # Network 2 | 3 | When creating compute add a tag: 4 | 5 | Under the **Firewall** section, expand **Management, security, disks, networking, sole tenancy**, select the **Networking** tab, and enter `postgres-tutorial` for the **Network tags** field. 6 | 7 | Then in VPC network > Firewall you can add rules to all everyone to access by using that tag -------------------------------------------------------------------------------- /Deployment/GCP/README.md: -------------------------------------------------------------------------------- 1 | # Google Cloud Platform 2 | 3 | ### Compare to AWS 4 | 5 | - Better UI/UX, but less polished/buggy interface 6 | - [Always free tier of most things](https://cloud.google.com/free) 7 | - 1 Micro Instance & 1 App Engine 8 | - 5GB of Cloud Storage 9 | - NoSQL DB -------------------------------------------------------------------------------- /Deployment/Github/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jsfuentes/Code-Cheatsheet/30a9cd5ee04200b17ec711d162d8714bb3b7b550/Deployment/Github/README.md -------------------------------------------------------------------------------- /Deployment/cloudflare.md: -------------------------------------------------------------------------------- 1 | # Cloudflare 2 | 3 | Becomes your DNS provider and adds a cache layer in front of your server 4 | 5 | Allows you to CNAME a root domain 6 | 7 | FREE SSL & FREE CACHING WTF 8 | 9 | Very helpful support articles and UI 10 | 11 | 1) Add DNS Records 12 | 13 | 2) Go to ssl/tls and edge certificates to enable 14 | 15 | ### Redirect non-www to www 16 | 17 | Need record for both non-www and www 18 | 19 | Add pagerule that redirect `example.com*` to `https://www.example.com/$1` 20 | 21 | -------------------------------------------------------------------------------- /Deployment/loadtesting.md: -------------------------------------------------------------------------------- 1 | https://loader.io/ - free load testing by sendgrid -------------------------------------------------------------------------------- /Deployment/processManagement.md: -------------------------------------------------------------------------------- 1 | # Process Management 2 | 3 | Easily start and stop processes and look at 4 | 5 | - pm2 6 | - pm2 monit 7 | - http://supervisord.org/ 8 | - [Let’s Encrypt](https://letsencrypt.org/) - running [certbot](https://certbot.eff.org/) 9 | 10 | ## Pm2 11 | 12 | Application manager for node 13 | 14 | Easily start and stop background node processes, 15 | 16 | | Cmd | Effect | 17 | | ------------------ | ------------------------------ | 18 | | pm2 list | list process | 19 | | pm2 monit | monitor connections in cool UI | 20 | | pm2 start app.js | Start | 21 | | pm2 stop app.js | | 22 | | pm2 restart app.js | | 23 | 24 | Might also do some cool logging -------------------------------------------------------------------------------- /Deployment/redis.md: -------------------------------------------------------------------------------- 1 | # Redis 2 | 3 | Inmemory data store and pubsub for ephermal/persistent and distrubuted cache, queue, or pubsub 4 | 5 | Many providers that allow VPC access(cant use in local dev) -------------------------------------------------------------------------------- /Deployment/sockets.md: -------------------------------------------------------------------------------- 1 | # Socket Alternatives 2 | 3 | https://www.pubnub.com 4 | 5 | socket.io-redis 6 | 7 | https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events -------------------------------------------------------------------------------- /Deployment/speed_opt.md: -------------------------------------------------------------------------------- 1 | # Speed Optimizations 2 | 3 | https://gtmetrix.com/ 4 | 5 | Compress with gzip ([express](https://www.npmjs.com/package/compression)) or use a CDN like cloudflare 6 | 7 | Speed performance test available in chrome and https://gtmetrix.com/ 8 | 9 | -------------------------------------------------------------------------------- /Deployment/surge.md: -------------------------------------------------------------------------------- 1 | # {Surge 2 | 3 | For fully static sites, HTML, CSS, SJ 4 | 5 | ```bash 6 | npm install --global surge 7 | 8 | # Then create a (free) account with them 9 | surge 10 | 11 | surge --help 12 | 13 | surge #need domain to relaunch in domain 14 | ``` 15 | 16 | ## React Router 17 | 18 | For react router, you need it to always go to the index.html page, simply change the name of the index.html page to `200.html` and it will route every successful request there 19 | 20 | -------------------------------------------------------------------------------- /Deployment/vercel.md: -------------------------------------------------------------------------------- 1 | # Vercel 2 | 3 | ```bash 4 | npm i -g vercel 5 | ``` 6 | 7 | Zeit ez, first deploy is prod else dev 8 | 9 | ```bash 10 | vercel #will link autolink to zeit/github project 11 | vercel -e KEY=value #include env variables 12 | vercel --prod #prod deployment 13 | ``` 14 | 15 | Use to include environment variables 16 | 17 | Look in main folders now.json for variables like the project name 18 | 19 | ## Domains 20 | 21 | 1. In the GUI online, you can import from a github repo easily 22 | 2. You can then click settings, domains to add a domain 23 | 24 | OR 25 | 26 | ``` 27 | now domains add 28 | ``` 29 | 30 | 3. Get www redirect: Add www.jsfuentes.com AND jsfuentes.com, then go to GUI domains and set a redirect from www to jsfuentes 31 | 32 | ## [Analytics](https://vercel.com/docs/concepts/analytics/quickstart) 33 | 34 | Comes with analytics 35 | 36 | -------------------------------------------------------------------------------- /JS/All/Angular/bash.md: -------------------------------------------------------------------------------- 1 | # Angular 2 | ## Bash Commands 3 | ```bash 4 | ng new [name] 5 | 6 | ng serve --open 7 | 8 | ng generate component heroes 9 | 10 | ng generate directive|pipe|service|class|guard|interface|enum|module 11 | 12 | ng generate service hero 13 | ng generate service message --module=app 14 | 15 | ng generate module app-routing --flat --module=app 16 | ``` 17 | 18 | `--flat` = don’t put in own folder 19 | 20 | `--module=app` = put in module app 21 | -------------------------------------------------------------------------------- /JS/All/Angular/input.md: -------------------------------------------------------------------------------- 1 | ##### input 2 | ```html 3 |
    4 | 7 | 8 | 11 |
    12 | ``` 13 | 14 | ##### @Input 15 | 16 | Getting input into component 17 | ```ts 18 | @Input() hero: Hero; 19 | ``` 20 | -------------------------------------------------------------------------------- /JS/All/Angular/typescript.md: -------------------------------------------------------------------------------- 1 | ## TypeScript: 2 | 3 | ##### Classes 4 | In a hero.ts file, then import it everywhere you use it 5 | ```ts 6 | export class Hero { 7 | id: number; 8 | name: string; 9 | } 10 | ``` 11 | 12 | ##### Services: 13 | 14 | `providers: [HeroService]` in app.module.ts 15 | 16 | ```ts 17 | constructor(private heroService: HeroService) { 18 | } 19 | 20 | ngOnInit() { 21 | this.heroes = this.heroService.getHeroes(); 22 | } 23 | ``` 24 | 25 | - In a class, public if you use it in the html or something 26 | - Define getHeroes in the service 27 | -------------------------------------------------------------------------------- /JS/All/Chrome_Plugins/README.md: -------------------------------------------------------------------------------- 1 | # [Chrome Plugins](https://developer.chrome.com/extensions/devguide) 2 | 3 | - Chrome.runtime is available on any webpage 4 | - Since Manifest V3, can't use any remote code including any CDNs or packages that load code remotely 5 | 6 | To get file from built folder, 7 | 8 | ```js 9 | chrome.runtime.getURL("../myfile.html"); //relative path 10 | ``` 11 | 12 | Catch errors 13 | 14 | ```js 15 | chrome.runtime.lastError.message 16 | ``` 17 | 18 | ## Keep constant Chrome-ID 19 | 20 | Add key value to the manifest.json 21 | 22 | 1. Go to https://chrome.google.com/webstore/developer/dashboard/ and click more Info to get the key 23 | 3. Add that key value to your manifest.json 24 | 25 | -------------------------------------------------------------------------------- /JS/All/Chrome_Plugins/browser_action.md: -------------------------------------------------------------------------------- 1 | # Browser Action 2 | 3 | *Untested in Manifest V3* 4 | 5 | ```js 6 | await browser.action.setBadgeBackgroundColor({ 7 | color: "#000000" 8 | }); 9 | 10 | await browser.browserAction.setBadgeText({ 11 | text: number.toString() 12 | }); 13 | ``` 14 | 15 | If badge text set to "", then the badge completely disappears regardless of teh badge color -------------------------------------------------------------------------------- /JS/All/Chrome_Plugins/context_menu.md: -------------------------------------------------------------------------------- 1 | # Context Menu 2 | 3 | Can add stuff to the right click menu 4 | 5 | Need `"contextMenus"` permission in the manifest 6 | 7 | background.js 8 | 9 | ```js 10 | function searchUrbanDict(word) { 11 | debug("TESTING STUFF"); 12 | }; 13 | 14 | browser.contextMenus.create({ 15 | title: "Search in UrbanDictionary", 16 | contexts: ["selection"], // ContextType 17 | onclick: searchUrbanDict, // A callback function 18 | }); 19 | ``` 20 | 21 | #### ContextTypes 22 | 23 | `"all"`, `"page"`, `"frame"`, `"selection"`, `"link"`, `"editable"`, `"image"`, `"video"`, `"audio"`, `"launcher"`, `"browser_action"`, or `"page_action"` 24 | 25 | #### ItemTypes 26 | 27 | `"normal"`, `"checkbox"`, `"radio"`, or `"separator"` -------------------------------------------------------------------------------- /JS/All/Chrome_Plugins/deploying.md: -------------------------------------------------------------------------------- 1 | # Deploying 2 | 3 | https://developer.chrome.com/webstore/publish 4 | 5 | 1) Go to https://chrome.google.com/webstore/developer/dashboard 6 | 7 | 2) Upload zipped folder of Chrome Plugin with manifest.json in root 8 | 9 | 3) If you need the oauth extension key, then you can find it in the url of the submission draft -------------------------------------------------------------------------------- /JS/All/Chrome_Plugins/events.md: -------------------------------------------------------------------------------- 1 | # Events 2 | 3 | #### When Installed 4 | 5 | ```javascript 6 | chrome.runtime.onInstalled.addListener(() => { 7 | //...... 8 | }); 9 | ``` 10 | 11 | #### Bookmarks Created 12 | 13 | ```javascript 14 | chrome.bookmarks.onCreated.addListener(function() { 15 | //...... 16 | }); 17 | ``` 18 | 19 | #### Tab changes 20 | 21 | [tabs.onUpdated](https://developer.chrome.com/extensions/extensions/tabs#event-onUpdated) 22 | 23 | #### Navigation to Page 24 | 25 | webNavigation supports filters 26 | 27 | ```javascript 28 | chrome.webNavigation.onCompleted.addListener(() => { 29 | alert("This is my favorite website!"); 30 | }, {url: [{urlMatches : 'https://www.google.com/'}]}); 31 | ``` -------------------------------------------------------------------------------- /JS/All/Chrome_Plugins/setup.md: -------------------------------------------------------------------------------- 1 | # Setup 2 | 3 | ## Min Chrome Plugin 4 | 5 | manifest.json 6 | 7 | ```json 8 | { 9 | "manifest_version": 3, 10 | "name": "Hello Extensions", 11 | "description": "Base Level Extension", 12 | "version": "1.0", 13 | "action": { 14 | "default_popup": "hello.html", 15 | "default_icon": "hello_extensions.png" 16 | } 17 | } 18 | ``` 19 | 20 | hello.html 21 | 22 | ```html 23 | 24 | 25 |

    Hello Extensions

    26 | 27 | 28 | ``` 29 | 30 | ### [Load unpacked extension](https://developer.chrome.com/docs/extensions/get-started/tutorial/hello-world#load-unpacked) 31 | 32 | 1. Go to `chrome://extensions` 33 | 2. Click load unpacked and select extension directory 34 | 35 | - Now when you make changes click the reload button for that plugin in `chrome://extensions` -------------------------------------------------------------------------------- /JS/All/Chrome_Plugins/shortcuts.md: -------------------------------------------------------------------------------- 1 | # Shortcuts / Commands 2 | 3 | Listen for key presses and get event in background script 4 | 5 | background listener 6 | 7 | ```js 8 | browser.commands.onCommand.addListener((command) => { 9 | debug("Command:", command); 10 | if (command === "insert-request-link") { 11 | insertRequestLink(); 12 | } 13 | }); 14 | ``` 15 | 16 | manifest.json 17 | 18 | ```json 19 | "commands": { 20 | "start-recording": { 21 | "suggested_key": { 22 | "default": "Ctrl+Shift+E", 23 | "mac": "Command+Shift+E" 24 | }, 25 | "description": "Toggle feature foo" 26 | } 27 | }, 28 | ``` 29 | 30 | -------------------------------------------------------------------------------- /JS/All/Chrome_Plugins/tabs.md: -------------------------------------------------------------------------------- 1 | # Tabs 2 | 3 | Mostly don't need `tabs` permission, except to populate `url`, `pendingUrl`, `title`, and `favIconUrl` properties of `Tab`. 4 | 5 | ### Open New Tab 6 | 7 | ```js 8 | const createProperties = { url: `localhost:3000/show/${show_id}/edit` }; 9 | browser.tabs 10 | .create(createProperties) 11 | .catch(err => console.error("Tab create error: ", err)); 12 | ``` 13 | 14 | ### Get active tab 15 | 16 | ```js 17 | const tabs = await browser.tabs.query({ 18 | lastFocusedWindow: true, 19 | active: true 20 | }); 21 | const activeTab = tabs[0]; 22 | ``` 23 | 24 | ### Send Message to All Tabs 25 | 26 | ```js 27 | browser.tabs.query({}).then((tabs) => { 28 | tabs.forEach((tab) => { 29 | ensureValidContent(tab.id).catch(console.error); 30 | }); 31 | }); 32 | ``` 33 | 34 | -------------------------------------------------------------------------------- /JS/All/Chrome_Plugins/url_match.md: -------------------------------------------------------------------------------- 1 | # Match Patterns 2 | 3 | ``` 4 | := :// 5 | := '*' | 'http' | 'https' | 'file' | 'ftp' 6 | := '*' | '*.' + 7 | := '/' 8 | ``` 9 | 10 | -------------------------------------------------------------------------------- /JS/All/Electron/deeplinks.md: -------------------------------------------------------------------------------- 1 | # Deep Links 2 | 3 | How do you have a link open in your app? 4 | 5 | If you are using electron-builder, edit your build key in the package.json 6 | 7 | ```json 8 | "build": { 9 | "productName": "Slingshow", 10 | "appId": "org.jn.Slingshow", 11 | "protocols": { 12 | "name": "slingshow-protocol", 13 | "schemes": [ 14 | "slingshow" 15 | ] 16 | }, 17 | } 18 | ``` 19 | 20 | main.js 21 | 22 | ```javascript 23 | // This will catch clicks on links such as open in slingshow 24 | app.on("open-url", (event, data) => { 25 | event.preventDefault(); 26 | console.log("URL OPENED", event, data); 27 | }); 28 | 29 | app.setAsDefaultProtocolClient("slingshow"); 30 | ``` 31 | 32 | Data will just be the url like `Slingshow://help=me` 33 | 34 | -------------------------------------------------------------------------------- /JS/All/Electron/dialog.md: -------------------------------------------------------------------------------- 1 | # Dialog 2 | 3 | Show blocking native messages 4 | 5 | ```js 6 | const indexOfClickedButton = dialog.showMessageBoxSync({ 7 | type: "warning", 8 | message: "Welcome to the future", 9 | title: "Permissions Error" 10 | }); 11 | console.log("Printed after the message is accepted") 12 | ``` 13 | 14 | -------------------------------------------------------------------------------- /JS/All/Electron/image.md: -------------------------------------------------------------------------------- 1 | # Images 2 | 3 | In Electron, for the APIs that take images, you can pass either file paths or `NativeImage` instances. 4 | 5 | ### Native Images 6 | 7 | ```javascript 8 | 9 | ``` 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /JS/All/Electron/messages.md: -------------------------------------------------------------------------------- 1 | # Messages 2 | 3 | ## From Main to Render 4 | 5 | Main 6 | 7 | ```js 8 | win.webContents.send('async-msg', 'pinggg'); 9 | ``` 10 | 11 | Renderer 12 | 13 | ```js 14 | ipc.on('reply', (event, arg) => { 15 | console.log("Message is ", arg); 16 | }) 17 | ``` 18 | 19 | ### From Render to Main 20 | 21 | main.js 22 | 23 | ```js 24 | import { ipcMain } from "electron"; 25 | 26 | ipcMain.on("async-msg", (event, arg) => { 27 | console.log(arg); 28 | event.sender.send('reply', 'pong'); 29 | }); 30 | ``` 31 | 32 | renderer.js 33 | 34 | ```js 35 | const ipc = require("electron").ipcRenderer; 36 | 37 | ipc.send("start-recording", "ping"); 38 | 39 | ipc.on('reply', (event, arg) => { 40 | console.log("Message is ", arg); 41 | }) 42 | ``` 43 | 44 | -------------------------------------------------------------------------------- /JS/All/Electron/multiplatform.md: -------------------------------------------------------------------------------- 1 | # Differences Between Platforms 2 | 3 | ## Mac 4 | 5 | Icon in taskbar is application icon(.ico or .icns) 6 | 7 | ## Linux 8 | 9 | Icon is taskbar is window icon 10 | 11 | ```js 12 | mainWindow = new BrowserWindow({ 13 | title: 'ElectronApp', 14 | icon: __dirname + '/app/assets/img/icon.png', 15 | }); 16 | ``` -------------------------------------------------------------------------------- /JS/All/Electron/notarizing.md: -------------------------------------------------------------------------------- 1 | Need many things -------------------------------------------------------------------------------- /JS/All/Electron/packages/README.md: -------------------------------------------------------------------------------- 1 | # Electron Packages 2 | 3 | Cool ones to check out 4 | 5 | - [devtron](https://www.electronjs.org/devtron) -------------------------------------------------------------------------------- /JS/All/Electron/packages/electron-is-dev.md: -------------------------------------------------------------------------------- 1 | # Electron-is-Dev 2 | 3 | Simplest package ever, but it is recommended by the electron website so it must add value 4 | 5 | ```npm install electron-is-dev``` 6 | 7 | ```js 8 | const isDev = require('electron-is-dev'); 9 | 10 | if (isDev) { 11 | console.log('Running in development'); 12 | } else { 13 | console.log('Running in production'); 14 | } 15 | ``` 16 | 17 | ## The actual code lol 18 | 19 | ```js 20 | 'use strict'; 21 | const electron = require('electron'); 22 | 23 | const app = electron.app || electron.remote.app; 24 | 25 | const isEnvSet = 'ELECTRON_IS_DEV' in process.env; 26 | const getFromEnv = parseInt(process.env.ELECTRON_IS_DEV, 10) === 1; 27 | 28 | module.exports = isEnvSet ? getFromEnv : !app.isPackaged; 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /JS/All/Electron/packages/electron-log.md: -------------------------------------------------------------------------------- 1 | # Electron-Log 2 | 3 | Log to file in production 4 | 5 | By default, it writes logs to the following locations: 6 | 7 | - **on Linux:** `~/.config/{app name}/logs/{process type}.log` 8 | - **on macOS:** `~/Library/Logs/{app name}/{process type}.log` 9 | - **on Windows:** `%USERPROFILE%\AppData\Roaming\{app name}\logs\{process type}.log` 10 | 11 | ```js 12 | const log = require("electron-log"); 13 | Object.assign(console, log.functions); //replace console with file logging in the main process 14 | ``` 15 | 16 | Supports following log levels 17 | 18 | ``` 19 | error, warn, info, verbose, debug, silly 20 | ``` 21 | 22 | ### -------------------------------------------------------------------------------- /JS/All/Electron/packages/forge.md: -------------------------------------------------------------------------------- 1 | # [Electron-Forge](https://www.electronforge.io/) 2 | 3 | Add webpack to get hotreloading 4 | 5 | There is a [react template](https://github.com/electron-userland/electron-forge-templates), but for some reason it is deprecated or something.. 6 | 7 | ```bash 8 | npx create-electron-app electron --template=webpack 9 | cd electron #preinstalled to yarn.lock 10 | rm -rf yarn.lock node_modules 11 | npm install 12 | npm start 13 | ``` 14 | 15 | #### Building 16 | 17 | ```bash 18 | npm run make #=> electron-forge make 19 | ``` 20 | 21 | ### Config 22 | 23 | example.forge.config.js 24 | 25 | ```js 26 | { 27 | packagerConfig: { ... }, 28 | electronRebuildConfig: { ... }, 29 | makers: [ ... ], 30 | publishers: [ ... ], 31 | plugins: [ ... ], 32 | hooks: { ... }, 33 | buildIdentifier: 'my-build' 34 | } 35 | ``` 36 | 37 | -------------------------------------------------------------------------------- /JS/All/Electron/packages/sentry.md: -------------------------------------------------------------------------------- 1 | # Sentry 2 | 3 | ```js 4 | import * as Sentry from "@sentry/electron"; 5 | 6 | Sentry.init({ 7 | dsn: "https://[hi]@sentry.io/2590109" 8 | }); 9 | ``` 10 | 11 | -------------------------------------------------------------------------------- /JS/All/Electron/renderer.md: -------------------------------------------------------------------------------- 1 | # Renderer Process 2 | 3 | Access remote 4 | 5 | ```js 6 | const { dialog } = require('electron').remote 7 | console.log(dialog); 8 | ``` 9 | 10 | Make file that works in both 11 | 12 | ```js 13 | const electron = require("electron"); 14 | const dialog = electron.dialog || electron.remote.dialog; //ensure works in both main and renderer 15 | ``` 16 | 17 | -------------------------------------------------------------------------------- /JS/All/Electron/tray.md: -------------------------------------------------------------------------------- 1 | # Tray 2 | 3 | ```javascript 4 | const { app, Menu, Tray } = require('electron') 5 | 6 | let tray = null 7 | app.on('ready', () => { 8 | tray = new Tray('/path/to/my/icon') 9 | const contextMenu = Menu.buildFromTemplate([ 10 | { label: 'Item1', type: 'radio' }, 11 | { label: 'Item2', type: 'radio' }, 12 | { label: 'Item3', type: 'radio', checked: true }, 13 | { label: 'Item4', type: 'radio' } 14 | ]) 15 | tray.setToolTip('This is my application.') 16 | tray.setContextMenu(contextMenu) 17 | }) 18 | ``` 19 | 20 | ## Icons 21 | 22 | Use **Template Images** for Mac OS so it can flip on dark/light mode 23 | 24 | Template images consist of black and an alpha channel 25 | 26 | To mark an image as a template image, its filename should end with the word `Template`. For example: 27 | 28 | - `xxxTemplate.png` 29 | - `xxxTemplate@2x.png` -------------------------------------------------------------------------------- /JS/All/Node/ejs.md: -------------------------------------------------------------------------------- 1 | # ejs Templating 2 | 3 | ## Basics 4 | `<% [code here] %>` 5 | 6 | ## Partials 7 | Under the views/partials/ directory create a file called footer.ejs 8 | `<%- include('partials/footer') %>` 9 | 10 | ## IF 11 | ```js 12 | <% if (user) { %> 13 |

    <%= user.name %>

    14 | <% } %> 15 | ``` 16 | 17 | ## Loop 18 | ```js 19 | <% users.forEach(function(user){ %> 20 | <%- include('user/show', {user: user}); %> 21 | <% }); 22 | %> 23 | ``` 24 | 25 | ## Tags 26 | <% 'Scriptlet' tag, for control-flow, no output 27 | <%_ ‘Whitespace Slurping’ Scriptlet tag, strips all whitespace before it 28 | <%= Outputs the value into the template (HTML escaped) 29 | <%- Outputs the unescaped value into the template 30 | <%# Comment tag, no execution, no output 31 | <%% Outputs a literal '<%' 32 | %> Plain ending tag 33 | -%> Trim-mode ('newline slurp') tag, trims following newline 34 | _%> ‘Whitespace Slurping’ ending tag, removes all whitespace after it 35 | -------------------------------------------------------------------------------- /JS/All/Node/env.md: -------------------------------------------------------------------------------- 1 | # Env 2 | 3 | See packages/dotenv 4 | 5 | Node.js 20 adds support for .env. files 6 | 7 | ```bash 8 | node --env-file=.env app.js 9 | ``` 10 | 11 | then in code 12 | 13 | ```js 14 | process.env.PORT; // "3000" 15 | ``` 16 | 17 | -------------------------------------------------------------------------------- /JS/All/Node/forms.md: -------------------------------------------------------------------------------- 1 | # Forms 2 | 3 | ## Access data 4 | - `req.body` is JSON of data 5 | - `req.body.name` 6 | 7 | ## Images 8 | ```HTML 9 | 10 | ``` 11 | 12 | ## Multer 13 | Adds support for `enctype="multipart/form-data"` 14 | ```js 15 | const multer = require('multer'); 16 | 17 | const upload = multer({ dest: 'public/uploads/'}); 18 | 19 | router.post('/create', upload.any(), eventsController.event_create); 20 | 21 | //in event_create 22 | const fileInfo = req.files; 23 | ``` 24 | 25 | Now the files are in your filesystem, use them as you would static files. 26 | 27 | ## Mongoose Object 28 | 29 | ```js 30 | var Item = new ItemSchema( 31 | { img: 32 | { data: Buffer, contentType: String } 33 | } 34 | ); 35 | ``` 36 | 37 | ## Access Data 38 | newItem.img.data = fs.readFileSync(req.files.userPhoto.path) 39 | newItem.img.contentType = ‘image/png’; 40 | -------------------------------------------------------------------------------- /JS/All/Node/logging.md: -------------------------------------------------------------------------------- 1 | # Logging 2 | 3 | Could just use default `console.log` and `console.error` and then use bash redirects to a file 4 | 5 | ``` 6 | node index.js > regular.log 2> error.log 7 | ``` 8 | 9 | ## Packages 10 | 11 | - [`pino`](https://getpino.io/) 12 | - [`winston`](https://www.npmjs.com/package/winston) 13 | - [`roarr`](https://www.npmjs.com/package/roarr) 14 | - `log4js` 15 | 16 | allow for log levels, easy toggling logs on and off based on environment 17 | 18 | Logging frameworks will also (generally) support writing to more than just `stdout/stderr`. Winston calls these “transports” while Bunyan calls them “streams”. For example, you can configure writing to stdout, a file, and a database all at once. -------------------------------------------------------------------------------- /JS/All/Node/middleware.md: -------------------------------------------------------------------------------- 1 | # Middleware 2 | 3 | Can add as much middleware as you want to a route 4 | 5 | ```js 6 | router.post('/moderator', [Auth.adminOfPostedId, Auth.canInvite], postModerator); 7 | ``` 8 | 9 | ## Example 10 | 11 | middleware/auth.js 12 | 13 | ```js 14 | const createError = require("http-errors"); 15 | const debug = require("debug")("app:middleware:auth"); 16 | 17 | module.exports = { 18 | logged_in 19 | }; 20 | 21 | function logged_in(req, res, next) { 22 | if (req.session.uid === undefined) { 23 | throw createError().Unauthorized("Need to be logged in"); //handled by error handler 24 | } else { 25 | // debug(`Session active for ${req.session.uid}`); 26 | next(); 27 | } 28 | } 29 | ``` 30 | 31 | ### Next 32 | 33 | `next('route')` will go to next route handler that matches, if you pass anything else into `next()` it will be considered an error -------------------------------------------------------------------------------- /JS/All/Node/packages/commander.md: -------------------------------------------------------------------------------- 1 | # [Commander](https://www.npmjs.com/package/commander) 2 | 3 | Lets you define command line interfaces 4 | 5 | ``` 6 | yarn add commander 7 | ``` 8 | 9 | ## Usage 10 | 11 | command.js 12 | 13 | ```js 14 | const { Command } = require('commander'); 15 | const program = new Command(); 16 | program 17 | .command("join") 18 | .arguments("") 19 | .description("Make bots join an event.") 20 | .option('-d, --debug', 'output extra debugging') 21 | .option("-n, --number ", "Number of bots to summon", 3) 22 | .option( 23 | "--host ", 24 | "Which slingshow instance to point to.", 25 | "localhost:4000" 26 | ) 27 | .action(async (event, options) => { 28 | return join(event, { number: +options.number, host: options.host }); 29 | }); 30 | 31 | program.parse(process.argv); 32 | ``` 33 | 34 | in bash 35 | 36 | ```bash 37 | node command.js join -n 5 38 | ``` 39 | 40 | -------------------------------------------------------------------------------- /JS/All/Node/packages/crypto.md: -------------------------------------------------------------------------------- 1 | # Crypto 2 | 3 | ### Generate Random String 4 | 5 | ```js 6 | var crypto = require("crypto"); 7 | var id = crypto.randomBytes(24).toString('hex'); //byte to hex doubles length, so this will be length 40 8 | ``` 9 | 10 | ## Nanoid 11 | 12 | https://github.com/ai/nanoid 13 | 14 | ```js 15 | const nanoid = require('nanoid') 16 | model.id = nanoid()//=> "V1StGXR8_Z5jdHi6B-myT" 17 | nanoid(10) //=> "IRFa-VaY2b" 18 | ``` 19 | 20 | -------------------------------------------------------------------------------- /JS/All/Node/packages/dotenv.md: -------------------------------------------------------------------------------- 1 | # Dotenv 2 | 3 | Load .env files into your process.env 4 | 5 | ```bash 6 | npm i dotenv 7 | ``` 8 | 9 | ## Usage 10 | 11 | As early as possible, 12 | 13 | ```js 14 | require('dotenv').config() 15 | ``` 16 | 17 | or 18 | 19 | ```js 20 | import 'dotenv/config' 21 | ``` 22 | 23 | That's it. `process.env` now has the keys and values you defined in your `.env` file 24 | -------------------------------------------------------------------------------- /JS/All/Node/req.md: -------------------------------------------------------------------------------- 1 | # Req 2 | 3 | Express v4 requires extra middle ware to handle POST requests 4 | 5 | `app.use(bodyParser.json());` 6 | 7 | Express in 4.16 again has `express.json()` 8 | 9 | ```javascript 10 | app.use(express.json({ limit: "1GB" })); //default limit 100kb 11 | ``` 12 | 13 | ## Access 14 | 15 | ```js 16 | req.query //query parameters 17 | req.body //post body 18 | req.params //url variables like /user/:userid 19 | ``` 20 | 21 | ### Advanced 22 | 23 | #### Get Ip Address 24 | 25 | ```js 26 | const ip = 27 | req.headers["x-forwarded-for"] || 28 | req.connection.remoteAddress || 29 | req.socket.remoteAddress || 30 | (req.connection.socket ? req.connection.socket.remoteAddress : null); 31 | ``` 32 | 33 | #### Headers 34 | 35 | ```javascript 36 | req.headers 37 | ``` 38 | 39 | *See forms for how to do multipart forms for binary/form data* 40 | 41 | -------------------------------------------------------------------------------- /JS/All/Node/res.md: -------------------------------------------------------------------------------- 1 | # Response 2 | 3 | - res.json(); 4 | - res.sendFile(path.join(__dirname, 'index')); 5 | - works best with absolute path 6 | - res.send("Hello"); 7 | - res.redirect('/events'); 8 | - doesn't work well with react router 9 | - res.render('index'); 10 | - res.sendStatus(200); 11 | 12 | ## Render 13 | 14 | To render template files, set view folder and static folder. 15 | 16 | Relative to dir you launch node process from 17 | 18 | ```js 19 | app.set('views', './views'); //this is the default 20 | app.use(express.static('public')) 21 | app.use('/static', express.static('public')) 22 | ``` 23 | 24 | Examples 25 | 26 | ```javascript 27 | res.render('index', { title: 'Hey', msg: 'Hello!' }) 28 | ``` 29 | 30 | ### Respond with Error 31 | 32 | See http-errors 33 | 34 | ```js 35 | res.status(400).send({ 36 | message: 'This is an error!' 37 | }); 38 | 39 | res.status(404).send("Oh uh, something went wrong"); 40 | 41 | res.status(400); 42 | res.send('None shall pass'); 43 | 44 | res.send(404) 45 | ``` -------------------------------------------------------------------------------- /JS/All/Node/setup.md: -------------------------------------------------------------------------------- 1 | # Setup for Nodejs/Express 2 | 3 | `node` will work if you have node 4 | 5 | ## Using Generator 6 | ```bash 7 | npm install express-generator -g 8 | express [project name] --view=ejs 9 | ``` 10 | - `--view=ejs` adds ejs engine support 11 | - `--no-view` 12 | - `--git` adds a gitignore 13 | 14 | ## Running 15 | 16 | Add the following to package.json 17 | 18 | ```json 19 | "scripts": { 20 | "start": "export NODE_ENV=production && node ./bin/www", 21 | "dev": "export NODE_ENV=development && export DEBUG=app* && nodemon ./bin/www" 22 | } 23 | ``` 24 | 25 | Debug is for debug library 26 | 27 | Export works for config library -------------------------------------------------------------------------------- /JS/All/bun.md: -------------------------------------------------------------------------------- 1 | # [Bun](https://bun.sh/) 2 | 3 | - not full node compatibility, still buggy especially test runner, not production ready 4 | 5 | ### benefits 6 | 7 | - dropin node replacement that works with package.json 8 | - Benefits over Node 9 | - `bun run` watches and restarts automatically 10 | - typescript and jsx first class so runnable/transpiled in bun and respects tsconfig 11 | - Built-in package manager, test runner, bundler, and api for server 12 | 13 | - Bun and Node.js are both JavaScript runtimes, but they have some key differences: 14 | - Node.js is primarily written in C++, while Bun is written in Zig 15 | 16 | ### starting server builtin 17 | 18 | ```ts 19 | const server = Bun.serve({ 20 | port: 3000, 21 | fetch(request) { 22 | return new Response("Welcome to Bun!"); 23 | }, 24 | }); 25 | 26 | console.log(`Listening on localhost:${server.port}`); 27 | ``` 28 | 29 | -------------------------------------------------------------------------------- /JS/bundlers/parcel.md: -------------------------------------------------------------------------------- 1 | # Parcel 2 | 3 | Bundling without configuration 4 | 5 | ```bash 6 | npm i parcel 7 | ``` 8 | 9 | 10 | 11 | Simple building 12 | 13 | ```json 14 | "scripts": { 15 | "build": "parcel build src/js/main.js -d src/build/ -o main.js", 16 | "watch": "parcel watch src/js/main.js -d src/build/ -o main.js", 17 | ``` 18 | 19 | If using inside a chrome plugin, use` --no-hmr` flag to not do hot module replacement b/c you cant so will have error 20 | 21 | ## Debugging 22 | 23 | ``` 24 | rm -rf .parcel-cache 25 | ``` 26 | 27 | -------------------------------------------------------------------------------- /JS/bundlers/vite.md: -------------------------------------------------------------------------------- 1 | # [Vite](https://vitejs.dev) 2 | 3 | - Uses esbuild so fasttt 4 | - Better Hot Reloading, uses ESM base dev server which means something like doesnt need to rebundle entire app just part that changed 5 | 6 | ```bash 7 | npm create vite@latest 8 | ``` 9 | 10 | -------------------------------------------------------------------------------- /JS/closure.md: -------------------------------------------------------------------------------- 1 | # Closure 2 | 3 | Javascript has closures meaning functions defined store their environment when they are created 4 | 5 | ```js 6 | function makeFunc() { 7 | var name = 'Mozilla'; 8 | function displayName() { 9 | alert(name); 10 | } 11 | return displayName; 12 | } 13 | 14 | var myFunc = makeFunc(); 15 | myFunc(); //Mozilla 16 | ``` 17 | 18 | Can't rely on closure for global variables 19 | 20 | ```js 21 | let x = 100; 22 | let b = () => () => x; 23 | b()(); //100 24 | x = 10; 25 | b()(); //10 26 | ``` 27 | 28 | This works though 29 | 30 | ```js 31 | let x = 0; 32 | function y() {let z = x++; return () => z} 33 | let a = y(); 34 | let b = y(); 35 | x = 100; 36 | a(); //0 37 | b(); //1 38 | ``` 39 | 40 | -------------------------------------------------------------------------------- /JS/collections/JSON.md: -------------------------------------------------------------------------------- 1 | # JSON 2 | 3 | COmments not supported 4 | 5 | Must be double quotes 6 | 7 | ```json 8 | { 9 | "telephone": { 10 | "comment": "The phone number associated with this POI.", 11 | "type": "string", 12 | "example": "(415)383-9600" 13 | }, 14 | "timezone": { 15 | "comment": "The IANA timezone this POI is located in.", 16 | "type": "string", 17 | "example": "America/Los_Angeles" 18 | }, 19 | } 20 | ``` 21 | 22 | ## Parsing 23 | 24 | ```js 25 | var obj = JSON.parse('{ "name":"John", "age":30, "city":"New York"}'); 26 | let myJSON = JSON.stringify(obj); 27 | ``` 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /JS/collections/blob.md: -------------------------------------------------------------------------------- 1 | # Blob (Binary Large Object) 2 | 3 | a file-like object of immutable, raw data; they can be read as text or binary data, or converted into a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream)so its methods can be used for processing the data. Blobs can represent data that isn't necessarily in a JavaScript-native format. 4 | 5 | [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File)interface is based on `Blob` 6 | 7 | ```jsx 8 | const blob = new Blob(recordedChunks, { type: recordedChunks[0].type }); 9 | const blobURL = URL.createObjectURL(blob); 10 | 11 | //.... 12 |