Skip to content

Instantly share code, notes, and snippets.

View ginixsan's full-sized avatar

Ginés Sanz ginixsan

View GitHub Profile
@ginixsan
ginixsan / client.js
Created October 4, 2020 09:53 — forked from crtr0/client.js
A simple example of setting-up dynamic "rooms" for socket.io clients to join
// set-up a connection between the client and the server
var socket = io.connect();
// let's assume that the client page, once rendered, knows what room it wants to join
var room = "abc123";
socket.on('connect', function() {
// Connected, let's sign-up for to receive messages for this room
socket.emit('room', room);
});
@ginixsan
ginixsan / pedestrian-tracker.js
Created April 20, 2021 08:54 — forked from MForMarlon/pedestrian-tracker.js
Pedestrian tracker using HOG Descriptor and opencv4nodejs
// based from https://github.com/justadudewhohacks/opencv4nodejs/tree/master/examples/simpleTracking1.js
// This code is meant to be run on a Raspberry Pi 3 with the picamera.
// NOTE: Before running this code, for OpenCV to detect the camera, you need to run sudo modprobe bcm2835-v4l2
// TODO: Write each detected frame to an image file somewhere, with the timestamp in the name
const cv = require('opencv4nodejs');
const delay = 50;
const hog = new cv.HOGDescriptor();
hog.setSVMDetector(cv.HOGDescriptor.getDefaultPeopleDetector());
@ginixsan
ginixsan / index.html
Created May 10, 2021 07:56
Webview Tag Examples
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
<!-- All of the Node.js APIs are available in this renderer process. -->
We are using Node.js <script>document.write(process.versions.node)</script>,
@ginixsan
ginixsan / nodejs-cicd-github-actions.md
Created January 13, 2022 13:15 — forked from danielwetan/nodejs-cicd-github-actions.md
Deploy Node.js to VPS using Github Actions

Deploy Node.js to VPS using Github Actions

Steps to deploy Node.js to VPS using PM2 and Github Actions

1. Clone repo to vps folder

git clone https://github.com/danielwetan/node1.git

Do not use forEach with async-await

TLDR: Use for...of instead of forEach in asynchronous code.

The problem

Array.prototype.forEach is not designed for asynchronous code. (It was not suitable for promises, and it is not suitable for async-await.)

For example, the following forEach loop might not do what it appears to do:

@ginixsan
ginixsan / express.js
Created August 18, 2022 18:26 — forked from gabrielstuff/express.js
express + passport + session / req.session
/**
* Module dependencies.
*/
var express = require('express'),
mongoStore = require('connect-mongo')(express),
flash = require('connect-flash'),
viewHelpers = require('./middlewares/view'),
fs = require('fs'),
upload = require('jquery-file-upload-middleware');
@ginixsan
ginixsan / iBeaconCalculateDistance.js
Created October 26, 2022 17:39 — forked from JoostKiens/iBeaconCalculateDistance.js
iBeacon calculate distance in meters
// Based on http://stackoverflow.com/a/20434019
function calculateAccuracy(txPower, rssi) {
if (rssi === 0) {
return -1; // if we cannot determine accuracy, return -1.
}
var ratio = rssi * 1 / txPower;
if (ratio < 1.0) {
return Math.pow(ratio, 10);
@ginixsan
ginixsan / client.html
Created December 7, 2022 08:37 — forked from agrueneberg/client.html
HMAC-SHA256 example for verifying both the data integrity and the authentication of a request in Node.js and web browsers.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HMAC-SHA256 Example</title>
</head>
<body>
<script src="http://crypto.stanford.edu/sjcl/sjcl.js"></script>
<script>
var sharedSecret, query, signature, hmac, xhr;
@ginixsan
ginixsan / nodejs_java_encrypt_decrypt_128.js
Created January 17, 2023 07:49 — forked from luizwbr/nodejs_java_encrypt_decrypt_128.js
Encrypt and Decrypt using 128 for Nodejs or Javascript that actually works
// None of the tutorals could help me, so I adapted a few codes.
// What I really want is make a full duplex way between NodeJS and Java, using encrypt/decrypt with AES 128 bit
// 1 - you must have to generate the key
openssl enc -aes-128-cbc -k secret -P -md sha1
// key examples:
// DCDD74627CD60252E35DFBA91A4556AA
// 2CB24CFDB3F2520A5809EB4851168162
// 468CA14CA44C82B8264F61D42E0E9FA1