Skip to content

Instantly share code, notes, and snippets.

Avatar
🧑‍🚀

Martin Gaido martingaido

🧑‍🚀
View GitHub Profile
@martingaido
martingaido / colorDetectionCam.py
Created Aug 29, 2020
Color Detection/Filter using OpenCV and Webcam
View colorDetectionCam.py
# Color Detection/Filter using OpenCV and Webcam
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
while True:
_, frame = cap.read()
hsv_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
@martingaido
martingaido / covidPredictor.py
Created Aug 25, 2020
COVID-19 Predictor - Polynomial Regression
View covidPredictor.py
# COVID-19 cases predictor (polynomial regression for non-linear prediction)
# Data Source: https://ourworldindata.org/coronavirus-source-data
# Data Example
# id,cases
# 1,1
# 2,4
# 3,6
# 4,8
# 5,10
@martingaido
martingaido / house-prices.py
Created Aug 25, 2020
Predict House prices using linear regression
View house-prices.py
## Predict House prices using linear regression
## Dataset: https://www.kaggle.com/rubenssjr/brasilian-houses-to-rent
import pandas as pd
from sklearn import preprocessing, linear_model
import numpy as np
import sklearn
### Loading Data ###
print('-' * 30); print(' Importing Data ...'); print('-' * 30)
@martingaido
martingaido / encrypt-decrypt.sh
Last active Aug 14, 2020
Bash script to encrypt and decrypt files using 'openssl'
View encrypt-decrypt.sh
# Install it in .bashrc file
function encrypt(){
which openssl &> /dev/null
[ $? -ne 0 ] && echo "OPENSSL is not installed." && return 1
openssl enc -aes-256-cbc -salt -in $1 -out $2
}
function decrypt(){
@martingaido
martingaido / spreadOperator.js
Created Aug 7, 2020
Spread Operator in JavaScript
View spreadOperator.js
/* Spread Operator */
// Case 1
const temperatures = [25, 22, 10, 34, 28, 15];
console.log('Min Value: ', Math.min(...temperatures));
console.log('Max Value: ', Math.max(...temperatures));
// Case 2
const someNumbers = ['First Name', 'Last Name', 'Age', 'Gender'];
const [first, ...tail] = someNumbers;
@martingaido
martingaido / flattenArray.js
Created Aug 6, 2020
Flatten a two-dimensional and multi-dimensional array
View flattenArray.js
/* Flatter Arrays */
'use strict';
// Case 1 (two-dimensional array)
let array1 = [1, 2, [4, 5, 6], 8, [9, 10], 11];
let newArray1 = array1.flat();
console.log(newArray1);
@martingaido
martingaido / substrings.ts
Created Aug 1, 2020
Checking if String contains Substring
View substrings.ts
/* Checking if String contains Substring */
const word = 'sunny day in manhattan';
/* Old Way */
word.indexOf('sun') !== -1; // true
/* 🚀 ES6 Way */
word.includes('sun'); // true
@martingaido
martingaido / reversearr.ts
Created Aug 1, 2020
Different approaches to reverse an array
View reversearr.ts
/* Case #1 - Notice that this example also mutates the original array. */
console.time('Test 1');
const arrayOne = [1, 2, 3, 4];
const newArrayOne = arrayOne.reverse();
console.log(arrayOne); // [ 4, 3, 2, 1 ]
console.log(newArrayOne); // [ 4, 3, 2, 1 ]
console.timeEnd('Test 1');
@martingaido
martingaido / rmduparr.ts
Created Jul 30, 2020
Remove duplicate values from an iterable object using Set()
View rmduparr.ts
/* Remove duplicate values from an iterable object using Set()
x.add()
x.delete()
x.has()
x.clear()
x.size()
*/
const set_one = new Set()
@martingaido
martingaido / fibonacci.ts
Last active Jul 30, 2020
Function to create a Fibonacci sequence
View fibonacci.ts
/* Fibonacci Sequence */
const fibonacci = (result: number[], len: number) => {
let n1: number = result[0],
n2: number = result[1],
next: number,
cnt: number = 2;
while (cnt < len) {
next = n1 + n2;
You can’t perform that action at this time.