<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nelson chege </title>
    <description>The latest articles on DEV Community by Nelson chege  (@nelsonchege13).</description>
    <link>https://dev.to/nelsonchege13</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F841150%2Fff5e2fb7-d969-4869-8612-03e668ab4aa0.png</url>
      <title>DEV Community: Nelson chege </title>
      <link>https://dev.to/nelsonchege13</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nelsonchege13"/>
    <language>en</language>
    <item>
      <title>I made an Instagram clone</title>
      <dc:creator>Nelson chege </dc:creator>
      <pubDate>Tue, 09 Jan 2024 09:19:04 +0000</pubDate>
      <link>https://dev.to/nelsonchege13/i-made-an-instagram-clone-1e23</link>
      <guid>https://dev.to/nelsonchege13/i-made-an-instagram-clone-1e23</guid>
      <description>&lt;p&gt;spending a lot of time scrolling on Instagram made me think about creating an Instagram clone to challenge my skills. &lt;/p&gt;

&lt;p&gt;I decided to go as much as the hot tech as possible in the JavaScript to see how they worked or if they being hyped only but had no real advantage in using them &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tools I Used:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Shadcn UI&lt;/strong&gt;: For web components.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Next-Auth&lt;/strong&gt;: Handling authentication.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Drizzle&lt;/strong&gt;: for database management and ORM.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TRPC&lt;/strong&gt;: API interactions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Uploadthing&lt;/strong&gt;: file uploads.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is the &lt;a href="https://g-stagram.vercel.app/"&gt;link&lt;/a&gt; to the site&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;some of the take away that i had:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;TRPC:&lt;/em&gt; Working with TRPC made fetching data from the back-end an enjoyable experience. The ability to define functions in the back-end and call them in the UI reduced the chances of errors, and it was fun having to enjoy the fruits of autocomplete.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Drizzle:&lt;/em&gt; As someone used to writing raw queries, Drizzle offered the flexibility of using its ORM syntax or writing raw queries .It even generated types by inferring from the created table classes,&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Development process:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Navigating through this project, I initially overlooked the importance of thorough planning, resulting in a lack of understanding of the complete scope.&lt;br&gt;
Lesson learned - scoping and planning will be pivotal in my next project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I plan to integrate Drizzle into all of my future projects and consider migrating some of my existing work to leverage its capabilities. Nextjs has made it easy for you not needing a different back-end for small to medium project .For The JavaScript/Typescript ecosystem is increasingly showcasing tools that prioritise developer experience while also ensuring efficient functionality.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Understanding HTML canvas</title>
      <dc:creator>Nelson chege </dc:creator>
      <pubDate>Wed, 03 Jan 2024 08:16:07 +0000</pubDate>
      <link>https://dev.to/nelsonchege13/understanding-html-canvas-1hnc</link>
      <guid>https://dev.to/nelsonchege13/understanding-html-canvas-1hnc</guid>
      <description>&lt;p&gt;HTML canvas is a graphic interface that can be used to create video games and animation using JavaScript and the canvas element in HTML.it is also a lightweight solution when you want to create animations without any additional frameworks and libraries.&lt;/p&gt;

&lt;h1&gt;
  
  
  How to setup a basic playground
&lt;/h1&gt;

&lt;p&gt;you only need JavaScript and an html file to getting started using Canvas.&lt;/p&gt;

&lt;p&gt;in the HTML file ,add the canvas element and a script tag to your JavaScript file &lt;/p&gt;

&lt;p&gt;inside the JavaScript file, First select the canvas element in the HTML, using any of the document methods.you can get the canvas depending on how you have initialized the canvas element in you HTML file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const canvas  = document.querySelector('canvas')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then create the main object that will be used in whatever you want to make of it. here is a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext"&gt;link&lt;/a&gt; to the different context that are available when using Canvas.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const ctx = canvas.getContext('2d')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  How to draw something on canvas
&lt;/h1&gt;

&lt;p&gt;the object created ctx contains different methods that are used to create the different things within the canvas context&lt;/p&gt;

&lt;p&gt;for drawing rectangles , you can use the .fillRect() method&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ctx.fillRect(0,0,50,150)
%%the first two argument are for the postions of the rectangle being drawn, and the other  one is for the height and with of the said rectangle  %%
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you can also use the  .fillStyle() method to add colour to it &lt;/p&gt;

&lt;h1&gt;
  
  
  How to create a basic animation
&lt;/h1&gt;

&lt;p&gt;a callback function can be created to tell the browser that you wish to perform an animation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function animate(){
 window.requestAnimationFrame(animate)
}

animate()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in this case, it will be an infinite callback function that will continue running the function.This will make the screen refresh each time the function run.&lt;br&gt;
This is helpful because in things like animation, the screen needs to change for each frame in the animation.&lt;/p&gt;
&lt;h1&gt;
  
  
  Creating an object that moves
&lt;/h1&gt;

&lt;p&gt;for a simple example of creating a small game that you can move a character around,ill be creating an object that can move side to side and jump.&lt;/p&gt;

&lt;p&gt;First setup the object and give it full height and width of the screen&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const canvas = document.querySelector('canvas')
const ctx = canvas.getCOntext('2d')

