Skip to content

Instantly share code, notes, and snippets.

View m00zi's full-sized avatar
🎯
Focusing

moss m00zi

🎯
Focusing
View GitHub Profile
@m00zi
m00zi / after_res_hooks.js
Created February 24, 2017 07:00 — forked from pasupulaphani/after_res_hooks.js
Mongoose connection best practices
var db = mongoose.connect('mongodb://localhost:27017/DB');
// In middleware
app.use(function (req, res, next) {
// action after response
var afterResponse = function() {
logger.info({req: req}, "End request");
// any other clean ups
@m00zi
m00zi / api.js
Created March 23, 2018 19:35 — forked from fwielstra/api.js
An example NodeJS / Mongoose / Express application based on their respective tutorials
/* The API controller
Exports 3 methods:
* post - Creates a new thread
* list - Returns a list of threads
* show - Displays a thread and its posts
*/
var Thread = require('../models/thread.js');
var Post = require('../models/post.js');
@m00zi
m00zi / encryption.js
Created May 29, 2018 11:37 — forked from vlucas/encryption.js
Stronger Encryption and Decryption in Node.js
'use strict';
const crypto = require('crypto');
const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY; // Must be 256 bytes (32 characters)
const IV_LENGTH = 16; // For AES, this is always 16
function encrypt(text) {
let iv = crypto.randomBytes(IV_LENGTH);
let cipher = crypto.createCipheriv('aes-256-cbc', new Buffer(ENCRYPTION_KEY), iv);
@m00zi
m00zi / cmd.js
Created May 31, 2018 06:57 — forked from miguelmota/cmd.js
Node.js run command in child process promise
const exec = require('child_process').exec;
const cmd = 'echo "hello"';
function echo() {
return new Promise((resolve, reject) => {
exec(cmd, (error, stdout, stderr) => {
if (error) return resolve(false);
if (stderr) return resolve(false);
resolve(true);
});
@m00zi
m00zi / 1-file.txt
Created May 31, 2018 12:08 — forked from cowboy/1-file.txt
Iterate over all lines in a file, handing extra trailing newlines
foo bar
baz
qux
last line (there may or may not be a trailing newline after this line)
exports.deleteUser = (req, res, next) => {
var response;
console.log(req.params.user_id);
if (!req.params.user_id) {
response = {success: false, message: 'user id must be provided'};
res.send(response);
return;
}
console.log(req.params.user_id);
package main
import (
"bytes"
"log"
"net/smtp"
)
func main() {
// Connect to the remote SMTP server.
@m00zi
m00zi / ssl_smtp_example.go
Created October 26, 2018 11:57 — forked from chrisgillis/ssl_smtp_example.go
Golang SSL SMTP Example
package main
import (
"fmt"
"log"
"net"
"net/mail"
"net/smtp"
"crypto/tls"
)
@m00zi
m00zi / sendMail.go
Created October 26, 2018 14:51 — forked from andelf/sendMail.go
golang send mail net/smtp SMTP
package main
import (
"log"
"net/mail"
"encoding/base64"
"net/smtp"
"fmt"
"strings"
@m00zi
m00zi / gist:e6f5220c9ded3635c5bff26927d89198
Created October 26, 2018 19:02
An example of a JSON Unmarshal into a Go struct.
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
type Artist struct {