Skip to content

Instantly share code, notes, and snippets.

Avatar

Jose Quintana joseluisq

View GitHub Profile
@joseluisq
joseluisq / try_files.rs
Created Jun 27, 2021
A simple Nginx `try_files` directive parsing example written in Rust
View try_files.rs
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 Apr 5, 2021
Una simple convención que representa respuestas de servidor JSON.
View response.ts
/** 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 Apr 5, 2021
Generate secure random string values in Javascript using cryto-random bytes
View random_hash.js
/** 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 Feb 14, 2021
How to resize a qcow2 disk image on Linux
View resize_disk_image.md

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 Feb 10, 2021 — forked from lu4nm3/main.rs
Tokio Async: Concurrent vs Parallel
View main.rs
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 Nov 6, 2020
Dead simple Javascript browser scraper to backing up YOUR Quora content. Feel free to customize it to your needs.
View quora_browser_scraper.js
/**
* 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 Sep 24, 2020
How to save space on disk removing ArchLinux Pacman packages cache
View pacman_cache.md

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/
@joseluisq
joseluisq / renew-gpgkey.md
Created Sep 2, 2020 — forked from krisleech/renew-gpgkey.md
Renew Expired GPG key
View renew-gpgkey.md

Renew GPG key

Given that your key has expired.

$ gpg --list-keys
$ gpg --edit-key KEYID

Use the expire command to set a new expire date:

@joseluisq
joseluisq / slugify.ts
Created Aug 18, 2020
Custom Typescript slugify function
View slugify.ts
export function slugify (text: string, separator = "-", ampersand = "and") {
const a = "àáäâèéëêìíïîòóöôùúüûñçßÿỳýœæŕśńṕẃǵǹḿǘẍźḧ"
const b = "aaaaeeeeiiiioooouuuuncsyyyoarsnpwgnmuxzh"
const p = new RegExp(a.split("").join("|"), "g")
return text.toString().toLowerCase()
// Replace whitespaces and underscores with single hyphens
.replace(/[\s_]+/g, separator)
// Replace special chars
.replace(p, (c) => b.charAt(a.indexOf(c)))
@joseluisq
joseluisq / README.md
Last active Aug 10, 2020
How to get just the name of first Docker service running
View README.md

How to get just the name of first Docker service running

Following command will get just the name of the first Docker service running (usually the last one deployed) of a list of N services with running/shutdown/etc status.

Format name: service_name.N.ID

docker service ps my_service_name \
    --no-trunc --format="{{.Name}}.{{.ID}}/{{.DesiredState}}" | grep "Running" | cut -f1 -d "/" | head -n1
# my_service_name.1.abcd1v23ui456pyu7lx8k9fze