Skip to content

Instantly share code, notes, and snippets.

View ikhsanalatsary's full-sized avatar
🏠
Working from home

Abdul Fattah Ikhsan ikhsanalatsary

🏠
Working from home
View GitHub Profile
@ikhsanalatsary
ikhsanalatsary / catchWrapper.js
Last active December 11, 2020 00:04
A higher order function / decorator to catch promise based implementation
function catchWrapper(promiseFunc) {
return function(req, res, next) {
return promiseFunc(req, res, next).catch(function (error) {
// do something, e.g: logging, etc
console.error(error);
res.status(400).json({message: error.message});
})
}
}
@ikhsanalatsary
ikhsanalatsary / Student.vue
Last active September 6, 2020 09:07
Student rev.3
<template lang="html">
<vs-row vs-justify="center" vs-w="8">
<vs-col type="flex" vs-justify="center">
<form class="centerx labelx">
<vs-input
:danger="validationField.name"
danger-text="This field is required!"
label="Name"
placeholder="Student full name"
v-model="name"
@ikhsanalatsary
ikhsanalatsary / Student.vue
Created September 6, 2020 08:51
Student.vue rev2
<template lang="html">
<vs-row vs-justify="center" vs-w="8">
<vs-col type="flex" vs-justify="center">
<form class="centerx labelx">
<vs-input
:danger="validationField.name"
danger-text="This field is required!"
label="Name"
placeholder="Student full name"
v-model="name"
@ikhsanalatsary
ikhsanalatsary / Student.vue
Last active September 6, 2020 08:25
student1.vue
<template lang="html">
<vs-row vs-justify="center" vs-w="8">
<vs-col type="flex" vs-justify="center">
<form class="centerx labelx">
<vs-input
:danger="validationField.name"
danger-text="This field is required!"
label="Name"
placeholder="Student full name"
v-model="name"
@ikhsanalatsary
ikhsanalatsary / youtube-dl-pluralsight.md
Last active September 1, 2020 02:59 — forked from quangnd-pgvn/youtube-dl-pluralsight.md
Download Pluralsight videos

Download Plural Sight videos

Software required:

youtube-dl

After installation and putting the youtube-dl in PATH

youtube-dl --username YOUR_USERNAME --password YOUR_PASSWORD --all-subs https://app.pluralsight.com/library/courses/javascript-development-environment -o "~/video/%(playlist)s/%(chapter_number)s. %(chapter)s/%(playlist_index)s. %(title)s.%(ext)s" --sleep-interval 10 --user-agent "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36"
@ikhsanalatsary
ikhsanalatsary / as.ts
Created July 18, 2020 02:26
Typecasting Example 2
let someValue: any = "this is a string";
let strLength: number = (someValue as string).length;
// konversi object ke readonly (immutable diwaktu kompile)
let obj = { key: 'value' } as const
obj.key = 3; // error
@ikhsanalatsary
ikhsanalatsary / cast.ts
Created July 18, 2020 01:51
Typecasting Example
Number('3') * Number('2')
// ini error jika di typescript
// tapi di javascript, otomatis di konversi ke number
'3' * '2'
@ikhsanalatsary
ikhsanalatsary / withOmit.ts
Created July 18, 2020 00:55
Utility Type Example
type Admin = { name: string, age: number, position: "admin" };
// Type of "admin" is "{ position: "admin" }"
const admin: Omit<Admin, "age" | "name"> = { position: "admin" }
@ikhsanalatsary
ikhsanalatsary / refine.ts
Created July 17, 2020 23:35
Type Refinement example
function calculateSum(firstUserInput: unknown, secondUserInput: unknown) {
if (typeof firstUserInput !== "number") {
throw new TypeError("first provided value has a wrong type. Should be a number")
}
if (typeof secondUserInput !== "number") {
throw new TypeError("second provided value has a wrong type. Should be a number")
}
return firstUserInput + secondUserInput;
}
let calc1 = calculateSum('sa', 'dd')
@ikhsanalatsary
ikhsanalatsary / overloads.ts
Last active July 17, 2020 23:46
Overloading
class Utility {
collectionFor(name: string): Characters
collectionFor(name: string, type: 'removed'): number
collectionFor(name: string, type?: string | undefined): CharsOrNum {
if (typeof type === 'undefined') type = 'characters'
let constantName
const col1 = ['meny', 'men', 'mem', 'me']
const col2 = ['peny', 'pen', 'pem']
if (type === 'characters') {
constantName = `${name}_${type}`