Skip to content

Instantly share code, notes, and snippets.

Avatar

Alan Hoffmeister alanhoff

View GitHub Profile
@alanhoff
alanhoff / db.js
Created Nov 19, 2014
Rodar apenas uma vez
View db.js
var rodando = false;
var minhaFunc = function(){
if(rodando)
return; // Já está rodando
rodando = true;
db.query('select 1 + 1 as result', function(err, result){
rodando = false;
if(err)
View sockets.js
// no arquivo1.js
process.on('excluir', function(socket){
array_de_sockets.splice(socket.....);
});
// no arquivo2.js
if(tem_alguma_coisa_errada)
process.emit('excluir', socket);
View schema.js
var SiteSchema = new Mongoose.Schema({
site: String,
newLink: {
tipe: String,
index: {
unique: true
}
}
});
View protype.js
// Biblioteca responsável pela conexão no banco de dados
var level = require('levelup');
var config = require(__dirname + '/config');
var db = level(config.get('connection'));
var conns = {
_db: db // Para acesso direto ao LevelDB
};
View flooder.js
// jshint node: true, strict: false
var tls = require('tls');
// Configurações do servidor
var config = {
host: '****',
port: 8080
};
// Dispara se o servidor não conectar em 5 segundos
View gist:2d6283b192b953860637
/*!
* Node.JS module "Deep Extend"
* @description Recursive object extending.
* @author Viacheslav Lotsmanov (unclechu) <lotsmanov89@gmail.com>
* @license MIT
*
* The MIT License (MIT)
*
* Copyright (c) 2013 Viacheslav Lotsmanov
*
View getUrl.js
var util = require('util');
module.exports = function getUrl(bucket, object, insegure){
return util.format('%s://%s.s3.amazonaws.com/%s', insecure? 'http' : 'https', bucket, object);
}
View index.js
// Load all files inside this folder with a single require
var fs = require('fs');
var str = require('underscore.string');
var files = fs.readdirSync(__dirname);
module.exports = {};
// Iterate over the files that we found, replace the name
// require the file and exports it
files = files.forEach(function(file){
@alanhoff
alanhoff / app.js
Created Oct 14, 2014
Proxy de arquivos do S3
View app.js
var express = require('express');
var app = expres();
var knox = require('knox');
// Criamos um cliente para conectar no S3
var s3 = knox.createClient({
key: 'di32jdouh329dhu2jdjed=='
secret: 'dihuhdi2u3hdu3d9h23udh9382hd93='
bucket: 'ILoveYourNastyBucket'
});
View gist:e39eb0ce07293fc5d083
$scope.form = $location.search().form;
console.log($scope.form);