Skip to content

Instantly share code, notes, and snippets.

View marcosrjjunior's full-sized avatar

Marcos RJJunior marcosrjjunior

View GitHub Profile
@marcosrjjunior
marcosrjjunior / custom-kysely-adapter.ts
Last active July 15, 2024 10:37
Custom kysely adapter to use with authjs (nextauth)
import { Kysely, SqliteAdapter } from 'kysely'
export function KyselyAdapter(db: Kysely<any>): any {
const { adapter } = db.getExecutor()
const { supportsReturning } = adapter
const isSqlite = adapter instanceof SqliteAdapter
/** If the database is SQLite, turn dates into an ISO string */
const to = isSqlite ? format.to : <T>(x: T) => x as T
/** If the database is SQLite, turn ISO strings into dates */
const from = isSqlite ? format.from : <T>(x: T) => x as T
@marcosrjjunior
marcosrjjunior / docker-compose.yaml
Created July 6, 2024 06:22
docker compose services
version: '3.4'
services:
postgres:
container_name: postgres_api
image: postgres:16.3-alpine3.20
ports:
- 5432:5432
restart: always
volumes:
- db_data:/var/lib/postgresql/data
@marcosrjjunior
marcosrjjunior / kysely + turso + migrations (sqlite)
Last active November 11, 2024 17:44
Kysely + Turso + Migrations
{
"scripts": {
// ...
"db:migrate:up": "bun run -r dotenv/config ./src/lib/db/migrate latest",
"db:migrate:down": "bun run -r dotenv/config ./src/lib/db/migrate down",
"db:migrate:create": "bun run -r dotenv/config ./src/lib/db/migrate create initial",
"db:generate:types": "bunx kysely-codegen --out-file=src/lib/db/schema/Database.ts",
},
"dependencies": {
"kysely": "^0.27.3",
@marcosrjjunior
marcosrjjunior / outdoors
Last active July 9, 2023 10:47
outdoors
[
{
"type": "alltrails",
"title": "Oeschinen Lake Lookout",
"movingTime": "1h 40m",
"length": "7.1 km",
"elevationGain": "386m",
"createdAt": "June 7, 2023",
"image": "http://alltrails.com/api/alltrails/v3/maps/175121895/profile_photo?size=large&key=3p0t5s6b5g4g0e8k3c1j3w7y5c3m4t8i&show_static_map=yes&static_map_size=396x180",
"url": "https://www.alltrails.com/explore/recording/afternoon-hike-at-oeschinenbahn-heuberg-db2b418"
@marcosrjjunior
marcosrjjunior / listing-and-hashing.md
Created January 10, 2023 03:46
Listing and hashing files from directory sha256

List files from dir

find src/*

Excluding directories

find src/* -not -path "src/dir-name-to-exclude/*"
@marcosrjjunior
marcosrjjunior / date-fns-timezone.ts
Last active September 14, 2023 01:23
date-fns timezone to utc
// zoneName: {country}/{city}
export const zoneTimeToUTC = ({ zoneName }) => {
const now = new Date('2022-12-06T20:12:46+10:00')
const nowTimezone = formatInTimeZone(now, zoneName, 'yyyy-MM-dd HH:mm:ss')
return zonedTimeToUtc(nowTimezone, zoneName).toISOString()
}
@marcosrjjunior
marcosrjjunior / test.json
Last active November 28, 2022 04:19
test
[
{
"id": 1,
"name": "Jennifer Connelly"
},
{
"id": 2,
"name": "Tom Cruise",
"children": [
{
@marcosrjjunior
marcosrjjunior / dgrm
Created September 5, 2022 03:50
url short
#### Idea
- Structure a simple URL shortener. Simple URL and short URL
- Now, what if we want to manage a link for each user
- Ability to store views on the link
- Client is complaining that the link is slow
- Client is still complaining that the link is slow
@marcosrjjunior
marcosrjjunior / React
Last active September 5, 2022 04:08
tst
// DATA
// Initial JSON data
const people = [
{
id: 1,
name: 'Jennifer Connelly'
},
{
id: 2,
name: 'Tom Cruise',
@marcosrjjunior
marcosrjjunior / RedisService.ts
Last active January 22, 2023 19:58
node redis 4.0.4+
import hash from 'object-hash';
import { createClient } from 'redis';
import { config } from '../config';
import { serialize } from '../utils/objectTransformer';
import { log } from '../utils/errors';
export const REDIS_KEY_PREFIX = `PROJECTPREFIX-${config.env?.toLowerCase()}`;
class RedisService {
client: any;