Skip to content

Instantly share code, notes, and snippets.

View loretoparisi's full-sized avatar
🐍
NightShift

Loreto Parisi loretoparisi

🐍
NightShift
View GitHub Profile
@loretoparisi
loretoparisi / es_autocomplete.mapping.js
Created September 20, 2021 17:16
Elastic Search Auto Complete Analyzer
{
"aliases": {},
"mappings": {
"properties": {
"text": {
"type": "text",
"analyzer": "autocomplete"
}
}
},

With wildcard

{
  "query": {
    "bool": {
      "must": [
        {
          "wildcard": {
 "text": "*antonio*banderas*"
@loretoparisi
loretoparisi / awscat.sh
Last active August 20, 2021 09:45
AWS S3 CAT to BASH
#!/bin/bash
function __awscat {
if [ "$1x" != 'x' ]; then
aws s3 cp --quiet "$1" /dev/stdout
fi
}
__awscat $1
@loretoparisi
loretoparisi / thread_support.py
Created August 5, 2021 16:56
Python Thread Support with Bounder Thread Pool or Process Executor
from functools import wraps
from .bounded_pool_executor import BoundedThreadPoolExecutor
from .bounded_pool_executor import BoundedProcessPoolExecutor
_DEFAULT_POOL = BoundedThreadPoolExecutor(max_workers=5)
_PROCESS_POOL = BoundedProcessPoolExecutor(max_workers=5)
def threadpool(f, executor=None):
@wraps(f)
def wrap(*args, **kwargs):
@loretoparisi
loretoparisi / bounded_pool_executor.py
Last active April 10, 2025 20:19
Python Thread Support with Bounder Thread Pool or Process Executor
import multiprocessing
import concurrent.futures
import threading
name = 'bounded_pool_executor'
class _BoundedPoolExecutor:
semaphore = None
@loretoparisi
loretoparisi / github_colors.css
Created May 7, 2021 16:54
Github CSS Colors HEX scale
{
--color-scale-black: #010409;
--color-scale-white: #f0f6fc;
--color-scale-gray-0: #f0f6fc;
--color-scale-gray-1: #c9d1d9;
--color-scale-gray-2: #b1bac4;
--color-scale-gray-3: #8b949e;
--color-scale-gray-4: #6e7681;
--color-scale-gray-5: #484f58;
--color-scale-gray-6: #30363d;
@loretoparisi
loretoparisi / s3_delete_object_version_id.js
Last active May 6, 2021 18:58
S3 Delete Object with VersionId
function deleteVersionedObject(bucket, key, callback) {
var params = {
Bucket: bucket,
Key: key
};
s3.deleteObject(params, function (error, data) {
if (error) {
console.error("S3Dataset delete error key:%s error:%@", params.key, error);
return callback(error);
}
@loretoparisi
loretoparisi / trace_mem.py
Created May 6, 2021 12:49
Python Memory Alloc Trace
def trace_mem(nframe=6,top=8):
'''
naive memory trace
'''
import tracemalloc
is_tracing = tracemalloc.is_tracing()
if not is_tracing:
# start tracing
tracemalloc.start(nframe)
return {}
@loretoparisi
loretoparisi / aws_s3_get_object_put_object_async.js
Last active July 6, 2022 18:12
NodeJS JavaScript AWS S3 getObject, putObject, deleteObject with async await and recursive approach for nested S3 folders
async function getObjectAsync(bucket, key) {
try {
const data = await s3
.getObject({ Bucket: bucket, Key: key })
.promise();
var contents = data.Body.toString('utf-8');
return contents;
} catch (err) {
console.log(err);
}
@loretoparisi
loretoparisi / stripJSON.js
Created April 22, 2021 15:32 — forked from usmansbk/stripJSON.js
Recursively remove json keys in an array
/**
* @function stripJSON
* @desc - This function removes selected object keys
* @param {Object} json - JavaScript object to strip
* @param {Object[]} keys - array of selected keys (string)
* @return {Object} - deep copy of object without keys
*/
function stripJSON(json, keys) {
if (json === null || json === undefined) return json;
let obj = {}, key;