Skip to content

Instantly share code, notes, and snippets.

🐙
PLING

felipekm felipekm

🐙
PLING
Block or report user

Report or block felipekm

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View validaCnpj.js
function validarCNPJ(cnpj) {
cnpj = cnpj.replace(/[^\d]+/g, '');
if (cnpj === '') {
return false;
}
if (cnpj.length !== 14) {
return false;
}
View validaCpf.js
function VerificaCPF(strCpf) {
if (!strCpf || strCpf === '') {
return false;
}
var soma = 0,
resto;
for (i = 1; i <= 9; i += 1) {
@felipekm
felipekm / uploadForm.js
Created Dec 8, 2015
Angularjs $http post file and form data
View uploadForm.js
$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 Dec 8, 2015
AngularJS file upload directive
View file.directive.js
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 Mar 1, 2016
Pub/sub with Redis [Node.js and node_redis]
View server.js
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 Mar 1, 2016
Redis basic commands
View redisBasic.md

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 Mar 27, 2016
node.js redis pubsub sample
View redispubsub.js
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 — forked from floatdrop/thoughts.md
Error management in gulp
View thoughts.md

#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 / AppSpec.yml
Last active Nov 3, 2016 — forked from makeittotop/gist:1394226fec1c9c27fb72f728e92a6870
AWS CodeDeploy Sample appspec.yml
View AppSpec.yml
version: 0.0
os: linux
files:
- source: /index.html
destination: /var/www/html/
hooks:
BeforeInstall:
- location: scripts/install_dependencies
timeout: 300
runas: root
View codedeploy-restart.sh
# 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
You can’t perform that action at this time.