Skip to content

Instantly share code, notes, and snippets.

@chameleonbr
chameleonbr / flat_unflat.js
Created March 7, 2023 19:16
Flat and unflat obj
function flat(obj) {
var result = {};
for (var key in obj) {
if (typeof obj[key] == "object") {
var flatObj = flat(obj[key]);
for (var subkey in flatObj) {
result[key + "." + subkey] = flatObj[subkey];
}
} else {
result[key] = obj[key];
const http = require('http');
const RED = require("node-red");
const express = require("express");
const app = express();
const server = http.createServer(app);
const settings = require('./settings');
@chameleonbr
chameleonbr / nodered.express.js
Created May 17, 2021 20:15
NodeRED running on Express and Appmetrics Dash monitoring on other port
var dash = require('appmetrics-dash');
dash.monitor({port:4000});
const http = require('http');
const RED = require("node-red");
const express = require("express");
const app = express();
const server = http.createServer(app);
@chameleonbr
chameleonbr / nodered.polka.js
Created May 17, 2021 20:11
NodeRED running on Polka
const http = require('http')
const RED = require("node-red")
const polka = require('polka')
const server = http.createServer()
const app = polka({server})
const settings = require('./settings')
@chameleonbr
chameleonbr / list_gcp_iprange.sh
Created October 16, 2017 17:53 — forked from n0531m/list_gcp_iprange.sh
Google Cloud Platform : ip address range
#!/bin/bash
# https://cloud.google.com/compute/docs/faq#ipranges
#nslookup -q=TXT _cloud-netblocks.googleusercontent.com 8.8.8.8
for LINE in `dig txt _cloud-netblocks.googleusercontent.com +short | tr " " "\n" | grep include | cut -f 2 -d :`
do
dig txt $LINE +short
done | tr " " "\n" | grep ip4 | cut -f 2 -d : | sort -n
//index.js
const cote = require('cote')
const winston = require('winston')
const timeService = new cote.Responder({ name: 'Time Service' })
timeService.on('time', (req) => {
return new Promise((resolve, reject) => {
let date = new Date()
resolve(date)
@chameleonbr
chameleonbr / HashIterate.php
Created December 15, 2014 21:58
Get keys from zset or set then get hash data by key.
<?php
namespace MyApp\Lua;
/**
* Use with Predis
**/
class HashIterate extends \Predis\Command\ScriptCommand
{
public function getKeysCount()
{
@chameleonbr
chameleonbr / word_letter_pairs_redis.lua
Last active April 19, 2017 20:49
Redis Word Letter Pairs
local function compare(frase1, frase2)
local function letterPairs(word)
local numPairs = string.len(word)
local wPairs = {}
local cnt = 1
while cnt < numPairs do
local pedaco = string.sub(word,cnt,cnt+1)
table.insert(wPairs,pedaco)
cnt = cnt + 1
end
@chameleonbr
chameleonbr / word_letter_pairs.lua
Created November 14, 2014 18:40
WordLetterPairs
function compare(frase1, frase2)
function letterPairs(word)
numPairs = string.len(word)
wPairs = {}
cnt = 1
while cnt < numPairs do
pedaco = string.sub(word,cnt,cnt+1)
table.insert(wPairs,pedaco)
cnt = cnt + 1
end
POST /loja/v1.0/produtos HTTP/1.1
Content-Type: application/json
{
"nome" : "Guitarra Fender Stratocaster Preta",
"preco" : 8500.00
}
//------RESPOSTA-------
HTTP/1.1 201 Created