You can tell if mongoose is already connected or not by simply checking:
if(mongoose.connection.readyState){
}
0 = no
1 = yes
Handbrake it's an open-source video transcoder and a lifesaver! For people that don't have a lot of time for transcoding or don'...
fred.ns.cloudflare.com |
pola.ns.cloudflare.com |
npm install -g nativescriptThe requirements for a full build of an app are here:
https://docs.nativescript.org/angular/start/quick-setupThen we proceed to make a new app:
tns create HelloWorld --template tns-template-blank-ngAnd for last we try to see our magnificent app in the preview panel:
tns previewThis will throw a QR code that we can scan with our playground app and the app will just pop up in the phone. Well, that's for now, a little guide to make a new app in NativeScript/Angular. See you next time.
var worker = require('worker.js');
var request = require("request"); var cheerio = require("cheerio");
var url = "http://www.bumeran.com.ar/empleos-publicacion-hoy.html";
exports.start = function(req, res) { request(url, function() { return function(err, resp, body) { if (err && resp.statusCode == 200) { console.log(err); //throw err; } $ = cheerio.load(body); var pages = $(".paginador.box a:nth-last-child(2)").text().trim(); console.log(pages); scraper(pages); }; }); };
function scraper(pages) { for(var i = 0; i < pages ; i++){ var url = "http://www.bumeran.com.ar/empleos-publicacion-hoy-pagina-" + (i + 1) + ".html"; request(url, ( function(i) { return function(err, resp, body) { if (err && resp.statusCode == 200){ console.log(err); //throw err; } $ = cheerio.load(body); $(".aviso_box.aviso_listado").each(function(index, tr) { console.log("Scrapping..." + $(this).attr("href")); scraperLinks($(this).attr("href")); }); }; })(i)); } }
function scraperLinks(link) { var url = "http://www.bumeran.com.ar" + link; request(url, function(err, resp, body) { if (err && resp.statusCode == 200) { console.log(err); } //throw err; $ = cheerio.load(body); //console.log(body); var location = $('.aviso-resumen-datos tr td').last().text().trim(); // $('#.aviso-resumen-datos tr').last().find( "a" ).text(); var detail = $("#contenido_aviso p:nth-child(2)").text();//$("#contenido_aviso p").first().text(); var title = $(".box h2").first().text().trim(); var date = $(".aviso-resumen-datos tbody tr td").first().text().trim(); console.log("Saving..." + url); saveAd(url, location, detail, title, date); }); }
$ git push origin master # To https://github.com/user/repo.git # ! [rejected] master -> master (non-fast-forward) # error: failed to push some refs to 'https://github.com/user/repo.git' # To prevent you from losing history, non-fast-forward updates were rejected # Merge the remote changes (e.g. 'git pull') before pushing again. See the # 'Note about fast-forwards' section of 'git push --help' for details.This error can be a bit overwhelming at first, do not fear.
git push -f https//github.com/user/repo.git
to force the upload.>npm install express
>npm install jade
|
Now we have the pieces lest make the directory structure for this project, just add the directories "views" and "public" we will save the static things in public, like JavaScript and CSS files and jade views in views. Pretty obvious right...
var app = express();
app.configure(function(){
app.set('port', process.env.PORT || 3000); //set the port
app.set('views', __dirname + '/views'); //set views dir
app.set('view engine', 'jade'); // set the template engine
app.use(express.favicon()); //set the favicon
app.use(express.static(path.join(__dirname, 'public'))); //set the public dir for static content
});
app.get('/', function(req, res){
res.render('index.jade', {title: 'Jade Example'}); //sends title to the template and renders it
});
app.listen(3000);
|
!!! 5
html
head
title= title
link(rel='stylesheet', href='/css/bootstrap.css')
link(rel='stylesheet', href='/css/bootstrap-responsive.min.css')
body
header.site-header
a.logo(href='/', title='Express, Jade and Stylus') Express, Jade and Stylus
nav.site-nav
ul.nav
li.current
a(href='/', title='Home') Home
block content
p
| Created by
a(href='http://http://grimaldigerardo.blogspot.com.ar/') Gerardo Grimaldi
|
extends layout
block content
h1 = title
p Welcome to #{title}
|
node app.js
|
var nodemailer = require("nodemailer");
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: "me@gmail.com",
pass: "pass"
}
});
var mailOptions = {
from: "Server <me@gmail.com>", // sender address
to: "me@gmail.com", // list of receivers
subject: "", // Subject line
text: "", // plaintext body
html: "" // html body
};
exports.mailOptions = mailOptions;
exports.sendMail = function () {
smtpTransport.sendMail(mailOptions, function(error, response){
if(error){
console.log(error);
}else{
console.log("Message sent: " + response.message);
}
/* if you don't want to use this transport object anymore, uncomment following line
//smtpTransport.close(); // shut down the connection pool, no more messages*/
});
};
var express = require('express');var mail = require("./nodemail");var app = express();
app.use(express.logger());
app.get('/mail/:name/:subject/:text/:securitytoken', function(req, res) {
if (req.params.securitytoken != 'Salt742!') return res.send('Error: Wrong password...'); try { newMail(req.params.name,req.params.subject, req.params.text); } catch(err) { onError(err); }});
app.listen(process.env.PORT);
function newMail(name, subject, text) { mail.mailOptions.subject = 'Message from User: ' + name + ' with Subject : ' + subject; mail.mailOptions.text = text; mail.sendMail();}
function onError(err) { console.log(err);}
console.log('Server HTTP Listening on port ' + process.env.PORT + '...');