Week 40 / 2022

Mohamed Saif published on
8 min, 1585 words

REST vs GraphQL

  • New concepts: data graph, type system and resolvers.
  • GraphQL organizes all the server’s data in a graph structure (versus by resources) defined by one interface (versus multiple endpoints). Objects are represented by nodes and relationships between these objects are described by the graph’s edges.
  • For each node an object type is defined in the GraphQL schema.
  • Each object type is backed by a resolver. The resolver is responsible for accessing the server’s data (versus CRUD operations). Since GraphQL does not implement CRUD, there is no mapping between functions and HTTP methods.
  • When the GraphQL server receives the client’s request, it will traverse the objects requested by the client always beginning at the query root.
  • A GraphQL service may also have a mutation type — this is a second entry point into the app data grap?

Career

  • A successful {user growth team} rigorously and regularly prioritizes their work.
  • why it’s important to track all our todos in a single and easily accessible list?
  • simply by writing steps down and tracking what needs to be done.
  • The first step in effective prioritization is listing every task that you might need to do.
  • It’s far easier and more efficient to compile a small number of goals that are important to complete, pick initial tasks toward those goals, and then make a pairwise comparison between what you’re currently doing and what else is on your to-do list.
  • Ask yourself on a recurring basis: Is there something else I could be doing that’s higher- leverage? If not, continue on your current path. If yes, it’s time to rethink what you’re doing.
  • To determine higher leverage tasks: focusing on what directly produces value, and focusing on the important and non-urgent.
  • what matters is how much value you’ve created. That value is measured in terms of products shipped, users acquired, business metrics moved, or sales made, rather than in terms of hours worked, tasks completed, lines of code written, or meetings attended.
  • When you get the important things right, the small things often don’t matter.
  • Don’t try to get everything done. Focus on what matters—and what matters is what produces value.
  • Quadrant 2 investments don’t have any natural deadlines and won’t get prioritized as a result of urgency. But in the long run, they provide significant value because they help us to learn and to grow both personally and professionally.
  • Quadrant 1 Tasks, all may be important and urgent, but assess whether you’re simply addressing the symptoms of the problem and not its underlying cause.
  • Oftentimes, the root cause is an underinvestment in a Quadrant 2 activity.

C: Dynamic Memory Allocation

  • malloc(size): reserves a block of memory of specified number of bytes, and returns a pointer of void type. ptr = (cast-type *) malloc(size). if error, Null pointer returned
  • calloc(n, size): continues allocation.

Commands

>> free
  • total: all existing memory
  • used: total - (allocated free + shared + buffer + cache) memory
  • free: not used by any proccess
  • shared, buffer, cache: used by the OS
  • -h: human format
  • -s: repeat printing every N seconds
  • -c: repeat printing N times, then exit. By default it uses one second intervals.
>> watch
  • watch -n 5 -d free -h
  • -n:N seconds refresh
  • -t remove header/title
  • -d highlight changes
  • use case: watch "cat /var/log/syslog | tail -n 3": update with the last 3 lines from this file.
>> pmap
  • report process memory map.
>> objdump
  • used to display various types of information stored in object files.
  • -f: get file header.
  • -p: object-specific file header content?
  • -h: section header?
  • -x: all header content?
  • -d: assembler content of the sections capable of execution? and -D: assembler content of all the sections of the file?
  • -s: complete content of all the sections of the file

OS

shared memory
  • A shared memory is an extra piece of memory that is attached to some address spaces to use. As a result, all of these processes share the same memory segment and have access to it.
  • One process must explicitly ask for an area, using a key, to be shared by other processes. This process will be called the server. All other processes, the clients, that know the shared area can access it.
  • A shared memory segment is identified by a unique integer, the shared memory ID.
  • general_schema_for_using_shared_mem
