Skip to content

Instantly share code, notes, and snippets.

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

Andre Alves Leocadio Hiweus

🏠
Working from home
View GitHub Profile

This script below get a path to one video and stream using php, this is possible because the Range header field. If the browser doesn't allow this header the script only drop all video on response.

<?php
  function streamVideo($path) {
      $fileInfo = pathinfo($path);
      header("Content-Disposition: inline; filename=\"{$fileInfo['basename']}\"");
      if(!isset(getallheaders()['Range'])) {
          echo file_get_contents($path);
@Hiweus
Hiweus / multiple-ssh.md
Last active March 25, 2024 03:07
Configure computer to use multiple ssh keys for same service

Configure multiple ssh keys on machine

For this project i will use github as example. I have two keys id_rsa and personal_rsa.

First of all you need to create file ~/.ssh/config. Inside the file put content as follow and edit as your need

# Default configuration (ask for password if there's no key in config file)
Host *
IdentitiesOnly yes

Configure mocha to watch typescript files

When you use mocha with flag --watch on typescript you need to set .mocharc.json file on root folder of project to specify for mocha watch .ts files; Otherwise the terminal will spawn in the first run but will not restart when you save the file.

// .mocharc.json
{
    "extension": [
 "ts"

Calc distance

SQL Server function to calc distance between two coordinates

create FUNCTION [dbo].[fncCalcula_Distancia_Coordenada](
                                                   @decLat1Deg DECIMAL(9,6), -- First latitude in degrees.
                                                   @decLon1Deg DECIMAL(9,6), -- First longitude in degrees.
                                                   @decLat2Deg DECIMAL(9,6), -- Second latitude in degrees.

Watch mode scripts npm

Sometimes packages like Nodemon, Mocha who watch changes on files to perform some actions doesnt work correctly 🤕.

All these packages use CHOKIDAR library to watch file changes, to fix this behaviour on chokidar set environment variable CHOKIDAR_USEPOLLING=true.

# Linux

Problems i faced with JEST

Jest slow on WSL2

I moved my project from Windows Desktop to Linux Home and the tests became faster.

Jest not watching file changes on WSL2

This is related to watchman and inotify, i just moved my project from Windows Desktop to Linux home and watch mode start to work. This ocours because inotify doesn't work correctly ousite a linux file system. Issue Here

@Hiweus
Hiweus / abandonadoPorVoce.whatsapp.js
Created May 3, 2022 15:50
Script para enviar pelo whatsapp a musica inteira "Abandonada por você" linha por linha
var linhas = `Abandonada por você
Tenho tentado te esquecer
No fim da tarde, uma paixão
No fim da noite, uma ilusão
No fim de tudo, a solidão
Apaixonada por você
Tenho tentado não sofrer
Lendo antigas poesias
Rindo em novas companhias
E chorando por você

To create a custom mouse script in nautilus just put your script in ~/.local/share/nautilus/scripts/ and make sure it's executable.

Configure nginx to use ssl

Generating certificates

# generate .crt and .key files
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.crt

# generate strong Diffie-Hellman group
sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
const camelToSnakeCase = str => str.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`);
function mapFieldsToStorageName(name) {
const map = new Map()
map.set('userId', 'owner_id')
return map.get(name) ?? camelToSnakeCase(name)
}
function generateQuery(tableName, filters, ordering, options) {
const values = []