Skip to content

Instantly share code, notes, and snippets.

View magick93's full-sized avatar
💩
Focusing

magick93

💩
Focusing
View GitHub Profile
@henryivesjones
henryivesjones / postgresql_date_timestamp_interval_cheat_sheet.md
Created February 14, 2023 16:56
PostgreSQL DATE, TIMESTAMP, and INTERVAL cheat sheet

PostgreSQL DATE, TIMESTAMP, and INTERVAL cheat sheet

Working with DATE, TIMESTAMP, and INTERVAL in PostgreSQL can be confusing. In this article I will go over the three date/time related data types, and the two most useful date/time functions: DATE_PART and DATE_TRUNC. Finally, I will provide some real life examples of how these types and functions can be used within queries.

Types

PostgreSQL Date/Time Documentation

DATE

The DATE type contains the year, month, and day of a date. It is not possible to do any type of time related functions on a DATE without first converting it to a TIMESTAMP. Subtracting two DATE values from one another results in an INT representing the # of days between.

TIMESTAMP

The TIMESTAMP type contains a year, month, day, hour, minute, second, and microsecond. This is the type that I most often use.

@FelixZY
FelixZY / supabase_api_auth.sql
Last active April 30, 2024 09:18
How to configure Supabase (https://supabase.com/) to generate and accept API tokens.
-- Token Based API Access for Supabase
--
-- How to configure Supabase (https://supabase.com/) to generate and accept API tokens.
--
-- (c) 2022 Felix Zedén Yverås
-- Provided under the MIT license (https://spdx.org/licenses/MIT.html)
--
-- Disclaimer: This file is formatted using pg_format. I'm not happy with the result but
-- prefer to follow a tool over going by personal taste.
--
@oliveratgithub
oliveratgithub / socialnetworkimagesizes.js
Last active May 9, 2023 07:11
Social media networks image sizes as JSON and JavaScript lists – Contains image sizes for all major social networks and messengers as of 2020 (Facebook, Twitter, Instagram, Tik Tok, Telegram, WhatsApp, and more)
let socialnetworkimagesizes = {
'facebook': {
'profile': {
'Profile picture': { 'w': 180, 'h': 180 }
,'Cover photo': { 'w': 820, 'h': 312 }
}
,'content': {
'Timeline image': { 'w': 1200, 'h': 630 }
,'Highlighted image': { 'w': 1200, 'h': 717 }
,'Link - rectangular': { 'w': 1200, 'h': 628 }
@CSTDev
CSTDev / auto-increment-version.sh
Last active May 1, 2024 01:57
Script that will find the last Git Tag and increment it. It will only increment when the latest commit does not already have a tag. By default it increments the patch number, you can tell it to change the major or minor versions by adding #major or #minor to the commit message.
#!/bin/bash
#get highest tag number
VERSION=`git describe --abbrev=0 --tags`
#replace . with space so can split into an array
VERSION_BITS=(${VERSION//./ })
#get number parts and increase last one by 1
VNUM1=${VERSION_BITS[0]}
@trondhindenes
trondhindenes / .gitlab-ci.yml
Last active April 17, 2024 10:07
Run KinD (Kubernetes in Docker) as part of Gitlab CI job
#Spin up Kubernetes control plane as part of before_script, and destroys it using after_script
#Some custom logic to get to the right ip address
#Requres the gitlab docker runner, with "pass-thru" to the host docker socket.
stages:
- test
image: python:3.6.6 #the docker image you run in needs Docker installed, and access to the host docker socket.
test_integration_k8s:
tags:
@ianks
ianks / slugify.sql
Last active October 31, 2023 05:03
Generating Slugs in Postgres
CREATE EXTENSION IF NOT EXISTS "unaccent";
CREATE OR REPLACE FUNCTION slugify("value" TEXT)
RETURNS TEXT AS $$
-- removes accents (diacritic signs) from a given string --
WITH "unaccented" AS (
SELECT unaccent("value") AS "value"
),
-- lowercases the string
"lowercase" AS (
@hmfaysal
hmfaysal / iab_categories_openrtb_2.5_spec.json
Created February 5, 2018 10:57
IAB Categories OpenRTB 2.5 Spec
{
"categories": {
"IAB1": "Arts & Entertainment",
"IAB2": "Automotive",
"IAB3": "Business",
"IAB4": "Careers",
"IAB5": "Education",
"IAB6": "Family & Parenting",
"IAB7": "Health & Fitness",
"IAB8": "Food & Drink",
@bbrowning
bbrowning / openshift_instructions.md
Last active August 22, 2018 15:59
Running Apache OpenWhisk on OpenShift

Running Apache OpenWhisk on OpenShift

Prerequisites

These instructions assume you are using Minishift 1.0.1 or newer as your OpenShift installation.

You'll also need a wsk binary in your $PATH to interact with OpenWhisk after it's deployed. Download the latest version for your OS

@so0k
so0k / kubectl.md
Last active April 25, 2024 12:40
Playing with kubectl output

Kubectl output options

Let's look at some basic kubectl output options.

Our intention is to list nodes (with their AWS InstanceId) and Pods (sorted by node).

We can start with:

kubectl get no
@johannesjo
johannesjo / table-to-json.js
Last active April 30, 2024 21:10
Snippet to convert html table to json (to be used with google chrome or similiar)
function tableToJson(table) {
var data = [];
// first row needs to be headers
var headers = [];
for (var i=0; i<table.rows[0].cells.length; i++) {
headers[i] = table.rows[0].cells[i].innerHTML.toLowerCase().replace(/ /gi,'');
}
// go through cells