Node JS Socket.IO

//—————- HTTPS Server —————————————- var fs = require(‘fs’); var https = require(‘https’); var express = require(‘express’); var app = express(); var options = { key: fs.readFileSync(‘/etc/letsencrypt/live/hg-system.com/privkey.pem’), cert: fs.readFileSync(‘/etc/letsencrypt/live/hg-system.com/fullchain.pem’) }; var server = https.createServer(options, app); var port = 3000; server.listen(port, function() { log(‘listening on *:’ + port); }); app.use(express.static(‘public’)); app.get(‘/’, (req, res) => { res.sendFile(‘index.html’); }); Weiterlesen…

NodeJS DB Connection

//—————- SQL Server —————————————- var mysql = require(‘mysql’); var db = mysql.createConnection({ host : ‘localhost’, user : ‘dbuser’, password : ‘dbpass’, database: ‘dbname’ }); db.connect(); db.query(‘SELECT 1 + 1 AS solution‘, function(err, rows, fields) { if (err) throw err; console.log(‘The solution is: ‘, rows[0].solution); }); process.on(‘exit’, function (){ db.end(); console.log(‘Goodbye!’); });

NodeJS HTTP/HTTPS – Server (with Let’s Encrypt SSL Cert)

Basic HTTP-Server var fs = require(‘fs’); var http = require(‘http’); var express = require(‘express’); var app = express(); var server = http.createServer(app); var port = 3000; server.listen(port, function() { log(‘listening on *:’ + port); }); app.use(express.static(‘public’)); app.get(‘/’, (req, res) => { res.sendFile(‘index.html’); }); Extend your Server to HTTPS with Free SSL Cert var fs = Weiterlesen…

Usefull JavaScript’s & jQuery Code

#1 create a prototype function for e.g. a replaceAll function for strings: String.prototype.replaceAll = function(search, replacement) { var target = this; return target.replace(new RegExp(search, ‘g’), replacement); }; Useage: var test1, test2; var str = “aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa” test = str .replaceAll(“a”, “c”) “cccccccccccccccccccccccccccccc” //combineable test2 = str.replace(“a”, “b”) .replaceAll(“a”, “c”) “bccccccccccccccccccccccccccccc” jQuery Example: $(“body”).find(“div”).each(function() { $(this).setRandomColor(); }); Weiterlesen…

Usefull Python Scripts

Remove lines from File containing: bad_words import sysbad_words = [‘one bad word’,’ another bad word’]scriptname = sys.argv[0]for _old in sys.argv:if _old == scriptname:continue_new = _old + ‘_filter_x.log’print(“processing ‘” + _old + “‘\n\noutput: ” + _new + “\n\n\n\n”)with open(_old) as oldfile, open(_new, ‘w’) as newfile:for line in oldfile:if any(bad_word in line for bad_word in bad_words):newfile.write(line) Combine Weiterlesen…