Skip to content

Instantly share code, notes, and snippets.

View matiaslopezd's full-sized avatar
🛰️
matiaslopezd[at]404.city

Matías López matiaslopezd

🛰️
matiaslopezd[at]404.city
View GitHub Profile
@mhawksey
mhawksey / gist:1442370
Last active February 25, 2024 12:01
Google Apps Script to read JSON and write to sheet
function getJSON(aUrl,sheetname) {
//var sheetname = "test";
//var aUrl = "http://pipes.yahoo.com/pipes/pipe.run?_id=286bbb1d8d30f65b54173b3b752fa4d9&_render=json";
var response = UrlFetchApp.fetch(aUrl); // get feed
var dataAll = JSON.parse(response.getContentText()); //
var data = dataAll.value.items;
for (i in data){
data[i].pubDate = new Date(data[i].pubDate);
data[i].start = data[i].pubDate;
}
@sabarasaba
sabarasaba / gist:3080590
Created July 10, 2012 02:19
Remove directory from remote repository after adding them to .gitignore
git rm -r --cached node_modules
git commit -m 'Remove the now ignored directory node_modules'
git push origin master
var cluster = require('cluster');
var PORT = +process.env.PORT || 1337;
if (cluster.isMaster) {
// In real life, you'd probably use more than just 2 workers,
// and perhaps not put the master and worker in the same file.
cluster.fork();
cluster.fork();
cluster.on('disconnect', function(worker) {
@jedi4ever
jedi4ever / nodejs-cluster-zero-downtime.md
Last active June 29, 2024 16:00
nodejs clustering, zero downtime deployment solutions

Clustering: The basics

The trick? pass the file descriptor from a parent process and have the server.listen reuse that descriptor. So multiprocess in their own memory space (but with ENV shared usually)

It does not balance, it leaves it to the kernel.

In the last nodejs > 0.8 there is a cluster module (functional although marked experimental)

@sstur
sstur / dom-to-json.js
Last active October 8, 2023 04:17
Stringify DOM nodes using JSON (and revive again)
function toJSON(node) {
let propFix = { for: 'htmlFor', class: 'className' };
let specialGetters = {
style: (node) => node.style.cssText,
};
let attrDefaultValues = { style: '' };
let obj = {
nodeType: node.nodeType,
};
if (node.tagName) {
function mae(a, b) {
return a["charAt"](b);
}
function bfQh(a, b) {
return a["charCodeAt"](b);
}
@kkkrist
kkkrist / app.js
Last active February 26, 2019 00:26
Rate limiting for FeathersJS HTTP (REST API) and Web Sockets connections (Express, Node.js)
'use strict'
const bodyParser = require('body-parser')
const compress = require('compression')
const configuration = require('feathers-configuration')
const cors = require('cors')
const favicon = require('serve-favicon')
const feathers = require('feathers')
const hooks = require('feathers-hooks')
const limiter = require('limiter').RateLimiter // Generic limiter used for authentication attempts inside web socket connection
@chris-garrett
chris-garrett / gist:8b9831ca2e2c05eacaa16b75f15213bf
Created December 13, 2017 00:40
initial nginx config for feathers.js
upstream app_server {
ip_hash;
server app_react:3000 max_fails=3 fail_timeout=30s;
}
upstream api_server {
ip_hash;
server api_feathers:3040 max_fails=3 fail_timeout=30s;
}
@voluntas
voluntas / webrtc_quic.js
Last active September 17, 2022 22:46
RTCQuicTransport の動作サンプル
// Chrome Canary M74
// chrome://flags で Experimental Web Platform features を有効にすれば使えるようになる
// mDNS を有効にしていると上手く動かないかもしれないので要注意
// https://developers.google.com/web/updates/2019/01/rtcquictransport-api
// https://github.com/shampson/RTCQuicTransport-Origin-Trial-Documentation
const iceTransport1 = new RTCIceTransport;
const iceTransport2 = new RTCIceTransport;
@matiaslopezd
matiaslopezd / get-fqdn.js
Last active December 1, 2020 19:09
Get FQDN with Regex
/**
* Get FQDN from a string
* @name FQDN
* @param URL {String} - String you want get FQDN
* @return {String}
**/
function FQDN(URL = '') {
URL = URL.subtring(0, 50); // This will avoid evaluate long malicious fqdn
const regex = /[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9](?:\.[a-zA-Z]{2,})+/i;
const filtered = regex.exec(URL);