Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ThinkCode
ThinkCode / search.py
Created August 1, 2011 21:26 — forked from GaretJax/search.py
Search for Keyword in Text File and return line number
import os, sys
import re, MySQLdb
db = MySQLdb.connect("localhost","testuser","test123","TESTDB" )
#
# MySQL Code
# CREATE TABLE keyword (keywordid integer primary key auto_increment, keyword VARCHAR(255) NOT NULL);
#
# CREATE TABLE location (companyid integer, pdfid integer, keywordid integer references keyword(keywordid),
@ThinkCode
ThinkCode / PythonistaBackup.py
Created February 7, 2016 16:46 — forked from omz/PythonistaBackup.py
PythonistaBackup.py
# coding: utf-8
'''Creates a zip archive of your Pythonista files and serves them via HTTP in your local network.'''
from SimpleHTTPServer import SimpleHTTPRequestHandler
import os
import shutil
import tempfile
import shutil
PORT = 8080
import sys
import clr
sys.path.append(r'C:\Program Files (x86)\PIPC\AF\PublicAssemblies\4.0')
clr.AddReference('OSIsoft.AFSDK')
from OSIsoft.AF import *
from OSIsoft.AF.PI import *
from OSIsoft.AF.Asset import *
from OSIsoft.AF.Data import *
# https://hakibenita.com/fast-load-data-python-postgresql
from typing import Iterator, Dict, Any, Optional
from urllib.parse import urlencode
import datetime
#------------------------ Profile
import time
@ThinkCode
ThinkCode / bulk-insert.py
Created February 21, 2022 07:22 — forked from ellisvalentiner/bulk-insert.py
Recipe for (fast) bulk insert from python Pandas DataFrame to Postgres database
#!/usr/bin/env/python
import psycopg2
import os
from io import StringIO
import pandas as pd
# Get a database connection
dsn = os.environ.get('DB_DSN') # Use ENV vars: keep it secret, keep it safe
conn = psycopg2.connect(dsn)