<?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: George Pamfilis</title>
    <description>The latest articles on DEV Community by George Pamfilis (@gpamfilis).</description>
    <link>https://dev.to/gpamfilis</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%2F783159%2F7f5f0c49-1c8c-44b0-95d7-3c0878c07ef2.jpg</url>
      <title>DEV Community: George Pamfilis</title>
      <link>https://dev.to/gpamfilis</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gpamfilis"/>
    <language>en</language>
    <item>
      <title>Handle back-press NextJS navigate to route other than previous - snippet</title>
      <dc:creator>George Pamfilis</dc:creator>
      <pubDate>Wed, 20 Mar 2024 14:30:46 +0000</pubDate>
      <link>https://dev.to/gpamfilis/handle-back-press-nextjs-navigate-to-route-other-than-previous-snippet-12ao</link>
      <guid>https://dev.to/gpamfilis/handle-back-press-nextjs-navigate-to-route-other-than-previous-snippet-12ao</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use client";
import { Box, styled } from "@mui/material";
import ThankYouRequest from "@/_components/thankyourequest";
import { useRouter } from "next/navigation";
import { useEffect } from "react";

const FOOTER_HEIGHT = 60; // Constant for the footer height
const HEADER_HEIGHT = 80; // Adjust this value to control the header height

const SectionContainer = styled(Box)({
  position: "relative",
  height: `calc(100vh - ${HEADER_HEIGHT}px - ${FOOTER_HEIGHT}px)`,
  display: "flex",
  justifyContent: "center",
  alignItems: "center",
  overflow: "hidden",
});

const useBackButtonDetector = (onBack) =&amp;gt; {
  useEffect(() =&amp;gt; {
    const handleBackButton = (event) =&amp;gt; {
      event.preventDefault();
      onBack(); // Callback function when back button is detected
    };

    window.history.pushState(null, null, window.location.pathname);
    window.addEventListener("popstate", handleBackButton);

    return () =&amp;gt; window.removeEventListener("popstate", handleBackButton);
  }, [onBack]);
};

export default function ThankYouPage({
  params,
}: {
  params: { businessName: string; requestID: string };
}) {
  const router = useRouter();

  const handleBack = () =&amp;gt; {
    console.log("Back button pressed");
    router.push(`/client/${params.businessName}/book`); // Redirect to the business page
    // Your custom logic here
  };

  useBackButtonDetector(handleBack);

  return (
    &amp;lt;&amp;gt;
      &amp;lt;SectionContainer&amp;gt;
        &amp;lt;ThankYouRequest booking_request_id={params.requestID} /&amp;gt;
      &amp;lt;/SectionContainer&amp;gt;
    &amp;lt;/&amp;gt;
  );
}

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

&lt;/div&gt;



</description>
      <category>nextjs</category>
      <category>router</category>
      <category>react</category>
    </item>
    <item>
      <title>Reset IDs postgresql database - snippet</title>
      <dc:creator>George Pamfilis</dc:creator>
      <pubDate>Wed, 06 Mar 2024 20:09:53 +0000</pubDate>
      <link>https://dev.to/gpamfilis/reset-ids-postgresql-database-snippet-188i</link>
      <guid>https://dev.to/gpamfilis/reset-ids-postgresql-database-snippet-188i</guid>
      <description>&lt;p&gt;I created a copy of a database so i can mutate the data and try things out. I was getting an error on insert.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sqlalchemy.exc.IntegrityError: (raised as a result of Query-invoked autoflush; consider using a session.no_autoflush block if this flush is occurring prematurely)
(psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "customers_pkey"
DETAIL: Key (id)=(14) already exists.

[SQL: INSERT INTO customers (user_id, first_name, last_name, email, phone_number) VALUES (%(user_id)s, %(first_name)s, %(last_name)s, %(email)s, %(phone_number)s) RETURNING customers.id]
[parameters: {'user_id': 1, 'first_name': 'myname', 'last_name': '', 'email': 'myemail', 'phone_number': ''}]
(Background on this error at: https://sqlalche.me/e/14/gkpj)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is a snippet that helped me out.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DO $$
DECLARE
    l_table RECORD;
    column_exists BOOLEAN;
BEGIN
    FOR l_table IN SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name != 'alembic_version'
    LOOP
        -- Check if 'id' column exists in the table
        SELECT EXISTS (
            SELECT FROM information_schema.columns 
            WHERE table_schema = 'public' 
            AND table_name = l_table.table_name 
            AND column_name = 'id'
        ) INTO column_exists;

        -- Log the table name and whether the 'id' column exists
        RAISE NOTICE 'Processing table: %, ID column exists: %', l_table.table_name, column_exists;

        -- If 'id' column exists, set the sequence value and log the action
        IF column_exists THEN
            EXECUTE FORMAT('SELECT setval(pg_catalog.quote_ident(''%s_id_seq''), COALESCE(MAX(id), 1)) FROM %I', l_table.table_name, l_table.table_name);
            RAISE NOTICE 'Sequence set for table: %', l_table.table_name;
        ELSE
            RAISE NOTICE 'No ID column for table: %', l_table.table_name;
        END IF;
    END LOOP;
END;
$$;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>postgres</category>
      <category>python</category>
      <category>database</category>
      <category>sql</category>
    </item>
    <item>
      <title>Trigger Expo Build GitLab CI - Snippet</title>
      <dc:creator>George Pamfilis</dc:creator>
      <pubDate>Thu, 29 Feb 2024 15:39:56 +0000</pubDate>
      <link>https://dev.to/gpamfilis/trigger-expo-build-gitlab-ci-snippet-5673</link>
      <guid>https://dev.to/gpamfilis/trigger-expo-build-gitlab-ci-snippet-5673</guid>
      <description>&lt;p&gt;Here is a snippet I use to trigger my apps to build. I have them set to manual because it costs money with Expo.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.gitlab-ci.yml&lt;/code&gt; snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;eas_build_internal_android_developv2:
  stage: build-mobile
  image: node:16.17.0

  script:
    - npm install -g expo-cli
    - npm install -g eas-cli
    - cd mobileapp
    - npm i
    - EXPO_TOKEN=$EXPO_EAS_TOKEN eas build -p android --profile develop --no-wait

  only:
    refs:
      - develop
    changes:
      - mobileapp/**/* 
  when: manual

eas_build_internal_android_productionv2:
  stage: build-mobile
  image: node:16.17.0

  script:
    - npm install -g expo-cli
    - npm install -g eas-cli
    - cd mobileapp
    - npm i
    - EXPO_TOKEN=$EXPO_EAS_TOKEN eas build -p android --profile production --no-wait
  only:
    refs:
      - main
    changes:
      - mobileapp/**/* 
  when: manual

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

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;eas.json&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "cli": {
    "version": "&amp;gt;= 2.2.1"
  },
  "build": {
    "development": {
      "developmentClient": true,
      "distribution": "internal"
    },
    "preview": {
      "env": {
        "EXPO_PUBLIC_BACKEND_DOMAIN": "https://something.ngrok-free.app"
      },
      "channel": "local",
      "distribution": "internal",
      "android": {
        "buildType": "apk"
      }
    },
    "develop": {
      "channel": "develop",
      "env": {
        "EXPO_PUBLIC_BACKEND_DOMAIN": "https://apidev.something.com",
        "EXPO_PUBLIC_GROWTHBOOK_CLIENT_KEY": ""
      },
      "distribution": "internal",
      "android": {
        "buildType": "apk"
      }
    },
    "production": {
      "env": {
        "EXPO_PUBLIC_BACKEND_DOMAIN": "https://api.something.com",
        "EXPO_PUBLIC_GROWTHBOOK_CLIENT_KEY": ""
      },
      "channel": "main",
      "distribution": "internal",
      "android": {
        "buildType": "apk"
      }
    }
  },
  "submit": {
    "production": {}
  }
}

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Might be also helpfull
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;app.json&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
{
  "expo": {
    "name": "mobileapp",
    "slug": "mobileapp",
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/something.png",
    "userInterfaceStyle": "light",
    "splash": {
      "image": "./assets/splash_v2.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "assetBundlePatterns": ["**/*"],
    "ios": {
      "supportsTablet": true
    },
    "android": {
      "adaptiveIcon": {
        "foregroundImage": "./assets/splash_v2.png",
        "backgroundColor": "#ffffff"
      },
      "package": "com.something.someone"
    },
    "web": {
      "favicon": "./assets/something.png"
    },
    "plugins": ["expo-router"],

    "extra": {
      "router": {
        "origin": false
      },
      "eas": {
        "projectId": "something"
      }
    },
    "runtimeVersion": {
      "policy": "appVersion"
    },
    "updates": {
      "url": "https://u.expo.dev/something"
    }
  }
}

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

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;babel.config.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = function (api) {
  api.cache(true);
  return {
    presets: ["babel-preset-expo"],
    plugins: [
      [
        "module:react-native-dotenv",
        {
          moduleName: "@env",
          path: ".env",
          blacklist: null,
          whitelist: null,
          safe: false,
          allowUndefined: true,
        },
      ],
    ],
  };
};

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

&lt;/div&gt;



</description>
      <category>expo</category>
      <category>gitlab</category>
      <category>reactnative</category>
      <category>cicd</category>
    </item>
    <item>
      <title>How to connect an external database to Kubernetes for a flask deployment.</title>
      <dc:creator>George Pamfilis</dc:creator>
      <pubDate>Thu, 29 Dec 2022 11:32:08 +0000</pubDate>
      <link>https://dev.to/gpamfilis/how-to-connect-an-external-database-to-kubernetes-for-a-flask-deployment-1pce</link>
      <guid>https://dev.to/gpamfilis/how-to-connect-an-external-database-to-kubernetes-for-a-flask-deployment-1pce</guid>
      <description>&lt;h2&gt;
  
  
  The Problem.
&lt;/h2&gt;

&lt;p&gt;I created a database on digital ocean and because I do not want to create a Kubernetes postgress database with persistent volumes and claims. I must connect to this External Service.&lt;/p&gt;

&lt;h4&gt;
  
  
  Digital ocean gave me this connection string for my &lt;code&gt;SQLALCHEMY_URI&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;postgresql://user:password@hostname:25061/databasename?sslmode=require&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It works with docker-compose and non docker flask run.&lt;/p&gt;

&lt;p&gt;For Kubernetes though it complains that it cannot resolve the hostname.&lt;/p&gt;

&lt;p&gt;We will rename the &lt;code&gt;hostname&lt;/code&gt;to &lt;code&gt;digitaloceanpostgress&lt;/code&gt;. It can be anything. It must match the &lt;code&gt;&lt;br&gt;
service.yml&lt;/code&gt; further down though.&lt;/p&gt;

&lt;p&gt;So our deployment will look something like this. This is mine, yours could be different.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: apps/v1 #  for k8s versions before 1.9.0 use apps/v1beta2  and before 1.8.0 use extensions/v1beta1
kind: Deployment
metadata:
  name: backend-deployment
  labels:
    app: backend-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: backend-deployment
  template:
    metadata:
      labels:
        app: backend-deployment
    spec:
      containers:
      - name: backend-deployment
        image: username/yourflaskserveretc:latest
        imagePullPolicy: Always
        ports:
        - containerPort: 8080
        env:
        - name: SQLALCHEMY_DATABASE_URI
        # Set this as a secret.
          value: "postgresql://user:password@digitaloceanpostgress:25061/databasename?sslmode=require"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Setting up the service.
&lt;/h3&gt;

&lt;p&gt;Type in your terminal &lt;code&gt;$ nslookup hostname (something.com)&lt;/code&gt; and paste the ip in the &lt;code&gt;service.yml&lt;/code&gt; bellow.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kind: Service
apiVersion: v1
metadata:
  name: digitaloceanpostgress
spec:
  clusterIP: None
  ports:
  - port: 25061
---
kind: Endpoints
apiVersion: v1
metadata:
  name: digitaloceanpostgress
subsets:
  - addresses:
  # nslookup hostname given by digitalocean database.
      - ip: ip-from-nslookup
    ports:
      - port: 25061
        name: digitaloceanpostgress
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Finito.
&lt;/h3&gt;

&lt;p&gt;Disclaimer. Although this works for me it might not be the goto solution for a pro. I am still a newbie.&lt;/p&gt;

&lt;h4&gt;
  
  
  References.
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.googblogs.com/kubernetes-best-practices-mapping-external-services/" rel="noopener noreferrer"&gt;https://www.googblogs.com/kubernetes-best-practices-mapping-external-services/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/63344920/access-external-database-from-kubernetes" rel="noopener noreferrer"&gt;https://stackoverflow.com/questions/63344920/access-external-database-from-kubernetes&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>csharp</category>
      <category>coding</category>
    </item>
  </channel>
</rss>
