Skip to content

Instantly share code, notes, and snippets.

View felipekm's full-sized avatar
🦈

Felipe Kautzmann felipekm

🦈
View GitHub Profile
@felipekm
felipekm / validaCnpj.js
Created November 24, 2015 18:47
Valida CNPJ
function validarCNPJ(cnpj) {
cnpj = cnpj.replace(/[^\d]+/g, '');
if (cnpj === '') {
return false;
}
if (cnpj.length !== 14) {
return false;
}
@felipekm
felipekm / validaCpf.js
Created November 24, 2015 18:50
validaCpf
function VerificaCPF(strCpf) {
if (!strCpf || strCpf === '') {
return false;
}
var soma = 0,
resto;
for (i = 1; i <= 9; i += 1) {
@felipekm
felipekm / uploadForm.js
Created December 8, 2015 12:35
Angularjs $http post file and form data
$http({
method: 'POST',
url: '/upload-file',
headers: {
'Content-Type': 'multipart/form-data'
},
data: {
email: Utils.getUserInfo().email,
token: Utils.getUserInfo().token,
upload: $scope.file
@felipekm
felipekm / file.directive.js
Created December 8, 2015 12:37
AngularJS file upload directive
angular.module('').directive('file', function () {
return {
scope: {
file: '='
},
link: function (scope, el, attrs) {
el.bind('change', function (event) {
var file = event.target.files[0];
scope.file = file ? file : undefined;
scope.$apply();
@felipekm
felipekm / server.js
Created March 1, 2016 03:39
Pub/sub with Redis [Node.js and node_redis]
var http = require('http');
var url = require('url');
var redis_lib = require("redis");
http.createServer(function (req, res) {
var query = url.parse(req.url, true).query;
var redis1 = redis_lib.createClient();
var redis2 = redis_lib.createClient();
res.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'});
@felipekm
felipekm / redisBasic.md
Last active March 1, 2016 11:09
Redis basic commands

LRANGE - Retrieve all items from a list

  • 0 - First item
  • -1 - Last item
LRANGE KEYNAME 0 -1

KEYS - All Keys

@felipekm
felipekm / redispubsub.js
Created March 27, 2016 13:49
node.js redis pubsub sample
var redis = require("redis")
, subscriber = redis.createClient()
, publisher = redis.createClient();
subscriber.on("message", function(channel, message) {
console.log("Message '" + message + "' on channel '" + channel + "' arrived!")
});
subscriber.subscribe("test");
@felipekm
felipekm / thoughts.md
Created May 17, 2016 14:24 — forked from floatdrop/thoughts.md
Error management in gulp

#Error management in gulp

Sucking at something is the first step to becoming sorta good at something

No one can assure you, that plugins will run smooth in any circumstances (except for tests - they could), so neither should you convince anyone, that your plugin will never break. Only thing, that you could possibly do (if something gone wrong) - is gracefully inform your plugin user, that something went wrong and die.

We are will use this plugin from beginning to demonstrate error management. Suppose you have a task in gulpfile.js that contains this code (we modified it a little bit to be closer to real-usage):

var coffee = require('gulp-coffee');
@felipekm
felipekm / codedeploy-restart.sh
Created July 21, 2017 16:38
CodeDeploy restarter
# Stop the code deploy agent
sudo service codedeploy-agent stop
#clear all deployments under
cd /opt/codedeploy-agent/deployment-root
sudo rm -rf *
# Restart the code deploy agent
sudo service codedeploy-agent start
@felipekm
felipekm / s3-policy.js
Last active January 25, 2018 22:09
Amazon S3 bucket policy sample to put code in
{
"Id": "Policy1516917873883",
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1516917869302",
"Action": [
"s3:PutObject"
],
"Effect": "Allow",