Skip to content

Instantly share code, notes, and snippets.

View pjanuario's full-sized avatar

Pedro Januário pjanuario

View GitHub Profile
@pjanuario
pjanuario / index.js
Created August 21, 2020 11:06 — forked from amiantos/index.js
Zip Multiple Files from S3 using AWS Lambda Function
// Lambda S3 Zipper
// http://amiantos.net/zip-multiple-files-on-aws-s3/
//
// Accepts a bundle of data in the format...
// {
// "bucket": "your-bucket",
// "destination_key": "zips/test.zip",
// "files": [
// {
// "uri": "...", (options: S3 file key or URL)
@pjanuario
pjanuario / view_energy.yaml
Created August 14, 2020 12:53
Homeassistant Energy View
title: Energia
icon: mdi:transmission-tower
path: energy
background: var(--background-image)
cards:
- type: vertical-stack
cards:
- type: horizontal-stack
cards:
- type: entities
@pjanuario
pjanuario / sunset_automation.yaml
Created April 6, 2020 21:26
Homeassistant sunset automation
# 15m after the sunrise
# - Open the covers
# - Turn off ligths
- id: sunrise
alias: 'Sunrise automation'
trigger:
- platform: sun
event: sunrise
offset: '00:15:00'
action:
@pjanuario
pjanuario / Node.js HTTP Server
Created May 23, 2018 09:15
Simple HTTP server to output request url and post body
// content of index.js
const http = require('http')
const port = 3000
const requestHandler = (request, response) => {
console.log("URL: %s", request.url)
if (request.method === 'POST') {
let body = '';
request.on('data', chunk => {
body += chunk.toString(); // convert Buffer to string
@pjanuario
pjanuario / toCamelase.js
Created June 5, 2017 15:04
Module to do a deep conversion of a object into a camelCase
import _ from 'lodash';
export default function toCamelCase(obj) {
if (!_.isObject(obj)) { return obj; }
if (_.isArray(obj)) {
return obj.map(toCamelCase);
}
return _.reduce(obj, (memo, value, key) => {
@pjanuario
pjanuario / snippets.cson
Created February 25, 2016 15:30
Atom snippets
'.source.js':
'Describe':
'prefix': 'desc'
'body': 'describe(\'$1\', function () {\n\tit(\'$2\', function () {\n\t\t$3\n\t});\n});'
'Test':
'prefix': 'it'
'body': 'it(\'$1\', function () {\n\t$2\n});'
'Before Each':
'prefix': 'be'
'body': 'beforeEach(function () {\n\t$1\n});'
var Logger = require('logger-facade-nodejs');
var LoggerConsolePlugin = require('logger-facade-console-plugin-nodejs');
// this is the default config
var config = {
level: 'debug',
timeFormat: 'YYYY-MM-DD HH:mm:ss',
messageFormat: '%time | %logger::%level - %msg',
json: true
};
@pjanuario
pjanuario / Microservices Stuff
Last active December 18, 2015 10:20
This gist will contain a bunch of links and stuff related with microservices researches and some thoughts maybe
Sam Newman - Building Microservices
http://shop.oreilly.com/product/0636920033158.do
Sam Newman podcast with Beth Skurrie about:
- microservices
- vanila rails codebase issues on larger codebases
- contract driven tests vs system integration tests
- pact
http://samnewman.io/blog/2015/12/16/magpie-talkshow-episode-8-beth-skurrie/
@pjanuario
pjanuario / download_files.sh
Last active August 29, 2015 14:28
Bash script to download files from a comma separated source file.
mkdir -p /tmp/downloaded_files
while IFS='' read -r line || [[ -n "$line" ]]; do
#echo "Text read from file: $line"
filename=$(echo $line | cut -d "," -f 1)
url=$(echo $line | cut -d "," -f 2)
echo "url: $url filename: $filename"
curl $url -o "/tmp/downloaded_files/$filename"
done < "$1"
@pjanuario
pjanuario / UserAge.rb
Created November 4, 2014 14:49
This gist contains some info about calculating users age avoiding leap year issues.
class User
attr_reader :born_on
def age(today = Time.now.utc)
return nil unless self.born_on.present?
((today.to_time - self.born_on.to_time) / 1.year).to_i
end
end