Skip to content

Instantly share code, notes, and snippets.

View ivanleoncz's full-sized avatar
🔭
I'm not here.

ivanleoncz ivanleoncz

🔭
I'm not here.
View GitHub Profile
@ivanleoncz
ivanleoncz / rollback_files_from_commit_to_another.sh
Last active July 22, 2020 00:17
Rollback all files from a commit to another.
#!/bin/bash
COMMIT="d92b4247d671bc55723747a00314344a46e848e1"
COMMIT_ROLLBACK="807a95993b80db239bd1c24d3fbeb4bb265430be"
echo "[INFO]: listing files from commit $COMMIT and rolling back to $COMMIT_ROLLBACK, in 5 seconds"
sleep 5
for file in `git show --pretty="" --name-only $COMMIT` ; do
echo " * $file"
git checkout $COMMIT_ROLLBACK $file
@ivanleoncz
ivanleoncz / osnetwork.py
Created August 11, 2019 02:28
Obtains network data from GNU/Linux Operating Systems.
""" Functions for obtaining network information from a system. """
import subprocess as sp
__version__ = "v1.0"
__author__ = "@ivanleoncz"
def get_nic_ipv4(nic):
"""
@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 = [
@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_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 / 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 / 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 / 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 / flask_dynamic_form.py
Last active April 6, 2019 16:02
Obtaining all data (keys/values) from POST request (form) in Python Flask.
#!/usr/bin/python3
""" Obtaining all form fields (dynamically) from a POST request.
$ curl http://127.0.0.1:8000/post -d "name=Nemo&country=Norway"
$ curl http://127.0.0.1:8000/data -d "company=Axos Inc.&business=IT Outsourcing"
"""
from flask import abort, Flask, jsonify, request
__author__ = "@ivanleoncz"
@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")