Skip to content

Instantly share code, notes, and snippets.

View revskill10's full-sized avatar
🎯
Focusing

Truong Hoang Dung revskill10

🎯
Focusing
  • Freelancer
  • Haiphong, Vietnam
View GitHub Profile
@revskill10
revskill10 / genpath.mjs
Created July 14, 2023 16:22
NextJS routes generation
import fs from 'fs';
import path from 'path';
function getCompName(filePath) {
const fileName = filePath.split('.')[0]
const componentName = fileName.replace(/\[|\]/g, '')
.split('/')
.filter(part => part !== 'routes')
.map(part => part.charAt(0).toUpperCase() + part.slice(1))
.join('');
@revskill10
revskill10 / translations.ts
Created July 13, 2023 14:15
Simple i18n helpers
type Path<T, Key extends keyof any = keyof T> = Key extends keyof T
? T[Key] extends object
? T[Key] extends infer R
? `${Key & string}.${Path<R, keyof R>}` | `${Key & string}`
: never
: `${Key & string}`
: never;
type Paths<T> = Path<T> extends string ? Path<T> : never;
function translation<T, P extends Paths<T>>(

Automating Daily Reports, because fuck it, really...

Each day at our company, developers are required to document their activities, painstakingly jotting down their daily work and future plans. A monotonous chore that I just really dislike.

So now, there's a scribe for that :

auto-dr-

Code

@revskill10
revskill10 / excel_generator.py
Created May 7, 2023 16:54 — forked from tnhu/excel_generator.py
Open and Edit an Excel template using Python's openpyxl library
from openpyxl import load_workbook
wb = load_workbook('template.xlsx')
# grab the active worksheet
ws = wb.active
# Data can be assigned directly to cells
ws['A2'] = 'Tom'
ws['B2'] = 30
Docker 23 + Traefik v2.9.10 and v1.7 + Let's Encrypt + Github Registry V2 ghcr.io + Updated on 12 April 2023
Content:
- Ubuntu 22.04
- Docker Engine 23.0.3
- Docker Compose 2.17.2
- Traefik v1.7.18 with dnsChallenge
- Traefik v2.9.9 with httpChallenge
--
- Github Registry V2 ghcr.io
@revskill10
revskill10 / useLocalStorage.ts
Created April 13, 2023 13:16 — forked from augustolazaro/useLocalStorage.ts
React hook to manage local storage changes
import * as React from 'react'
const originalSetItem = localStorage.setItem
localStorage.setItem = function() {
const event = new Event('storageChange')
document.dispatchEvent(event)
originalSetItem.apply(this, arguments)
}
const originalRemoveItem = localStorage.removeItem
localStorage.removeItem = function() {
//Extract fragment of code into its own function named after its purpose.
function printOwing(invoice) {
printBanner()
let outstanding = calculateOutstanding()
// print details
console.log(`name: ${invoice.customer}`)
console.log(`amount: ${outstanding}`)
}
@revskill10
revskill10 / deploy.md
Created February 28, 2023 09:51 — forked from intabulas/deploy.md
Deploying SurrealDB to Fly.io

These are the rough steps for getting a surrealdb instance running on fly.io and connecting to it. This is heavily based off of steps posted in the surrealdb discord by rvdende. View Origional Post.

These steps work just fine for the hobby (pay as you go) plan.

HEADS UP By default this will create an instance on a single shared cpu with 256m memory. This is pretty darn small to do anything but experiment, but its free. You can scale your instance to something more useable by visiting the https://fly.io/apps/<appname>/scale. Obviously scaling to larger instances will incur higher costs, please refer to fly.io pricing

Installing fly.io client

source: fly.io docs

@revskill10
revskill10 / monad.md
Created February 11, 2023 12:58
Explain Monad using Ruby

#Monad


  1. Explain Haskell typeclass using Ruby Type classes in Haskell can be thought of as similar to Ruby modules. Just like Ruby modules, type classes define a set of methods that can be implemented for different data types. However, unlike Ruby modules, type classes can be used to provide a common interface for data types that are defined in different places and by different libraries.

In Haskell, type classes are defined using the class keyword, followed by the name of the type class and the methods it defines. For example, here's how you might define a type class for types that can be compared for equality:

@revskill10
revskill10 / test.rb
Last active January 27, 2023 21:15
Pipeline programming
class Object
def true?
return unless self
tmp = yield
return tmp
end
def else
return yield unless self
self