Skip to content

Instantly share code, notes, and snippets.

View neos1803's full-sized avatar
🥽
Diving

Nanda W. Purba neos1803

🥽
Diving
View GitHub Profile
@neos1803
neos1803 / increment-string.sql
Created May 28, 2024 07:34
How to create a postgresql function that increment a string lead with 0000
CREATE OR REPLACE FUNCTION public.after_update()
RETURNS trigger
LANGUAGE plpgsql
AS $function$
declare
maximum character(5);
nextMax character(5);
BEGIN
-- Find max urutan
select max(tnp.urutan) into maximum from something;
@neos1803
neos1803 / delete.sh
Created May 27, 2024 02:31
Shell command to delete files by pattern
find . -name '*.orig' -delete
@neos1803
neos1803 / async-sign.js
Last active November 3, 2023 09:22
Sync and Async way of Verifying and Signing JWT
const { sign } = require('jsonwebtoken')
const token = new Promise((resolve, reject) => {
sign({ data: "Your Data" }, "Your_Secret", {}, (err, token) => {
if (err) reject(err);
else resolve(token)
});
});
@neos1803
neos1803 / script.js
Created September 14, 2023 07:17
Making directory the async way
const { stat, mkdir } = require('fs/promises');
/** Start of creating directory */
const directory = `your path like directory`;
await stat(directory)
.then(() => {
console.log(`Directory: ${dir} exist`);
return true
})
.catch(async (error) => {
@neos1803
neos1803 / script.js
Created September 14, 2023 07:07
Creating folder the sync way
const { existsSync, mkdir } = require('fs');
/** Start of creating directory */
const directory = `your path like directory`;
if (!existsSync(directory)) {
mkdir(directory, { recursive:true }, (err) => {
if (err) {
return console.error(err);
}
})
@neos1803
neos1803 / script.js
Created January 26, 2023 03:32
Javascript one liner two arrays duplicate checking
const duplicate = arr1.filter((v) => arr2.includes(v)).length > 0
@neos1803
neos1803 / script.ts
Created January 12, 2023 02:47
Simple Function to Transform Array of String to Text
/**
* Input: ['First Message', 'Second Message']
* Output: `1. First message \n 2. Second Message \n`
*/
export function arrayToTextWithEnter(arr: Array<any>): String {
let response = ``
arr.forEach((v, i) => {
response = response + `${i + 1}. ${v} \n`
});
@neos1803
neos1803 / script.js
Created October 6, 2022 04:33
Array increment of n in javascript one liner
const example = Array.from({ length: 1000 }, (_, i) => String(i + 1));
@neos1803
neos1803 / Task-1.md
Last active January 29, 2024 07:43
Technical Test (Note: You may choose which task you want to do. Doing all tasks is not a mandatory)

Create A Bookstore API with express

Guide

  1. Fork project project berikut sebagai base pengerjaan test https://github.com/neos1803/mock-technical-test.git
  2. Commit perubahan yang telah dikerjakan, bisa menggunakan cli: git commit -am 'Add some feature' atau menggunakan gui
  3. Push ke fork yang telah dibuat: git push origin nama-pribadi
  4. Silahkan open pull request.
  5. Penilaian akan dilakukan pada pull request masing-masing
@neos1803
neos1803 / loop.js
Last active June 2, 2022 04:05
Javascript for loop iteration notes
const array = [1,2,3,4,5,6,7,8];
// Declarative looping example
array.forEach((x) => someFunction());
array.map((x) => someFunction());
array.reduce((x) => someFunction());
// Imperative looping
for (const a of array) {
someFunction();
}