Skip to content

Instantly share code, notes, and snippets.

View eduardoromero's full-sized avatar
λ + µ = 💯

Eduardo Romero eduardoromero

λ + µ = 💯
  • Standard Metrics
  • Washington, USA
  • X @foxteck
View GitHub Profile
@eduardoromero
eduardoromero / observer-proxy.js
Created January 19, 2019 00:55
A Proxy Object that peeks into your Objects.
const Observe = (AnObject, Label = '') => {
const name = Label || generateLabel(AnObject)
if (DISABLE_TRACING) {
return AnObject
}
return new Proxy(AnObject, {
get(target, prop) {
let label = ''
@eduardoromero
eduardoromero / handler.js
Created January 17, 2019 05:32
Lambda function with IOPipe
const iopipeLib = require('@iopipe/iopipe')
const tracePlugin = require('@iopipe/trace')
const iopipe = iopipeLib({
token: process.env.IOPIPE_TOKEN || '',
enabled: Boolean(process.env.IOPIPE_TOKEN),
plugins: [
tracePlugin({
autoHttp: true
})
@eduardoromero
eduardoromero / observer.js
Created January 17, 2019 05:24
observe-proxy
const Observe = (AnObject) => {
return new Proxy(AnObject, {
get (target, prop) {
const method = target[prop]
if (typeof method === 'function') {
console.log(`\`${method}\` was accessed`)
} else {

Keybase proof

I hereby claim:

  • I am eduardoromero on github.
  • I am eromero (https://keybase.io/eromero) on keybase.
  • I have a public key ASBnzepAboWcHgMb3dAUskLUKbaIaCBh_qipA1vMB4txpAo

To claim this, I am signing this object:

@eduardoromero
eduardoromero / handler-004.js
Created September 24, 2017 18:57
Serverless WebTask API - DELETE
server.delete('/:id', (req, res, next) => {
const id = req.params.id
req.db.table('shares').get(id).delete()
.then((response) => {
res.status(200).json({
response
})
})
.catch(error => res.status(500).send({error}))
@eduardoromero
eduardoromero / handler-003.js
Last active September 24, 2017 18:56
Serverless WebTask API - POST/PUT
server.post('/', (req, res) => {
let data = req.body
req.db.table('shares').insert(data, {returnChanges: true})
.then((response) => {
data = Array.isArray(req.body) ? response.changes.map(item => item.new_val) : response.changes[0].new_val
res.status(200).json({
data: data,
response
@eduardoromero
eduardoromero / handler-002.js
Last active July 22, 2019 00:52
Getting data from RethinkDB
server.get('/', (req, res, next) => {
let _offset = parseInt(req.query.offset) || 0
let _limit = parseInt(req.query.limit) || 10
// max per page
if (_limit > 100) {
_limit = 100
}
req.db.table('shares').filter({}).skip(_offset).limit(_limit)
@eduardoromero
eduardoromero / handler-001.js
Last active July 22, 2019 00:52
Setting up express and rethinkdb
const bodyParser = require('body-parser')
const express = require('express')
const Webtask = require('webtask-tools')
const server = express()
server.use(bodyParser.json())
server.use(bodyParser.urlencoded({extended: true}))
// pass RethinkDB around xD
@eduardoromero
eduardoromero / serverless-config-credentials.sh
Created September 24, 2017 06:11
Get a WebTask Account
serverless config credentials --provider webtasks
@eduardoromero
eduardoromero / deploy.sh
Created September 24, 2017 06:07
Deploying our first Function to WebTask.io
npm i
sls deploy