Skip to content

Instantly share code, notes, and snippets.

View ivanleoncz's full-sized avatar
🔬
Bjarne Stroustrup is someone to admire.

ivanleoncz ivanleoncz

🔬
Bjarne Stroustrup is someone to admire.
View GitHub Profile
@ivanleoncz
ivanleoncz / MongoDB Reference
Last active October 13, 2017 05:25
CRUD and general administration of MongoDB databases.
### Create, Read, Update and Delete
# SHOW DATABASES
> show databases
> show dbs
# DEFINE DATABASE FOR OPERATIONS
> use database_name
# CREATE DATABASE AND COLLECTIONS
@ivanleoncz
ivanleoncz / mongo_client.py
Last active March 10, 2018 14:25
Demonstration of PyMongo usage (MongoDB 3.4.3 + PyMongo 3.4.0).
#!/usr/bin/python3
""" Demonstration of PyMongo usage. """
from bson.objectid import ObjectId
from datetime import datetime
from pymongo import MongoClient
__author__ = "@ivanleoncz"
@ivanleoncz
ivanleoncz / pass_hash_validator.py
Last active March 12, 2018 02:49
Determining validation of password, against password hash.
#!/usr/bin/python3
""" Determining validation of a password, against its hash. """
import bcrypt
from getpass import getpass
# simulation of hashed password stored in a DBMS (MongoDB, MySQL, SQLite, etc.)
salt = bcrypt.gensalt()
db_password = "Guido*Py2017".encode('utf-8')
db_pass_hash = bcrypt.hashpw(db_password,salt)
@ivanleoncz
ivanleoncz / sqlite_query_as_json.py
Created May 29, 2018 20:33
Demonstrating SQLite3 query with data returned as JSON Array.
""" Demonstrating SQLite3 query with data returned as JSON Array. """
from json import dumps
__author__ = "@ivanleoncz"
import sqlite3
def data_as_json():
db = sqlite3.connect("app_db.sqlite3")
@ivanleoncz
ivanleoncz / youtube2mp3.py
Last active November 25, 2018 15:24 — forked from benzap/youtube2mp3.py
Youtube to MP3 Downloader Script
#!/usr/bin/python3
#
# Requires: youtube_dl module
# Requires: ffmpeg
# Usage:
#
# python youtube2mp3.py <URL>, ...
#
# Example:
#
@ivanleoncz
ivanleoncz / createdb.js
Last active March 26, 2019 01:24 — forked from loic-moriame/index.js
Building SQLite models with Sequelize.js.
const Sequelize = require('sequelize');
var sequelize = new Sequelize({
dialect:"sqlite",
storage:"./db.sqlite",
});
// DB Connection
sequelize.authenticate().then(
function (err) {console.log("Connection established!");},
function (err) {console.log("Unable to connect!", err);}
@ivanleoncz
ivanleoncz / calculation.py
Last active March 26, 2019 13:11
Example of Unit Testing.
import time
class Calc:
""" Arithmetic Operations for two numbers, per function. """
def add(self, n1, n2):
""" Performs addition of two numbers. """
time.sleep(5) # intentional sleep for measuring time consumed
return n1 + n2
@ivanleoncz
ivanleoncz / app_express.js
Last active March 26, 2019 13:40
Simple Express.js Application
var express = require('express');
var port = 3000;
var app = express();
app.get('/', function(req, res) {
res.send('<h1>Welcome! </h1>');
});
app.get('/username/:user_name', function(req, res) {
@ivanleoncz
ivanleoncz / app_express_template.js
Created March 26, 2019 13:57
Simple Express.js app, using Template Engine (EJS).
var express = require('express');
var path = require('path');
var port = 3000;
var app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.get('/', function(req, res) {
res.render('index', {username: 'ivanleoncz'});
@ivanleoncz
ivanleoncz / app.js
Created April 4, 2019 22:23
Simple Express.js app, following REST Architecture, with tests included (Jest + Supertest).
const express = require('express');
const bodyParser = require('body-parser');
var app = express();
var router = express.Router();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
var tasks = [