ELF, Executabl and Linkablr Format
  • binary file format for Unix and Unix-like systems on x86
  • C ------> ELF ------> process
  • ELF contains, headers, sections, segments
  • object file vs binary file?
  • c program ---preprocessor---> extendable c file ---compiler---> machine-specific code (.s) ---assembler---> object/relocatable files (.o) ---linker---> executable file (.out)
  • .c -> .c -> .s -> .o -> .out
  • The Unix file command can be used to find out information about the type of a file
  • compilation cycle. and tools for examining .o and .out file.
  1. the preprocessor (expands #'s): cpp [file.c] or gcc -E [file.c], -E Preprocess only; do not compile, assemble or link.
  2. the compiler (produces .s or .o files): translates the preprocessor's C source code output to machine-specific assembly code (an .s file). Some core compilers may directly translate to relocatable binary machine code (a .o file) instead of to assembly code. gcc -S [file.c], or from .o file by using objdump or gdb.
  3. the assembler (produces .o files from .s files) this is mostly a simple 1-1 mapping of assembly to machine instructions.
  4. the link editor (produces a.out files)

EdgeDB

  • graph-relational DB.
  • Powered by the Postgres query engine under the hood, uses PostgreSQL as its data storage and query execution engine. treats PostgreSQL as a lower-level storage engine and introduces better schema and query abstractions on top.
  • types not tables, objects not rows
  • It leverages this object-oriented model to provide a superpowered query language that solves some of SQL’s biggest usability problems.
  • execute queries over HTTP? if your language is not supported.
  • Unlike most graph databases, EdgeDB maintains a strict schema.
  • LLVM for data: it compiles its high-level schema and queries to low-level tables and optimized SQL.
  • Async: utilizes non-blocking IO to make client connections cheap and scalable, solving the connection overload problem that's increasingly prevalent in an auto-scaling, serverless deployments.
  • EdgeQL is compiled into Postgres queries that go head-to-head with the best handwritten SQL.
  • ORMs are libraries that provide a high-level way to query and manipulate data in your database.
  • EdgeDB take full advantage of the power of Postgres, whereas ORMs cannot?
  • installation, defining your schema, adding some data, and writing your first query.
  • curl https://sh.edgedb.com --proto '=https' -sSf1 | sh then source "/home/saif/.config/edgedb/env"
  • edgedb project init: new project? name of EdgeDB instance? Specify the version of EdgeDB? edgedb.toml? Downloading package...? Initializing EdgeDB instance...? Applying migrations...? create .toml and dbschema/default.esdl. spun up an EdgeDB instance called quickstart and “linked” it to the current directory. As long as you’re inside the project directory, all CLI commands will be executed against this instance. edgedb project init
  • EdgeDB schemas are defined with a dedicated schema description language called (predictably) EdgeDB SDL (or just SDL for short). It’s an elegant, declarative way to define your data model. VScode support?
  • Commonly, your entire schema will be declared in a file called default.esdl but you can split your schema across several .esdl files if you prefer. You can split up your schema into logical subunits called modules, though it’s common to define the entire schema in a single module called default.
  • unique UUID to every object inserted into the database.
  • links eliminate the need for foreign keys; you’ll see just how easy it is to write “deep” queries without JOINs.
  • run a migration to apply this schema to the database. creare migration file: edgedb migration create . apply migration: edgedb migrate. edgedb migrate is an alias of edgedb migration apply
  • cli gathers up our *.esdl files and sends them to the database. The database itself parses these files, compares them against it’s current schema, and generates a migration plan! Then the database sends this plan back to the CLI, which creates a migration file (a simple EdgeQL script consisting of DDL commands).
  • EdgeDB UI, the admin dashboard baked into every EdgeDB instance. You’ll see a card for each database running on your instance.
  • insert [type-name] {property := "[value]"};
  • select [type-name] {singular-propertey, link-property: {..}};
  • when type wrong property name, i got this error: InvalidReferenceError: ...' has no link or property 'name'
  • instance? project? two different concepts here
  • A single EdgeDB instance can contain multiple databases. execute queries against specified DB using --database/-d.
  • edgedb instance [start/stop/restart/destroy]
  • to avoid specify instance name in each command, they introduce the project concept. A project is a directory on your file system that is associated (“linked”) with an EdgeDB instance (now, all CLI commands will be applied against the linked instance by default). Linked?
  • when initializing new project, if a dbschema directory exists and contains a subdirectory called migrations, those migrations will be applied against the new instance.
  • edgedb project info, Every project maps one-to-one to a particular EdgeDB instance. From inside a project directory,
  • if you're not inside a project directory, you must provide extra connection parameters. help-connect
  • Similarly, client libraries will auto-connect to the project’s linked instance without additional configuration.
  • edgedb instance link: for remote instance, you have specifiy [host, port, database-user, database-name, instance-name (local alisa)]