Skip to content

Instantly share code, notes, and snippets.

View joseluisq's full-sized avatar

Jose Quintana joseluisq

View GitHub Profile
@joseluisq
joseluisq / env.ts
Last active May 10, 2022 08:54
Get a Typescript typed environment variable value from `process.env` (NodeJS) with type casting for booleans, strings and numbers
/**
* Return an environment variable typed value from `process.env`.
* It also supports a default value in case of `undefined`.
*
* The function will follow these steps to take a typed value:
* 1. First it will try to get the env value from `process.env`.
* 2. Then if `undefined` then it try with the default environment variable value if defined.
* 3. Otherwise if the default value is `undefined` then it will return the Javascript default values:
* - Boolean: `false`
* - String: `""`
# Match on all types of devices but joysticks
#
# If you want to configure your devices, do not copy this file.
# Instead, use a config snippet that contains something like this:
#
# Section "InputClass"
# Identifier "something or other"
# MatchDriver "libinput"
#
# MatchIsTouchpad "on"
@joseluisq
joseluisq / try_files.rs
Created June 27, 2021 21:03
A simple Nginx `try_files` directive parsing example written in Rust
enum Token {
Start,
Middle,
End,
}
/// Parses the Nginx-like `try_files` directive string and returns a vector of tokens.
pub fn parse(val: &str) -> Vec<String> {
let mut kind = Token::Start;
let mut token = String::new();
@joseluisq
joseluisq / response.ts
Created April 5, 2021 10:10
Una simple convención que representa respuestas de servidor JSON.
/** Representa una respuesta JSON satisfactoria */
interface ResponseOk<T = null> {
success: true
data: T
}
/** Representa una respuesta JSON errónea */
interface ResponseFail<T = null> {
success: false
code: string|number
@joseluisq
joseluisq / random_hash.js
Created April 5, 2021 09:43
Generate secure random string values in Javascript using cryto-random bytes
/** Generate secure random string values in Javascript using cryto-random bytes */
function randomHash (len) {
return Array.from(
window.crypto.getRandomValues(new Uint8Array(Math.ceil(len / 2))),
(b) => ("0" + (b & 0xFF).toString(16)).slice(-2)
).join("")
}
// Simple tests with various lengths
@joseluisq
joseluisq / resize_disk_image.md
Last active April 16, 2024 11:18
How to resize a qcow2 disk image on Linux

How to resize a qcow2 disk image on Linux

This example takes olddisk.qcow2 and resizes it into newdisk.qcow2, extending one of the guest's partitions to fill the extra space.

1. qcow2 format

1.1. Verify the filesystems of olddisk.qcow2

@joseluisq
joseluisq / main.rs
Created February 10, 2021 22:23 — forked from lu4nm3/main.rs
Tokio Async: Concurrent vs Parallel
use futures::StreamExt;
use std::error::Error;
use tokio;
use tokio::macros::support::Pin;
use tokio::prelude::*;
use tokio::time::{Duration, Instant};
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut multi_threaded_runtime = tokio::runtime::Builder::new()
.threaded_scheduler()
@joseluisq
joseluisq / quora_browser_scraper.js
Last active November 6, 2020 13:45
Dead simple Javascript browser scraper to backing up YOUR Quora content. Feel free to customize it to your needs.
/**
* DISCLAIMER:
* The only intention of this "scraper script" is to serving as a backup tool for YOUR own content on Quora.
* Which means YOUR PUBLIC/PRIVATE content with YOU as author.
* So use this script under Quora Policy and Term conditions. https://www.quora.com/about/tos_archive
**/
/**
* Dead simple Javascript browser scraper to backing up YOUR Quora content.
* Feel free to customize it to your needs.
@joseluisq
joseluisq / pacman_cache.md
Last active August 6, 2021 09:48
How to save space on disk removing ArchLinux Pacman packages cache

How to save space on disk removing ArchLinux Pacman packages cache

1. Check out how many space is taken by Pacman packages cache

ls /var/cache/pacman/pkg/ | wc -l
# 13886
du -sh /var/cache/pacman/pkg/
# 61G	/var/cache/pacman/pkg/