Skip to content

Instantly share code, notes, and snippets.

View davalapar's full-sized avatar
🦁
rawr

@davalapar davalapar

🦁
rawr
View GitHub Profile
@davalapar
davalapar / request.js
Last active October 28, 2019 10:42
request.js
const fs = require('fs');
const p = require('path');
const http = require('http');
const https = require('https');
const qs = require('querystring');
const request = (config) => {
if (typeof config !== 'object' || config === null) {
throw Error('invalid non-object config');
@davalapar
davalapar / cpu.js
Created October 26, 2019 00:02 — forked from bag-man/cpu.js
How to calculate the current CPU load with Node.js; without using any external modules or OS specific calls.
var os = require("os");
//Create function to get CPU information
function cpuAverage() {
//Initialise sum of idle and time of cores and fetch CPU info
var totalIdle = 0, totalTick = 0;
var cpus = os.cpus();
//Loop through CPU cores
@davalapar
davalapar / windows.md
Created October 25, 2019 02:41
Command Lines

EADDRINUSE 80, 8080

  1. Type "netstat -aon" on Command Prompt
  2. Find the relative PID number to 127.0.0.1:8080 (or 3000)
  3. Run "taskkill /f /pid pidnumber"
@davalapar
davalapar / index.js
Last active November 10, 2020 13:09
LetsEncrypt Setup, Renew & NodeJS Usage
const fs = require('fs');
const http = require('http');
const https = require('https');
const express = require('express');
const app = express();
app.get('*', (req, res) => res.send('yehh'));
http.createServer(app).listen(80);
@davalapar
davalapar / es7-async-await.js
Created May 28, 2019 08:21 — forked from msmfsd/es7-async-await.js
Javascript fetch JSON with ES7 Async Await
// Async/Await requirements: Latest Chrome/FF browser or Babel: https://babeljs.io/docs/plugins/transform-async-to-generator/
// Fetch requirements: Latest Chrome/FF browser or Github fetch polyfill: https://github.com/github/fetch
// async function
async function fetchAsync () {
// await response of fetch call
let response = await fetch('https://api.github.com');
// only proceed once promise is resolved
let data = await response.json();
// only proceed once second promise is resolved
@davalapar
davalapar / index.js
Created April 20, 2019 01:55 — forked from xemasiv/index.js
Notifications
var n = new Notification('Connected', { body: 'Well done mate'} );
setTimeout(() => n.close(), 3000);
Notification.permission;
Notification.requestPermission().then(console.log).catch(console.error);
// https://developer.mozilla.org/en-US/docs/Web/API/notification

XADD streamname [MAXLEN items] * field value [field value ...]

Adds a set of fields with values to the specified stream. If MAXLEN items are exceeded, items are removed from the beginning of the stream to bring the length down to MAXLEN. The "*" field is to autogenerate an item ID, but can be overriden.

Return value

Simple string reply: epoch time (in milliseconds) followed by a .N (for differentiating multiple events on the same millisecond)

@davalapar
davalapar / script.js
Created March 29, 2019 23:38 — forked from Lewiscowles1986/script.js
Anonymous Upload images to Imgur V3 JS
var ImgurAPIKey = 'YEAH-IM-NOT-GIVING-THAT';
window.addEventListener('paste', function(e) {
function eventPreventDefault(e) {
e.preventDefault();
}
function getClipboardData(e) {
return window.clipboardData || e.clipboardData;
}
@davalapar
davalapar / webpack.config.js
Created March 22, 2019 18:04
sample webpack.config.js
/* eslint-disable camelcase */
const os = require('os');
const path = require('path');
const webpack = require('webpack');
const webpackNodeExternals = require('webpack-node-externals');
const TerserPlugin = require('terser-webpack-plugin');
const Client = (env, argv) => {
const { mode } = argv;
@davalapar
davalapar / sha256.js
Created March 22, 2019 00:46
sha256.js
const crypto = require('crypto');
const sha256 = s => crypto.createHash('sha256').update(s, 'utf8').digest('hex');
module.exports = { sha256 };