Skip to content

Instantly share code, notes, and snippets.

View Razzo78's full-sized avatar

Rudy Azzan Razzo78

View GitHub Profile
@Razzo78
Razzo78 / UseDbImport.py
Last active January 26, 2018 09:30
Python, Sqlite - Import data from CSV with DbImport class
import pandas as pd
df_data = pd.read_csv("fileName.csv", sep='\t')
# DbImport: https://gist.github.com/Razzo78/3580cf9ed1f3c9a34484ab887b6dbf5d
db = DbImport("myDb.sqlite")
data_ins = {"filed_id": -1,
"filed_name": ""
}
@Razzo78
Razzo78 / DBImport.py
Last active January 26, 2018 09:29
Python, Sqlite - Import database and mapping tables to class and execute a query to populate mapped class
from sqlalchemy import create_engine, MetaData, Table
from sqlalchemy.orm import mapper, sessionmaker
from sqlalchemy.sql import select
class Table1Name(object):
pass
class Table2Name(object):
@Razzo78
Razzo78 / CycleListView.qml
Last active November 26, 2018 17:46
QML - Cycle listview elements, for read or modify
//Listview id: listView
for (var i = 0; i <= listView.model.count; i++){
var elemCur = listView.model.get(i);
//Reading
console.log(elemCur.name);
//Editing
elemCur.name = "pippo";
@Razzo78
Razzo78 / ThreadUISwitch.cpp
Last active January 26, 2018 09:32
QT - Execute a function from a task thread in the main thread context. This is useful to update UI, without cross thread errors.
void ThreadToolUI::PostToMainThread(const std::function<void()> & fun)
{
QObject signalSource;
QObject::connect(&signalSource, &QObject::destroyed, qApp, [=](QObject*){
fun();
});
}
Task::run<void>([=]() {
qDebug() << "Current therad is task thread";
@Razzo78
Razzo78 / RxCppCallOnNext.cpp
Last active February 8, 2018 07:47
C++, ReactiveX - How to call on_next from a declared observable
rxcpp::subjects::subject<int> sub;
auto o = sub.get_subscriber();
auto source = sub.get_observable();
source.subscribe(
[](int v) {printf("OnNext: %d\n", v); },
[]() {printf("OnCompleted\n"); });
o.on_next(1);
o.on_next(2);
@Razzo78
Razzo78 / RnadomWalk.py
Last active January 26, 2018 09:31
Python - A random walk is a mathematical object, known as a stochastic or random process, that describes a path that consists of a succession of random steps on some mathematical space such as the integers. (Wikipedia)
import numpy as np
np.random.seed(123)
tails = [0]
for x in range(10) :
coin = np.random.randint(0,2)
tails.append(tails[x] + coin)
print(tails)
@Razzo78
Razzo78 / stop_zerop.py
Last active January 26, 2018 09:33
Python - Stop a number before it goes under zero
step = max(0, step - 1)
@Razzo78
Razzo78 / SendEmail.py
Last active November 1, 2017 18:21
Python - Send email
import smtplib
sender = 'im@here.it'
receivers = ['reciver@mandi.it']
message = """Ciao"""
smtpObj = smtplib.SMTP('smtp.gmail.com:587')
smtpObj.ehlo()
smtpObj.starttls()
@Razzo78
Razzo78 / SqlAlchemyGet.py
Last active January 14, 2023 12:06
Python, SQL Server - Connect and get data with SqlAlchemy
from sqlalchemy import create_engine, MetaData, Table
from sqlalchemy.orm import mapper
from sqlalchemy.sql import select
class MyTable(object):
pass
# Trusted Connection
@Razzo78
Razzo78 / StringOfListNumbersCommaSeparated.py
Created October 20, 2017 14:57
Python - Create a string of list numbers separated with comma
myList = range(1, 50)
concatValues = ','.join(map(str, myList))