Skip to content

Instantly share code, notes, and snippets.

View bicho19's full-sized avatar
💭
writing lines that ends with ;

Hachemi Hamadi bicho19

💭
writing lines that ends with ;
View GitHub Profile
import {
Entity,
ManyToOne,
PrimaryKey,
Property,
type Rel,
} from '@mikro-orm/core';
import { Application } from '@/modules/application/models/application.entity';
@Entity({ tableName: 'deployments' })
@bicho19
bicho19 / generate-pushid.js
Created February 5, 2024 21:12 — forked from mikelehen/generate-pushid.js
JavaScript code for generating Firebase Push IDs
/**
* Fancy ID generator that creates 20-character string identifiers with the following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the
* latter ones will sort after the former ones. We do this by using the previous random bits
* but "incrementing" them by 1 (only in the case of a timestamp collision).
*/
@bicho19
bicho19 / calendar.tsx
Created December 7, 2023 16:48 — forked from mjbalcueva/calendar.tsx
shadcn ui calendar custom year and month dropdown
"use client"
import * as React from "react"
import { buttonVariants } from "@/components/ui/button"
import { ScrollArea } from "@/components/ui/scroll-area"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
import { cn } from "@/lib/utils"
import { ChevronLeft, ChevronRight } from "lucide-react"
import { DayPicker, DropdownProps } from "react-day-picker"

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.

// based on: https://github.com/bsimic0001/AegisWallet/blob/master/mobile/src/main/java/com/aegiswallet/utils/MessagingUtils.java
public class MessagingUtils {
public static void main(String[] args) {
System.out.println("encode: " + encode("*100#"));
System.out.println("decode: " + decode("<<message to decode>>"));
}
/**
@bicho19
bicho19 / DashedDivider.kt
Created June 21, 2022 14:30 — forked from kafri8889/DashedDivider.kt
Dashed divider in Jetpack Compose
@Preview
@Composable
private fun DashedDividerPreview() {
DashedDivider(
color = Color.Black,
thickness = 1.dp,
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
)
@bicho19
bicho19 / DateTextField.kt
Created June 21, 2022 14:28 — forked from kafri8889/DateTextField.kt
Date format in TextField Jetpack Compose
@Composable
fun Screen() {
var date by remember {
mutableStateOf(
TextFieldValue(
text = "dd-MM-yyyy"
)
)
}
@bicho19
bicho19 / associations.md
Created May 28, 2022 14:56 — forked from AloofBuddha/associations.md
Sequelize Relationships: hasOne vs belongsTo
@bicho19
bicho19 / app.html
Created May 4, 2022 13:40 — forked from derekchiang/app.html
[electron]Use electron as a Web Server
<!doctype html>
<html><head><script src="app.js"></script></head><body></body></html>