Skip to content

Instantly share code, notes, and snippets.

View jkyberneees's full-sized avatar
😎
up and running

Rolando Santamaria Maso jkyberneees

😎
up and running
View GitHub Profile
const http = require('http')
const app = new http.Server()
app.on('request', (req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' })
res.write('Hello World')
res.end()
})
app.listen(3000)
const service = require('restana')({})
service.get('/hi', (req, res) => {
res.send('Hello World!')
})
service.start()
const express = require('express')
const app = express()
app.get('/hi', (req, res) => {
res.send('Hello World!')
})
app.listen(3000)
const N = 2000000
const items = []
for (var i = 0; i < N; i++) {
items.push({ index: i })
}
console.log(items.map(e => e.index).filter(v => v % 2 === 0).reduce((sum, v) => sum += v))
const express = require('express')
const bodyParser = require('body-parser')
const axios = require('axios')
const httpc = axios.create({
baseURL: 'http://localhost:3000',
timeout: 30000
})
const app = express()
const server = require('express')({})
server.get('/', (req, res) => {
res.send('Hello World!')
})
server.listen(3000)
(async () => {
const Client = require('hazelcast-client').Client
const hz = await Client.newHazelcastClient()
const list = hz.getList('my-distributed-list')
await list.add(process.pid)
console.log(await list.toArray())
await hz.shutdown()
})()
// on application instance start...
const counter = hazelcast.getAtomicLong('distributed-pushes-counter')
await counter.compareAndSet(0, await PushLogs.count({}))
// on push...
await counter.incrementAndGet()
// on request
await counter.get()
const lock = hazelcast.getLock('my-distributed-lock')
lock.lock().then(() => {
// the execution of this function will happen once
// at a time across all distributed instances
// ...
console.log('Happy Locking!')
}).finally(() => lock.unlock())
// on application instance start, init near cache Map
const {Client, Config} = require('hazelcast-client')
const nearCachedMapName = 'my-holy-fast-map'
const cfg = new Config.NearCacheConfig()
cfg.name = nearCachedMapName
cfg.invalidateOnChange = true
cfg.nearCacheConfigs[nearCachedMapName] = cfg
const hazelcast = await Client.newHazelcastClient(cfg)