Skip to content

Instantly share code, notes, and snippets.

View itsdonnix's full-sized avatar

DON itsdonnix

View GitHub Profile
@itsdonnix
itsdonnix / vlang_snippets.v
Created November 12, 2020 11:54
V programming language snippets
// Map string values char by char to array of byte
'Hello'.bytes()
// Map string values char by char to array of string
'Hello'.bytes().map(it.str())
// or
'Hello'.split('')
@itsdonnix
itsdonnix / capitalize.v
Last active September 1, 2022 03:10
V programming language capitalize string
/**
How to capitalize string in V programming language
**/
fn capitalize(str string) string {
mut words := str.split(' ')
for i, word in words {
if word.len == 0 { continue }
@itsdonnix
itsdonnix / pdf.js
Last active November 26, 2023 11:50
Generate PDF on NodeJS with Puppeteer & EJS
const ejs = require('ejs')
const puppeteer = require('puppeteer')
const fs = require('fs')
const { Buffer } = require('buffer')
const { PDFDocument } = require('pdf-lib')
async function createPDF({ template, data, output, title = 'Laporan', format = 'A4' }) {
const content = ejs.render(fs.readFileSync(template).toString(), data)
const browser = await puppeteer.launch({
@itsdonnix
itsdonnix / linux_commands.sh
Last active February 18, 2021 20:39
Linux Commands
# Bulk rename files.
rename 's/\.txt$/.text/' *.txt
rename 's/\.old$/.new/' *.old
@itsdonnix
itsdonnix / mobile_first_css_media_query.css
Last active September 8, 2021 09:36
Mobile First CSS Media Query Breakpoints from Tailwind CSS
/*
These media querie breakpoints is inspired from tailwind css
https://tailwindcss.com/docs/breakpoints
/*
/* 0px - 320px */
/* extra small: 320px - 640px */
@media (min-width: 320px) {}
@itsdonnix
itsdonnix / add_search_query_to_url.js
Last active September 1, 2022 03:07
Add search query to URL in JavaScript
/**
How to add search query to url in JavaScript
By. Don Alfons Nisnoni <[email protected]>
**/
function addSearchQuery(baseURL, searchQueryObj) {
const url = new URL(baseURL);
for (const key of Object.keys(searchQueryObj)) {
@itsdonnix
itsdonnix / github_authentication_with_token.md
Last active September 1, 2022 02:59
GitHub Authentication with personal access token

How to set GitHub Authentication using token

Now GitHub will only accept authentication with SSH and token only. Then, how to do it?

You need to change the git remote URL to:

git remote set-url <stream> https://<token>@github.com/<username>/<repository_name>
@itsdonnix
itsdonnix / sshfs_load_pem_file.md
Created January 31, 2022 03:58
Use sshfs to mount an AWS EC2 folder using PEM file

Use sshfs to mount an AWS EC2 folder using PEM file

sshfs -o "IdentityFile=path/to/file.pem" ubuntu@EC2_HOST:/path/to/dir /path/to/mount/point
@itsdonnix
itsdonnix / random_date_start_end.js
Created February 16, 2022 03:30
Javascript Random Date from start to end
function randomDate() {
// Start from 01 Jan 2010
const start = new Date(2010, 1, 1);
// End with current date
const end = new Date();
const randomDate = new Date(
start.getTime() + Math.random() * (end.getTime() - start.getTime())
);
return randomDate.toISOString().slice(0, 10);
}