Skip to content

Instantly share code, notes, and snippets.

View gihankarunarathne's full-sized avatar
💭
Working Smarter

Gihan Karunarathne gihankarunarathne

💭
Working Smarter
View GitHub Profile
@gihankarunarathne
gihankarunarathne / complex_query_example.py
Last active February 28, 2023 12:44
Query Spanner data using SQLAlchemy Dialect in plain format.
# You can pass `execution_options` such as https://github.com/googleapis/python-spanner-sqlalchemy#stale-reads.
# You don't need to set them while creating the Spanner db instance.
def foo():
with engines.get_engine('purchase').execution_options(read_only=True).connect() as conn:
reseller_thresholds = zsql(
conn,
'''
SELECT
p.ref_type,
@gihankarunarathne
gihankarunarathne / reseller_purchase_breach.sql
Last active July 18, 2022 19:07
Check for reseller threshold breach on Spanner
SELECT
p.ref_type,
p.ref_code,
p.sku,
rt.id_product_fulltype,
rt.sku_category,
COALESCE(ANY_VALUE(rt.threshold), rp.default_threshold) AS threshold,
SUM(item_status) AS purchased_count
FROM reseller.purchase_history p
LEFT JOIN reseller.reseller_sku_category rsc ON rsc.sku = p.value_code AND 'sku' = p.value_type
@gihankarunarathne
gihankarunarathne / throttle.js
Last active September 16, 2015 19:09
Throttle validation NodeJS library implementation (using Redis, MySQL and Promises)
/**
* Handle Throttling Values and restrict accessing when throttling
* value exceeded.
*
* This class implementation is inspired from Redis
* Refer: http://redis.io/commands/incr#pattern-rate-limiter-1
*
* Gihan Karunarathne <[email protected]>
*/
'use strict';
@gihankarunarathne
gihankarunarathne / idle.py
Last active August 29, 2015 14:23 — forked from dmgl/idle.py
#!/usr/bin/env python
from idlelib.PyShell import main
if __name__ == '__main__':
main()
@gihankarunarathne
gihankarunarathne / docker_panel_stats.js
Created May 18, 2015 08:57
Read a live JSON stream from Docker API
function() {
var self = this;
var url = apiUrl + "/containers/" + containerId + "/stats";
// var url = "/docker/containers/" + containerId + "/stats";
console.log('URL ', url);
oboe(url)
.node('*', function(data) {
console.log('Data ', data);
})