Skip to content

Instantly share code, notes, and snippets.

@Igaryu
Igaryu / idSQLite3.proc.nim
Last active October 19, 2023 08:29
NIM procedure tha verify that the file opened is really an sqlite database.
# I needed this function because the `connect` function of the `sqlite3` python module DOES NOT,
# and I repeat DOES NOT, verify that the file passed as a parameter is really an sqlite3 database file!
# If you open grandma's soup recipe in recipe.txt the `connect` function will not raise an error!!!
# The only way I found to REALLY determine if a file is, or isn't, an sqlite3 dbase file, is the following method:
# IF the first 16 bytes match the string b'SQLite format 3\x00' then it REALLY is a sqlite3 file!!
@Igaryu
Igaryu / gist:e38945bc50887083397293af4ccc753b
Last active April 16, 2023 09:32
NIM - Sqlite3 Connect
'''
Having recently approached Nim's language, I'm bringing back some 'goodies' that I will surely need in the future.
The first is the `connect` function of the `std/db_sqlite` library
If you try to open a sqlite3 database file with:
var dbase = open("DBase/IChing.db")
you will have a lot of problems. For Nim the correct way to open a sqlite3 database file is:
@Igaryu
Igaryu / Bash - EseguiBackup
Last active April 16, 2023 09:20
Script per TIme Machine senza dischi collegati permanentemente
#!/bin/bash
#
# Disk volumes CONSTANTS sets
#
Disco01="/Volumes/1st Time Capsule/" # Mount point first device: adapt
Device01="4AB05D67-2513-4EAB-8AC0-C258A4FBE1E4" # UID for first device
Disco02="/Volumes/2nd Time Capsule/" # Mount point second device: adapt
from time import sleep
def countdown(t):
'''
Defines a countdown and prints always in the same position che counter
'''
while t:
mins, secs = divmod(t, 60)
timer = '{:02d}:{:02d}'.format(mins, secs)
print(timer, end="\r")
@Igaryu
Igaryu / Python - isSQLite3.py
Last active August 10, 2023 09:19
isSQLite3.py
def isSQLite3(filename: str) -> bool:
```
I needed this function because the `connect` function of the `sqlite3` python module DOES NOT,
and I repeat DOES NOT, verify that the file passed as a parameter is really an sqlite3 database file!
If you open grandma's soup recipe in recipe.txt the `connect` function will not raise an error!!!
The only way I found to REALLY determine if a file is, or isn't, an sqlite3 dbase file, is the following
method:
#!/usr/bin/env python3
# Why importing tons of functions, when I can import the only the 6 I need?
from sys import exit
from random import choice
from string import ascii_letters, digits, punctuation
#
# Using try - except trap to verify if input data is a number
@Igaryu
Igaryu / LiveCode attraversa struttura directory.
Last active May 26, 2020 09:23
Walks thru a dir and its subdirectories in Livecode Language.
function recurDir dir, ext
set the defaultFolder to dir
repeat for each line fi in the files
if fileExt(fi) = ext then
put the longfilepath of fi & cr after fileList
end if
end repeat
repeat for each line di in the folders
if di is not "." and di is not ".." then
put recurDir((dir & slash & di), ext) & cr after fileList
import sqlite3
try:
import pymysql
except:
print("Devi installare la libreria di MySQL.")
print("Esegui: pip install pymysql da terimale")
exit(-9)
print(f'Libreria SQLite3 e PyMySQL caricate!)
return()