Skip to content

Instantly share code, notes, and snippets.

@kenial
kenial / sync_async_db_access.py
Last active February 14, 2024 14:08
Access in-memory SQLite3 DB asychronously, using concurrent.futures.thread.ThreadPoolExecutor
#! /usr/bin/python3
# Access in-memory SQLite3 DB asychronously,
# using concurrent.futures.thread.ThreadPoolExecutor
import datetime
import sqlite3
import concurrent.futures
RECORD_COUNT = 50000
e = concurrent.futures.thread.ThreadPoolExecutor(max_workers=2)
@kenial
kenial / spatialite_spatial_index_test.sql
Last active August 29, 2015 14:11
Test Spatialite spatial index queries
-- Spatialite queries test (cached result, total records: 2,178,275)
.timer on
.header on
.separator \t
.mode list
-- Seems table scan - slowest
@kenial
kenial / geodjango_sample.py
Created January 3, 2015 08:28
GeoDjango sample code
import django
from django.contrib.gis.measure import D
from django.contrib.gis.geos import *
from django.contrib.gis import geos
pnt = geos.Point(-122.146, 37.458, srid=4326)
pnt.transform(900913) # in meter
area = geos.Polygon([
(pnt.x-1, pnt.y-1),
(pnt.x+1, pnt.y-1),
@kenial
kenial / csfbc_sqlalchemy.py
Last active July 23, 2023 18:10
Cheat Sheet For Busy Coders: SQLAlchemy #SQL #mysql
#! /usr/bin/python
# 02/27/2015, Kenial
# Just simple scripts for instant use of SQLAlchemy.
import sqlalchemy as sa
sa.__version__ # '0.9.4' for me
# Sample DB connection string
# engine = sa.create_engine('postgresql://scott:tiger@localhost/mydatabase')
openssl req -new -newkey rsa:2048 -nodes -keyout server.key -out server.csr
sudo yum install epel-release -y
sudo yum install net-tools wget python34 python34-devel python-pip readline java-1.8.0-openjdk -y
sudo pip install virtualenvwrapper pip -U
echo source /usr/bin/virtualenvwrapper.sh >> ~/.bash_profile
mkvirtualenv py3 -p python3
workon py3
sudo pip install ipython
@kenial
kenial / curl_post_req_w_querystring_cookie_header.php
Last active August 16, 2016 18:10
Mix and match POST request w/ setting querystring, cookie, and response header in PHP
<?php
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>
<?php
//
// A very simple PHP example that sends a HTTP POST to a remote site
//
@kenial
kenial / pdo_stored_procedure_call.php
Created August 16, 2016 07:41
PDO-based stored procedure call in PHP
<?php
// $db = new PDO($connection_string, $db_user, $db_password);
$plan_code = "PLAN_CODE";
$product_status = 200;
$page = 1;
$fetch = 20;
$qry = "CALL `db_billing`.`odp_cm_get_products`('$plan_code', $product_status, $page, $fetch, @total_row_count)";
$stm = $db->prepare($qry);
$stm->execute();
@kenial
kenial / make_random_wav_sound.py
Last active July 29, 2022 18:49
make 1 second length random wave sound (PCM) file.
import random
def get_wave_data():
s = "52494646" # RIFF
s += "88580100" # subchunks. 88,200 in hex, little-endian
s += "57415645" # "WAVE" chunk identifier
s += "666d7420" # "fmt " chunk identifier
s += "10000000" # length of chunk, 16
s += "0100" # format code (PCM)
s += "0200" # channel