Skip to content

Instantly share code, notes, and snippets.

View mreis1's full-sized avatar

Reis mreis1

View GitHub Profile
@mreis1
mreis1 / README.md
Created November 17, 2020 09:44 — forked from anhldbk/README.md
TLS client & server in NodeJS

1. Overview

This is an example of using module tls in NodeJS to create a client securely connecting to a TLS server.

It is a modified version from documentation about TLS, in which:

  • The server is a simple echo one. Clients connect to it, get the same thing back if they send anything to the server.
  • The server is a TLS-based server.
  • Clients somehow get the server's public key and use it to work securely with the server

2. Preparation

Recently, after installing some libraries in my cordova project I started having this build error:

"This project uses AndroidX dependencies, but the 'android.useAndroidX' property is not enabled. Set this property to true in the gradle.properties file and retry."

Then after some research I came across this link: https://cordova.apache.org/announcements/2020/06/29/cordova-android-9.0.0.html (section = "Added AndroidX Support")

Turns out that androidX can be set in gradle properties starting on cordova-android@9. Since my project was using cordova-android@8 I upgraded and had to add "AndroidXEnabled" in config.xml as follows:

@mreis1
mreis1 / diff-dates.js
Created August 7, 2020 18:20
Calculate number of days and time between two dates
/**
diffDates returning number of days and time string
*/
function diffDates(a,b) {
var d = moment(a).diff(b);
var m = d / (3600*1000*24);
var m1 = Math.floor(m);
var t = d-(m1*3600*1000*24);
return {
days: m1,
@mreis1
mreis1 / elementor.txt
Created August 1, 2020 13:44
elementor code snippets
[data-elementor-device-mode="desktop"] selector {}
[data-elementor-device-mode="tablet"] selector {}
[data-elementor-device-mode="mobile"] selector {}
@mreis1
mreis1 / .htaccess
Last active July 22, 2020 21:56
Host wordpress in subfolder (ex: /wp) - .htaccess vs nginx
# BEGIN WordPress
# The directives (lines) between `BEGIN WordPress` and `END WordPress` are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
@mreis1
mreis1 / quotes.js
Created June 23, 2020 09:10
RegExp
// Credit: https://stackoverflow.com/questions/171480/regex-grabbing-values-between-quotation-marks
for (let o of [
"the world \"world\" is bright",
"the world `world` is bright",
"the world 'world' is bright"
]) {
var m = o.match(/(["'`])(?:(?=(\\?))\2.)*?\1/,'g');
console.log(m && m[0])
}
@mreis1
mreis1 / git-ssh-auth-win-setup.md
Created June 17, 2020 18:33 — forked from bsara/git-ssh-auth-win-setup.md
Setup SSH Authentication for Git Bash on Windows

Setup SSH Authentication for Git Bash on Windows

Prepararation

  1. Create a folder at the root of your user home folder (Example: C:/Users/uname/) called .ssh.
  2. Create the following files if they do not already exist (paths begin from the root of your user home folder):
  • .ssh/config
@mreis1
mreis1 / scheduleWarning.js
Last active May 26, 2020 10:30
Execute callback on time (schedule)
/***
Usage:
scheduleWarning('05:00:00',()=>console.log(new Date().toString())
*/
function scheduleWarning(time, triggerThis, adjust){
const ensureValidNum = (v, d, min, max) => {
if (!(typeof v === 'number' && !isNaN(v))) {
return d;
}
if (!(v >= min && v <= max)) { return d; }
@mreis1
mreis1 / client.js
Created April 17, 2020 15:36
node-axios-test (0.19.2)
const app = require('express')();
var axios = require('axios').default;
app.get('/:id', function (req, res) {
axios.get('http://localhost:3333/' + req.params.id)
.then((data) => {
console.log('Ok: ' + data);
res.json(data.data)
})
.catch((err) => {
@mreis1
mreis1 / readme.md
Last active February 17, 2020 00:26
JS Decorators
class MyClass {
    @readonly
    myProperty: string;
}
  • target: the class that the member is on.
  • name: the name of the member in the class.
  • descriptor: the member descriptor. This is essentially the object that would have been passed to Object.defineProperty.