Skip to content

Instantly share code, notes, and snippets.

@mirzap
mirzap / query_customer_feedback.py
Created March 11, 2023 21:30 — forked from amix/query_customer_feedback.py
Use LlamaIndex and GPT-3 to query customer insights
import os
import logging
import sys
import textwrap
from llama_index import (
GPTKeywordTableIndex,
SimpleDirectoryReader,
LLMPredictor,
)
@mirzap
mirzap / postgresql_recursive.sql
Created October 12, 2022 18:27 — forked from dankrause/postgresql_recursive.sql
An example of creating a recursive postgresql query to generate data about parent-child relationships within a single table.
CREATE TABLE test
(
id INTEGER,
parent INTEGER
);
INSERT INTO test (id, parent) VALUES
(1, NULL),
(2, 1),
@mirzap
mirzap / make_variable_check.md
Created August 30, 2022 19:47 — forked from bbl/make_variable_check.md
Makefile check if variable is defined

Check if variable is defined in a Makefile

Using ifndef

ifndef MY_FLAG
$(error MY_FLAG is not set)
endif
@mirzap
mirzap / email-address-syntax-validation-let-the-browser-do-it.md
Created August 14, 2022 18:34 — forked from nepsilon/email-address-syntax-validation-let-the-browser-do-it.md
Email address syntax validation? Let the browser do it (without regexp) — First published in fullweb.io issue #77

Email address syntax validation? Let the browser do it (without regexp)

Here is a simple and robust way to check for the validity of an email address syntax directly in the browser. No need for crazy regular expressions.

e = document.createElement('input')
e.type = 'email'
// check some email addresses
e.value = 'hi@'
@mirzap
mirzap / fn_uuid_time_ordered.sql
Created July 16, 2022 18:21 — forked from fabiolimace/UUIDv6.sql
Function for generating time-ordered UUIDs (v6) on PostgreSQL
/**
* Returns a time-ordered UUID (v6).
*
* Tags: uuid guid uuid-generator guid-generator generator time order rfc4122 rfc-4122
*/
create or replace function fn_uuid_time_ordered() returns uuid as $$
declare
v_time timestamp with time zone:= null;
v_secs bigint := null;
@mirzap
mirzap / generate_ulid_text.sql
Created July 15, 2022 17:29 — forked from kohenkatz/generate_ulid_text.sql
Postgres stuff for working with ULID
-- From https://github.com/geckoboard/pgulid/blob/d6187a00f66dca196cf5242588f87c3a7969df75/pgulid.sql
--
-- pgulid is based on OK Log's Go implementation of the ULID spec
--
-- https://github.com/oklog/ulid
-- https://github.com/ulid/spec
--
-- Copyright 2016 The Oklog Authors
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
@mirzap
mirzap / gist:a12ff04472d49e2aa45d965a727e93d6
Created September 30, 2021 15:57 — forked from robertsosinski/gist:1123254
Recursive breadcrumb query for Postgres
with recursive breadcrumbs(id, parent_id, name) as (
select id, parent_id, name
from pages
where id = 4
union
select p.id, p.parent_id, p.name
from pages p
inner join breadcrumbs b on p.id = b.parent_id
)
select * from breadcrumbs;
@mirzap
mirzap / SchemaSpy-HOWTO.md
Created July 25, 2021 08:49 — forked from dpapathanasiou/SchemaSpy-HOWTO.md
How to use SchemaSpy to generate the db schema diagram for a PostgreSQL database

SchemaSpy is a neat tool to produce visual diagrams for most relational databases.

Here's how to use it to generate schema relationship diagrams for PostgreSQL databases:

  1. Download the jar file from here (the current version is v6.1.0)

  2. Get the PostgreSQL JDBC driver (unless your installed version of java is really old, use the latest JDBC4 jar file)

  3. Run the command against an existing database. For most databases, the schema (-s option) we are interested in is the public one:

@mirzap
mirzap / auth-hook.js
Created July 19, 2021 14:45 — forked from ulises-jeremias/auth-hook.js
Examples of hooks utils using axios, recoil.js, keycloak-js, @react-keycloak/web and more.
import { useCallback, useEffect, useState } from 'react';
import { useSetRecoilState } from 'recoil';
import { useKeycloak } from '@react-keycloak/web';
import { commonNotification } from './common';
/**
* Returns the auth info and some auth strategies.
*
*/
@mirzap
mirzap / Dockerfile-es
Created July 12, 2021 11:26 — forked from wshayes/Dockerfile-es
Elasticsearch and Kibana using docker-compose (v3)
FROM docker.elastic.co/elasticsearch/elasticsearch:5.5.1
RUN \
mv /usr/share/elasticsearch/plugins/x-pack /usr/share/elasticsearch/plugins/.removing-x-pack && \
mv /usr/share/elasticsearch/plugins/.removing-x-pack /usr/share/elasticsearch/plugins/x-pack && \
/usr/share/elasticsearch/bin/elasticsearch-plugin remove x-pack