canvas.witdth = window.innerWitdth;
canvas.height = window.innerHeight;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next ,create a class that will hold the properties that we want object to contain (lets can it a player).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Player{
  constructor({position.velocity}){
    this.position = position
    this.velocity = velocity
    this.height = 150 pixels
  }
  draw(){
    canvas.fillStyle ='red'
    canvas.fillRect(this.position.x,this.position.y,50,this.height)
 }
 update(){
    this.draw();
    this.position.x += this.velocity.x
    this.position.y += this.velocity.y

  if(this.position.y + this.height + this.velocity.y &amp;gt;= canvas.height){
  this.velocity.y = 0
  }else{
    this.velocity.y += 0.2
  }
 }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now time to create a player instance  from the class created&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Player1 = new PLayer({postion:{x:0,y:0},velocity:{x:0,y:5}})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next thing is to write functions that takes in input from the keys pressed on the keyboard, and also adding helper variables&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Keys = {
    a:{ pressed:false },
    d:{ prassed:false }
    w:{ passed:false }
}

window.addEventLIstener("keyDown",(event)=&amp;gt;{
 switch (event.key){
   case "d":
     Keys.d.pressed = true;
     break;
   case "a":
     Keys.a.pressed = true;
     break;
  %%  this will handle the player jumping  %%   
   case "w":
     player1.velocity.y = -10;
     break;
 }
})

window.addEventLIstener("keyUp",()=&amp;gt;{
  case "d":
     Keys.d.pressed = false;
     break;
   case "a":
     Keys.a.pressed = false;
     break;
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;finally , create a  callback function that would be used to re render "yeah I'm used to that term from the react world ;)" and handle the animation&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function animate(){
   windows.requestAnimationFrame(animate)
   ctx.fillStyle ='black';
   ctx.fillRect(0,0 canvas.width,canvas.height);
   player1.update()

   player1.velocity.x = 0

  if (keys.a.pressed &amp;amp;&amp;amp; player.lastKeyPressed === "a") {
       player.velocity.x = -10;
  else if (keys.d.pressed &amp;amp;&amp;amp; player.lastKeyPressed === "d") {
       player.velocity.x = 10;
  }
}

animate()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  conclusion
&lt;/h1&gt;

&lt;p&gt;HTML canvas is a great way to getting started if interested in making animation using javascript. It's Lightweight from it being a native HTML element and no extra libraries or framework needed&lt;/p&gt;

</description>
    </item>
    <item>
      <title>working with Server Actions</title>
      <dc:creator>Nelson chege </dc:creator>
      <pubDate>Thu, 17 Aug 2023 13:49:23 +0000</pubDate>
      <link>https://dev.to/nelsonchege13/working-with-server-actions-hoj</link>
      <guid>https://dev.to/nelsonchege13/working-with-server-actions-hoj</guid>
      <description>&lt;p&gt;Server actions were introduced in NextJs version 13.4 in Alpha together with turbopack (Beta) and App router(stable).&lt;/p&gt;

&lt;p&gt;They have a good developer Experience when using them plus other features that are really nice to have.&lt;/p&gt;

&lt;p&gt;with server actions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;allows progressive Enhancement which allows forms to 
function correctly without javascript&lt;/li&gt;
&lt;li&gt;you can now you forms inside of server action, reducing the 
amount of javascript shipped to the client&lt;/li&gt;
&lt;li&gt;you don't need to create other endpoints todo mutations. 
(but these actions are considered as api endpoints by 
nextjs)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because at the moment,server Actions is still in Alpha, you have to add this to your next.config.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/** @type {import('next').NextConfig} */
const nextConfig = {
  experimental: {
    serverActions: true,
  },
};

module.exports = nextConfig;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now creating a simple form that calls an action&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { addTodo } from "../lib/actions";
const AddTodo = () =&amp;gt; {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;form action={addTodo}&amp;gt;
        &amp;lt;div className=""&amp;gt;
          &amp;lt;input
            type="text"
            name="todo"
            required
          /&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div&amp;gt;
          &amp;lt;button
            type="submit"
           &amp;gt;
            Submit
          &amp;lt;/button&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/form&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default AddTodo;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;server actions can be imported and saved in a separate file making them cool to work with.&lt;/p&gt;

&lt;p&gt;the &lt;strong&gt;"use server"&lt;/strong&gt; must be included on top of the file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use server";

import { randomUUID } from "crypto";
import { revalidatePath } from "next/cache";

export async function addTodo(data: FormData) {
  const todo = data.get("todo");

  await fetch("http://localhost:3500/todos", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      todo,
      userId: randomUUID,
    }),
  });

  revalidatePath("/");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;inside the Action you are able to do all the things that a normal API endpoint used to handle  such as communicating to a database&lt;/p&gt;

&lt;p&gt;the revalidatePath will update the cache with the new data add to the specified path.&lt;/p&gt;

&lt;p&gt;And thats all required to get started using server actions.&lt;/p&gt;

&lt;p&gt;An extra feature that can be included inside server action is the useTransition hook.&lt;br&gt;
This provides pending and startTransitions to play around with. you can disable the button using the pending status.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use client";

import React, { useRef, useTransition } from "react";

type AddTodoFormProps = { addTodo: (todo: string) =&amp;gt; Promise&amp;lt;void&amp;gt; };

const AddTodoForm = ({ addTodo }: AddTodoFormProps) =&amp;gt; {
  const todoRef = useRef&amp;lt;HTMLInputElement&amp;gt;(null);
  let [pending, startTransition] = useTransition();
  return (
    &amp;lt;&amp;gt;
      &amp;lt;div className=""&amp;gt;
        &amp;lt;input
          ref={todoRef}
          type="text"
          id="todo"
          name="todo"
          required
        /&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;button
          disabled={pending}
          onClick={async () =&amp;gt; {
            startTransition(async () =&amp;gt; {
              await addTodo(todoRef.current!.value);
            });
          }}
        &amp;gt;
          Submit
        &amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/&amp;gt;
  );
};

export default AddTodoForm;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;for the action, data passed to the action will only be that one variable&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use server";

import { randomUUID } from "crypto";
import { revalidatePath } from "next/cache";

export async function addTodo(data: string) {
  const todo = data;
  const payload = {
    todo,
    userId: randomUUID(),
    createdAt: new Date(new Date()).toLocaleString(),
  };

  await fetch("http://localhost:3500/todos", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify(payload),
  });

  revalidatePath("/");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;conclusion&lt;/p&gt;

&lt;p&gt;server actions is an easier way to communicate with your backend without extra endpoints and also reduce the javascript code that is passed to the client side. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>setting up next auth with the new app directory</title>
      <dc:creator>Nelson chege </dc:creator>
      <pubDate>Sat, 24 Jun 2023 16:14:24 +0000</pubDate>
      <link>https://dev.to/nelsonchege13/setting-up-next-auth-with-the-new-app-directory-318b</link>
      <guid>https://dev.to/nelsonchege13/setting-up-next-auth-with-the-new-app-directory-318b</guid>
      <description>&lt;p&gt;I was looking for ways to setup next-auth with the new app directory and found no blog that gave out the steps for actually doing it.&lt;/p&gt;

&lt;p&gt;here are the steps of setting it up.&lt;/p&gt;

&lt;p&gt;for this, i did not use the scr file structure in my next project.&lt;/p&gt;

&lt;p&gt;i install next auth &lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install next-auth&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;ii add an api route &lt;/p&gt;

&lt;p&gt;&lt;code&gt;touch app/api/auth/[...nextauth]/route.ts&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;inside of the routes add the following code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { authOptions } from "@/utils/authoptions";
import NextAuth from "next-auth/next";

const handler = NextAuth(authOptions);

export { handler as GET, handler as POST };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This handle all requests related to next-auth.&lt;br&gt;
we need to create authOptions&lt;/p&gt;

&lt;p&gt;iii create authOptions&lt;/p&gt;

&lt;p&gt;there are different providers that can be use for authentication,&lt;br&gt;
you can have a look at the next-auth docs to view how to impliment for different providers&lt;br&gt;
in this case ill simply use the credential provider&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mkdir utils&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;touch authOptions.ts&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;inside the authOptions file ,add the following&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { NextAuthOptions } from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";

export const authOptions: NextAuthOptions = {
  providers: [
    CredentialsProvider({
      name: "Credentials",
      credentials: {
        email: { label: "Username", type: "text" },
        password: { label: "Password", type: "password" },
      },
      authorize(credentials: any, req) {
        // database operations
        return {
          id: "1",
          Email: credentials.email,
        };
      },
    }),
  ],
};

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;iv adding required environment variables&lt;/p&gt;

&lt;p&gt;next auth needs the following environment variable&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# this is for jwt encording
NEXTAUTH_SECRET='supersecretkey'

#used to specify the url to the site
NEXTAUTH_URL='http://localhost:3000'

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;shifting to handling sessions in the client side&lt;/p&gt;

&lt;p&gt;v creating a session provider &lt;/p&gt;

&lt;p&gt;&lt;code&gt;mkdir providers&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;touch SessionProvider.tsx&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;then add the following code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use client";

import React from "react";
import { SessionProvider } from "next-auth/react";

type sessionProps = {
  children: React.ReactNode;
};
function NextAuthSessionProvider({ children }: sessionProps) {
  return &amp;lt;SessionProvider&amp;gt;{children}&amp;lt;/SessionProvider&amp;gt;;
}

export default NextAuthSessionProvider;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;vi adding the provider to layout.tsx&lt;/p&gt;

&lt;p&gt;include it to the rootLayout function&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    &amp;lt;html lang="en"&amp;gt;
      &amp;lt;body className={inter.className}&amp;gt;
        &amp;lt;NextAuthSessionProvider&amp;gt;{children}&amp;lt;/NextAuthSessionProvider&amp;gt;
      &amp;lt;/body&amp;gt;
    &amp;lt;/html&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and thats it , you can use the usesession hook to check if someone is logged in or not.&lt;/p&gt;

&lt;p&gt;here is a link to the full code &lt;a href="https://github.com/nelsonchege/next-auth-with-app-directory"&gt;https://github.com/nelsonchege/next-auth-with-app-directory&lt;/a&gt;&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>react</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Demystifying Hash Tables: Understanding the Inner Workings of This Key Data Structure</title>
      <dc:creator>Nelson chege </dc:creator>
      <pubDate>Sat, 22 Apr 2023 12:14:32 +0000</pubDate>
      <link>https://dev.to/nelsonchege13/demystifying-hash-tables-understanding-the-inner-workings-of-this-key-data-structure-cmb</link>
      <guid>https://dev.to/nelsonchege13/demystifying-hash-tables-understanding-the-inner-workings-of-this-key-data-structure-cmb</guid>
      <description>&lt;p&gt;A hash map, also known as a hash table, is a data structure that enables fast and efficient lookup, insertion, and deletion of key-value pairs.&lt;/p&gt;

&lt;p&gt;Because of their reliability hash tables are used in database indexing, caching, programming compilation, and many more places&lt;/p&gt;

&lt;p&gt;Think of a hash table as living in a gated community where each home has an address(key) and the home as the value, if you want to get to a particular home you go straight to the address, getting the value is independent of the size of the hash table&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;how is data stored into the hash table?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The key is transformed into an index that points to a memory address, this is done by a hashing function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---X_D-0EI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hnh2icnc7l9fu8417e3m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---X_D-0EI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hnh2icnc7l9fu8417e3m.png" alt="insertion in hash map" width="637" height="187"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are different hashing functions that can be used.&lt;/p&gt;

&lt;p&gt;The most straightforward hashing function works by (if the key is a string) converting each character into an ASCII value and then summing it. once you get the sum you divide the number by the size of the hash table getting the remainder.&lt;/p&gt;

&lt;p&gt;The remainder is then used as the index for that value&lt;/p&gt;

&lt;p&gt;Another hashing function is the folding method, in this function, the key is divided into equal parts then added together, then divide by the size of the hash table getting the remainder and index&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;one issue usually comes with hash functions : collusions&lt;/strong&gt; &lt;br&gt;
This occurs when a hashing function returns an index that has already been assigned a value.&lt;/p&gt;

&lt;p&gt;there are two ways that are used to address this occurring issues.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;open addressing&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;chaining/closed addressing&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;open addressing&lt;/strong&gt;&lt;br&gt;
when the hashing function returns an index that is already in use it moves to the next position, and checks if is empty. if empty it takes that space else it continues moving to the next position till it finds an empty space&lt;/p&gt;

&lt;p&gt;This is referred to as &lt;em&gt;linear probing&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--61oRuF3d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eob5742z8dfw15u8pw06.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--61oRuF3d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eob5742z8dfw15u8pw06.png" alt="Image showing linear probing" width="542" height="512"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This introduces another issue where values are not equally distributed in the hash table.&lt;/p&gt;

&lt;p&gt;New methods for finding an empty space have been created to try and solve this second issues which they include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;plus 3 rehash&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;quadratic probing&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;double hashing&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;chaining/closed addressing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This deals with collusion by making the index a pointer to a linked list, if an index is duplicated it's just added to the linked list.&lt;/p&gt;

&lt;p&gt;Popular programming languages such as Python, JavaScript, c++, and Ruby use chaining in their hash functions&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NT9g-xtn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1y9wsnwpnkir87t92mca.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NT9g-xtn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1y9wsnwpnkir87t92mca.jpg" alt="chained linked lists" width="602" height="372"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Even though generally hash tables are fast, the performance of a hash table is highly dependent on the quality of the hash function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;what are some of the factors to consider when creating the perfect hash function ?&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;minimize collusions&lt;/li&gt;
&lt;li&gt;uniform distribution of hash values&lt;/li&gt;
&lt;li&gt;easy to calculate&lt;/li&gt;
&lt;li&gt;resolve any collusion&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you would like to know more about optimizing the hash function &lt;a href="https://www.youtube.com/watch?v=DMQ_HcNSOAI&amp;amp;t=759s&amp;amp;ab_channel=strager"&gt;here&lt;/a&gt; is a video that I found useful, even though at points in the video I was just hearing him speaking in tongues :)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Hash tables are an efficient data structure that allows for fast data retrieval and insertion by using a hash function to map keys to indices in an array. They have a constant average time complexity of O(1) for insertion, deletion, and retrieval operations, making them ideal for storing and accessing large amounts of data quickly. Hash tables can be implemented in a variety of programming languages and have numerous applications in areas such as databases, search engines, and cryptography. However, the efficiency of a hash table may be affected by collisions, which can be mitigated through various collision resolution techniques. Overall, hash tables are a valuable tool for optimizing data access in software development&lt;/p&gt;

</description>
      <category>dsa</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Node-based Data Structure</title>
      <dc:creator>Nelson chege </dc:creator>
      <pubDate>Thu, 16 Mar 2023 22:58:39 +0000</pubDate>
      <link>https://dev.to/nelsonchege13/node-based-data-structure-313f</link>
      <guid>https://dev.to/nelsonchege13/node-based-data-structure-313f</guid>
      <description>&lt;p&gt;while searching for solutions on Google, I came across a new term, &lt;em&gt;"node-based data structure"&lt;/em&gt; ,&lt;br&gt;
this term was new to me and I decided to dig in a little bit deeper.&lt;br&gt;
These are some of the concepts that I discovered while researching node-based data structures.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Node-based data structures&lt;/strong&gt; are data structures that organizes and stores data as interconnected nodes. Each node contains data and one or more pointers that point to other nodes. &lt;/p&gt;

&lt;p&gt;This structure allows for efficient traversal and manipulation of the data&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;what is a node ?&lt;/strong&gt;&lt;br&gt;
I explain this using an analogy;&lt;br&gt;
think of how the TV show &lt;strong&gt;The Amazing Show&lt;/strong&gt; worked, contestants reached a given destination and got instructions on how to reach the next destination. Now replace the destination as the data in a node and the instructions as the pointer to the next node &lt;/p&gt;

&lt;p&gt;Simply node-base data structures are a collection of linked nodes that point to each other:&lt;/p&gt;

&lt;p&gt;the two main node-base data structures are:&lt;br&gt;
&lt;strong&gt;Linked List:&lt;/strong&gt; its a data structure that can have a node that has a single pointer pointing to a next node &lt;em&gt;&lt;strong&gt;singular linked list&lt;/strong&gt;&lt;/em&gt; or two pointers, one pointing the previous and one pointing to the next &lt;em&gt;&lt;strong&gt;doubly linked list&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tree:&lt;/strong&gt; for trees you can have a multiple pointers pointing to the next nodes. Trees don't have pointers for previous nodes, this create a parent-child relationship between the nodes&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementation of A Tree&lt;/strong&gt;&lt;br&gt;
we can represent a math equation into a tree&lt;br&gt;
Using BODMAS we can create  tree for this equation&lt;/p&gt;

&lt;p&gt;3 * (y + x) as     &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     *
    / \
   /   \
  3  (y + x)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;and  3 * y + X as&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     +
    / \
   /   \
(3 * y)  x
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Below is the code representation of the Tree&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
# represent 3 * (y + x) and  3 * y + X as trees 

class exp():
    pass

class Times(exp):
    def __init__(self,l,r):
        self.r = r
        self.l = l

    def __str__(self):
        return str(self.r) +" * "+ str(self.l)

    def eval(self,env):
        return self.r.eval(env) * self.l.eval(env)

class Plus(exp):
    def __init__(self,l,r):
        self.r = r
        self.l = l

    def __str__(self,l,r):
        return str(self.r) + " + " + str(self.l) 

    def eval(self,env):
        return self.r.eval(env) + self.l.eval(env)

class Const(exp):
    def __init__(self,val):
        self.val = val

    def __str__(self):
        return str(self.val)

    def eval(self):
        return self.val

class Variable(exp):
    def __init__(self,name):
        self.name = name

    def eval(self,env):
        return env[self.name]



# 3 * (y + x)
e1 = Times(Const(3),Plus(Variable('y'),Variable('x')))

# 3 * y + x
e2 = Plus(Times(Const(3),(Variable('y'))),Variable('x'))

# to get the calculations

env = {"x":2,"y":4}

e1.eval(env)
e2.eval(env)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>dsa</category>
      <category>algorithms</category>
      <category>python</category>
    </item>
    <item>
      <title>CSS tips for Responsive Web design</title>
      <dc:creator>Nelson chege </dc:creator>
      <pubDate>Sun, 12 Mar 2023 11:24:28 +0000</pubDate>
      <link>https://dev.to/nelsonchege13/css-tips-for-responsive-web-design-i94</link>
      <guid>https://dev.to/nelsonchege13/css-tips-for-responsive-web-design-i94</guid>
      <description>&lt;p&gt;Crafting a responsive website can be a daunting undertaking that demands a deliberate approach to guarantee a visually appealing layout on all devices. &lt;/p&gt;

&lt;p&gt;The growing array of devices and screen sizes presents challenges in creating a straightforward and efficient design. &lt;/p&gt;

&lt;p&gt;Here are some of some CSS tricks and properties to creating a more responsive designs&lt;/p&gt;

&lt;h2&gt;
  
  
  1. aspect ratio
&lt;/h2&gt;

&lt;p&gt;this css property lets you have consistent ratios of width and height for a html element in relation to its parent element or its-self&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container{
   aspect-ratio: 16/9;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The relationship for the element having the css class container will be the width of 16 by the height of 9 &lt;/p&gt;

&lt;p&gt;you can also set the width or height for which the aspect ratio will get its measurement from instead of getting from the parent element&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container{
   aspect-ratio: 16/9;
   width: 100px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Use rem or em instead of px
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Rem&lt;/em&gt; and &lt;em&gt;em&lt;/em&gt; are relative units that adjust their size based on the font size of their parent element. This means that if the font size of the parent element changes, all child elements that use &lt;em&gt;rem&lt;/em&gt; or &lt;em&gt;em&lt;/em&gt; will adjust their size accordingly. &lt;/p&gt;

&lt;p&gt;This makes it easier to create responsive designs that can adapt to different screen sizes and devices.&lt;/p&gt;

&lt;p&gt;On the other hand, &lt;em&gt;px&lt;/em&gt; is an absolute unit that sets the font size to a fixed pixel size. This can create issues with scalability, especially when designing for different devices and screen sizes. &lt;/p&gt;

&lt;p&gt;Additionally, using &lt;em&gt;px&lt;/em&gt; can make it difficult to implement accessibility features like zooming, as the font size will not adjust when the user zooms in or out.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. min() , max() and clamp()
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;min()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;starting of with min, it takes at-least two argument which are the desired width and the maximum width&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container{
   width: min(100px,70%);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the function only picks the smallest value so it doesn't care much on the placement of the arguments&lt;/p&gt;

&lt;p&gt;the 70% is the desired width and the element wont have a width greater than 100px&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# same as using min()
.container{
   width: 70%;
   max-width: 100px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;max()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;max() works opposite to how min() works&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container{
   width: max(100px,70%);
}

# same as using max()
.container{
   width: 70%;
   min-width: 100px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;clamp()&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;clamp() takes three arguments: a minimum value, a preferred value, and a maximum value. The preferred value is the size you want to use, and the other two values set the range in which the preferred value can adjust&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container{
  font-size: clamp(16px, 3vw, 24px);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Text-overflow
&lt;/h2&gt;

&lt;p&gt;You know those moments that you are trying to fit content in a div but is making one div bigger than the other divs in maybe in you flex row, well this solves that.&lt;/p&gt;

&lt;p&gt;it adds three dots to content that is longer than the space in the parent div has&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. Media-query
&lt;/h2&gt;

&lt;p&gt;without forgetting the big boy in responsive design,Media-query allows you adjust to different device properties, such as screen size or orientation.&lt;/p&gt;

&lt;p&gt;here is a basic view on how they work&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@media only screen and (max-width: 768px) {
  .menu {
    display: none;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;for the above example,the .menu element will be hidden on screens with a width of 768 pixels or less, allowing for a better user experience on smaller screens.&lt;/p&gt;

&lt;p&gt;for a more deeper understanding of Media-query &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries"&gt;heres&lt;/a&gt; the link to the documentation&lt;/p&gt;

&lt;p&gt;And those are some of many CSS properties that you can use for a more responsive web design&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Zustand, simplified redux</title>
      <dc:creator>Nelson chege </dc:creator>
      <pubDate>Thu, 23 Feb 2023 23:37:11 +0000</pubDate>
      <link>https://dev.to/nelsonchege13/zustand-simplified-redux-41b8</link>
      <guid>https://dev.to/nelsonchege13/zustand-simplified-redux-41b8</guid>
      <description>&lt;p&gt;Having Used Redux toolkit, it really does the job well having no issues with it. Setting Up the store makes using it in the rest of your project quite Easy.&lt;/p&gt;

&lt;p&gt;But one thing about creating the Redux stores is that it's really verbose and you have to write a lot more boilerplate code.&lt;/p&gt;

&lt;p&gt;This is the part where Zustand comes in, Doing what redux is doing but with really less code. ill be creating a simple project to show you how easy it is to use Zustand&lt;/p&gt;

&lt;p&gt;first, create a folder in the root directory that will contain the costume Hook for our state&lt;/p&gt;

&lt;p&gt;&lt;code&gt;touch store/useItemsStore.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;in that file, the hook is created as follows&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {create} from 'zustand';

const useMyStore = create((set) =&amp;gt; ({
  items: [], // initial state
  addItem: (newItem) =&amp;gt; set((state) =&amp;gt; ({ items: [...state.items, newItem] })),
  deleteItem: (index) =&amp;gt;
    set((state) =&amp;gt; ({ items: state.items.filter((_, i) =&amp;gt; i !== index) })),
}));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this will create an empty list and two functions for adding and deleting items&lt;/p&gt;

&lt;p&gt;when you want to use the above state and functions in you components you'll do the following&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useMyStore } from './store/useItemsStore';

function MyComponent() {
  const addItem = useMyStore((state) =&amp;gt; state.addItem);

  const handleClick = () =&amp;gt; {
    addItem('New Item');
  };

  return (
    &amp;lt;&amp;gt;
      &amp;lt;button onClick={handleClick}&amp;gt;Add Item&amp;lt;/button&amp;gt;
      {/* Render the list of items here */}
     &amp;lt;ul&amp;gt;
        {items.map((item, index) =&amp;gt; (
          &amp;lt;li key={index}&amp;gt;
            {item} &amp;lt;button onClick={() =&amp;gt; handleDelete(index)}&amp;gt;Delete&amp;lt;/button&amp;gt;
          &amp;lt;/li&amp;gt;
        ))}
      &amp;lt;/ul&amp;gt;
    &amp;lt;/&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's it. not a lot of code and still functions similarly to redux. it has been fun using it for small side projects so far&lt;/p&gt;

&lt;p&gt;here is a simple Todo App that i use Zustand to manage my state: &lt;a href="https://react-zustand.netlify.app/" rel="noopener noreferrer"&gt;https://react-zustand.netlify.app/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>c</category>
      <category>programming</category>
      <category>softwareengineering</category>
      <category>performance</category>
    </item>
    <item>
      <title>Getting started with Nextjs</title>
      <dc:creator>Nelson chege </dc:creator>
      <pubDate>Tue, 14 Feb 2023 02:17:08 +0000</pubDate>
      <link>https://dev.to/nelsonchege13/getting-started-with-nextjs-1k67</link>
      <guid>https://dev.to/nelsonchege13/getting-started-with-nextjs-1k67</guid>
      <description>&lt;p&gt;Next.js is a relatively new JavaScript framework for building applications with React.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Nextjs?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Nextjs generates static html pages which reduce the initial loading of reacts application and its super friendly for SEO purposes&lt;/p&gt;

&lt;p&gt;In this blog post, we'll take a closer look at how Next.js works and how you can get started building your own web applications with this powerful framework.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How Next.js Works&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next.js is built on top of React and uses the React component model to define your application's pages and components. It handles all the complicated tasks of rendering your pages on the server, so you can focus on writing the code that defines your application's functionality. &lt;/p&gt;

&lt;p&gt;Here's a high-level overview of how Next.js works:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The Client Makes a Request: When a user visits your Next.js application, the client sends a request to the server for the requested page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The Server Renders the Page: Next.js will handle the request on the server and generate the HTML for the requested page. This HTML will include the content of your React components and any data that needs to be passed from the server to the client.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The Server Sends the HTML to the Client: Once the HTML has been generated, Next.js will send it to the client, which will display the page in the user's browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The Client Renders the Page with React: The client will then use React to render the page and handle any dynamic interactions. This makes it possible to build rich, interactive web applications with Next.js.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Nextjs offers four types of rendering:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Server-Side Rendering (SSR):&lt;/strong&gt; This type of rendering generates the HTML for your pages on the server and then sends it to the client. SSR provides a better user experience as pages load faster, and it's ideal for dynamic web applications that require server-side processing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Static Site Generation (SSG):&lt;/strong&gt; This type of rendering generates a static version of your website that can be served without the need for a server. SSG is a great solution for websites that don't require any dynamic content or user interactions &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Client-Side Rendering (CSR):&lt;/strong&gt; This type of rendering generates the HTML for your pages on the client side using JavaScript. CSR is ideal for applications that require fast and smooth user interactions, but it can have negative effects on the initial loading time of the page.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Incremental Static Regeneration (ISR):&lt;/strong&gt;  ISR is a combination of Static Site Generation (SSG) and Server-Side Rendering (SSR), and it provides the benefits of both. With ISR, you can have pages that are pre-rendered as static HTML at build time, and then updated incrementally on the server as data changes. This provides the fast loading times of SSG, with the ability to handle dynamic data updates, just like in SSR.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In conclusion&lt;/strong&gt;, Next.js is a powerful and versatile framework for building modern web applications. With its focus on server-side rendering, it provides a fast and efficient solution for building websites and web applications with dynamic content.&lt;/p&gt;

</description>
      <category>vercel</category>
      <category>render</category>
      <category>authentication</category>
      <category>productivity</category>
    </item>
    <item>
      <title>DevFest Nairobi 2022</title>
      <dc:creator>Nelson chege </dc:creator>
      <pubDate>Mon, 07 Nov 2022 06:18:02 +0000</pubDate>
      <link>https://dev.to/nelsonchege13/devfest-nairobi-2022-2f3b</link>
      <guid>https://dev.to/nelsonchege13/devfest-nairobi-2022-2f3b</guid>
      <description>&lt;p&gt;The Annual Google devfest Nairobi happened over the weekend on Saturday and what an amazing event it was.This was my first devfest i have attended.met old friends,new like-minded people and also learnt new things in the process.&lt;/p&gt;

&lt;p&gt;Here are some of the notes that i was able to take during the different session:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Starting a Startup&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;some of the steps that one needs to take while starting a startup&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;create a team- create a team that understand and believe in your idea&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;2.MVP - Having a minimum viable product&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;make decisions on tech and infrastructure that will be used to create your product&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;4.acquire customers - you should also consider getting customers and not only focusing on developing your product&lt;/p&gt;

&lt;p&gt;5.scaling up- this is the next step after your product has started getting traction.Also joining an accelerator program helps Google offering one&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Everything APIs&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;types of API endpoints&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Soap&lt;/li&gt;
&lt;li&gt;XML&lt;/li&gt;
&lt;li&gt;REST&lt;/li&gt;
&lt;li&gt;Grpc&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;tips on naming conventions&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;use nouns and not verbs&lt;/li&gt;
&lt;li&gt;consistency is key in naming your endpoints&lt;/li&gt;
&lt;li&gt;use lowercase&lt;/li&gt;
&lt;li&gt;don't use method name in URL&lt;/li&gt;
&lt;li&gt;the name should try to be self explanatory&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;some of the ways to secure endpoints&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Basic auth (username &amp;amp; password)&lt;/li&gt;
&lt;li&gt;JWT&lt;/li&gt;
&lt;li&gt;OpenID and Oauth&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;what is throttling ?&lt;/em&gt; limiting the number of request made by a user in a certain period&lt;/p&gt;

&lt;p&gt;&lt;em&gt;tools used for creating, testing and documenting API endpoints&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Swagger UI&lt;/li&gt;
&lt;li&gt;Swagger Hub&lt;/li&gt;
&lt;li&gt;Postman&lt;/li&gt;
&lt;li&gt;Redocly&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;types of test that can be done on API endpoints&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Unit test&lt;/li&gt;
&lt;li&gt;Integration test&lt;/li&gt;
&lt;li&gt;Load / performance test&lt;/li&gt;
&lt;li&gt;security test&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;tools used to test API endpoints&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;JMeter&lt;/li&gt;
&lt;li&gt;Soup UI&lt;/li&gt;
&lt;li&gt;CuCumber&lt;/li&gt;
&lt;li&gt;Rest-Assured (the person how named this needs a pay raise)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Serverless Backend infrastructure with AWS Lambdas&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AWS lambda more like Google cloud Function&lt;/li&gt;
&lt;li&gt;Api Gateway replaces Web server hence acts as point of contact  when the the client sends a request&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;AWS Lambdas has:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Handlers&lt;/li&gt;
&lt;li&gt;Events&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The events was really enjoy-full and looking forward to attending to more of such events&lt;/p&gt;

</description>
      <category>devfestnairobi</category>
      <category>codetoinfinityandbeyond</category>
      <category>devfest2022</category>
    </item>
    <item>
      <title>creating a simple database using SQL</title>
      <dc:creator>Nelson chege </dc:creator>
      <pubDate>Sat, 29 Oct 2022 23:26:58 +0000</pubDate>
      <link>https://dev.to/nelsonchege13/creating-a-simple-database-using-sql-j9m</link>
      <guid>https://dev.to/nelsonchege13/creating-a-simple-database-using-sql-j9m</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6KLK5a7o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dti9rwvxrz9w9plxwuvg.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6KLK5a7o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dti9rwvxrz9w9plxwuvg.jpg" alt="Image description" width="745" height="400"&gt;&lt;/a&gt;assuming you have some basic understanding of database and SQL, the logical next step is to interact with SQL and creating databases and have a feel of writing queries.If you what a quick reminder of theory behind SQL, &lt;a href="https://dev.to/nelsonchege13/sql-101-447b"&gt;here&lt;/a&gt; is a blog to help you on that.&lt;/p&gt;

&lt;p&gt;On this blog, i will be taking you through creating a simple database for a coffee shop.&lt;/p&gt;

&lt;p&gt;Firstly we will define the schema for the database tables which is simply the blueprint of how the database will look like.&lt;/p&gt;

&lt;p&gt;The coffee shop database will have three tables:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Coffee Menu&lt;/li&gt;
&lt;li&gt;Employee table&lt;/li&gt;
&lt;li&gt;Orders table&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;columns for Coffee Menu table include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;id&lt;/li&gt;
&lt;li&gt;Coffee name&lt;/li&gt;
&lt;li&gt;price&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;columns for Employee table include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;id&lt;/li&gt;
&lt;li&gt;employees name&lt;/li&gt;
&lt;li&gt;role&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;columns for Orders table include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;id&lt;/li&gt;
&lt;li&gt;coffee ordered (foreign key from coffee menu table)&lt;/li&gt;
&lt;li&gt;served by (foreign key from Employees table)&lt;/li&gt;
&lt;li&gt;order time&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;with this we have a basic look at how the database looks like and now comes the best but running some SQL. i'll be using PostgreSQL but the commands will still work for any RDBMS.&lt;br&gt;
the command for creating a database is:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CREATE DATABASE &amp;lt;db_name&amp;gt;;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;note that any SQL query written must end with a semi colon.In this case i will run the below command to create the table.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CREATE DATABASE coffee_shop;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;next step is witting queries to create the different tables .The SQL format for creating a table is:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CREATE TABLE table_name (&lt;br&gt;
 column_name datatype,&lt;br&gt;
 column_name datatype,&lt;br&gt;
 ….&lt;br&gt;
);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;There are different datatypes that can be stored in a database column.Read more on the different datatypes &lt;a href="https://www.w3schools.com/sql/sql_datatypes.asp"&gt;Here&lt;/a&gt;. For our tables i will run the following SQL queries:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CREATE TABLE coffee_menu (&lt;br&gt;
 id INTEGER PRIMARY KEY,&lt;br&gt;
 coffee_name VARCHAR(255),&lt;br&gt;
 price FLOAT&lt;br&gt;
);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CREATE TABLE Employees(&lt;br&gt;
 id INTEGER PRIMARY KEY,&lt;br&gt;
employees_name VARCHAR(255),&lt;br&gt;
 role VARCHAR(255)&lt;br&gt;
);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CREATE TABLE Orders (&lt;br&gt;
 id INTEGER PRIMARY KEY,&lt;br&gt;
 coffee_ordered INT,&lt;br&gt;
 served_by INT,&lt;br&gt;
 order_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,&lt;br&gt;
 FOREIGN KEY (coffee_ordered) REFERENCES coffee_menu(id),&lt;br&gt;
 FOREIGN KEY (served_by) REFERENCES Persons(id)&lt;br&gt;
);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;That is it, that's all the queries needed to create our database.this will create all the tables and required columns for each table.&lt;/p&gt;

</description>
      <category>sql</category>
      <category>postgres</category>
      <category>database</category>
      <category>webdev</category>
    </item>
    <item>
      <title>SQL 101</title>
      <dc:creator>Nelson chege </dc:creator>
      <pubDate>Sun, 23 Oct 2022 01:40:56 +0000</pubDate>
      <link>https://dev.to/nelsonchege13/sql-101-447b</link>
      <guid>https://dev.to/nelsonchege13/sql-101-447b</guid>
      <description>&lt;p&gt;hi ,welcome to my first technical blog in hopefully a series of more to come. I will be discussing about different topics around technology.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;lets talk about SQL.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;what is SQL?&lt;/strong&gt;&lt;br&gt;
the definition of SQL is structured query language.&lt;br&gt;
SQL acts to other similar languages such as JavaScript , python and C++ only that its giving command to the database.&lt;/p&gt;

&lt;p&gt;The four most popular SQL commands forms the acronym&lt;br&gt;
CRUD :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;create&lt;/li&gt;
&lt;li&gt;read&lt;/li&gt;
&lt;li&gt;update&lt;/li&gt;
&lt;li&gt;delete&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;A database&lt;/strong&gt; is a collection of organized tables that act similar to excel spread sheet. yeah database are excel spread sheet on some serious steroids.&lt;/p&gt;

&lt;p&gt;These database are managed by Database management system that ensure everything is working properly with the database. Some of the available database management system (DBMS) include: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PostgreSQL&lt;/li&gt;
&lt;li&gt;Microsoft sqlserver&lt;/li&gt;
&lt;li&gt;MySQL&lt;/li&gt;
&lt;li&gt;oracle.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;there are two types of database: &lt;strong&gt;relational database&lt;/strong&gt; and &lt;br&gt;
&lt;strong&gt;non-relational database&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;relational database consist of tables that have relationship between them. Example is when one table has a data that reference data from another table&lt;/p&gt;

&lt;p&gt;before forgetting schemas ,a schema is the representation of any kind of structure we are defining around the data that will be inserted into a table&lt;/p&gt;

&lt;p&gt;when creating relationship between table you must consider &lt;strong&gt;normalization&lt;/strong&gt;, what is that you ask? this is the structuring of data in the lowest normal that ensure that data is not duplicated across different tables and also more redundancy of data &lt;/p&gt;

</description>
      <category>sql</category>
      <category>database</category>
      <category>computerscience</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
