Skip to content

Instantly share code, notes, and snippets.

View imanabu's full-sized avatar

Manabu Tokunaga imanabu

View GitHub Profile
@imanabu
imanabu / INeptuneSlowQueryLog.ts
Last active May 17, 2024 00:23
NeptuneSlowQueryLog TypeScript Schema
export interface Root {
queryStats: QueryStats
memoryStats: MemoryStats
queryTimeStats: QueryTimeStats
statementCounters: StatementCounters
transactionCounters: TransactionCounters
concurrentExecutionStats: ConcurrentExecutionStats
queryBatchStats: QueryBatchStats
storageCounters: StorageCounters
}
@imanabu
imanabu / NeptuneSlowQueryParse.py
Last active May 16, 2024 23:53
Neptune Slow Query Parser and Most Offensive Query Discovery Jupyter Notebook Example
# %% [markdown]
# # Neptune Slow Query Log Analysis
# %%
log_file_name = "slowquery.txt"
# %%
import json
def read_file_lines(filename):
@imanabu
imanabu / parseCSV.scala
Last active October 26, 2020 03:42
Scala Fully Parse CSV lines from a File, supports ignoring commans in quoted strings. Can generate a JSON DTO.
package dtos
import play.api.libs.json.{Format, Json}
case class ITableRow(
cols: Seq[String]
)
object ITableRow {
implicit val jsonFormatter: Format[ITableRow] = Format(Json.reads[ITableRow], Json.writes[ITableRow])
@imanabu
imanabu / JsonReadOptionDoubleJson
Last active May 14, 2020 13:52
implicit converter lets you read Json into Option[Double] Scala Data Type
object DoubleReads {
def reads(json: JsValue): JsResult[Option[Double]] = json match {
case JsNumber(n) => JsSuccess(Some(n.toDouble))
case JsString(s) => JsSuccess(Some(s.toDouble))
case _ => JsSuccess(None)
}
}
// Later in your code where you need
implicit val odr: json.Reads[Option[Double]] = DoubleReads.reads
@imanabu
imanabu / gist:ea2c2bc206caa9d93c08544cf51c7c77
Created February 11, 2020 04:44
Encode and Decode a 128-bit UUID to DICOM UID Segment
private static String dotEncode(long n) {
String s = String.format("%d", n);
if (s.startsWith("-")) {
return ".2" + s.substring(1);
}
return ".1" + s;
}
private static long dotDecode(String s) {
if (s.startsWith("1")) {
@imanabu
imanabu / json-date-time-serailizer.py
Created August 14, 2019 21:09
Python: Allow JSON serialize to work over datetime data type
def to_serializable(val):
"""
Allows the JSON serializer to work over datetime data type
:param val:
:return:
"""
if isinstance(val, datetime):
return val.isoformat() + "Z"
vf = type(val).__name__
@imanabu
imanabu / check-scan-dir.py
Created August 14, 2019 20:58
Python Dir Exists and Scan Directory
import os
import os.path
from pathlib import Path
if not Path.exists(Path(image_source_dir)):
raise Exception(f"The source not found: {image_source_dir}. Please correct this in Migrate.py")
index = 0
previousInfo: ImageInfo = None
for ent in Path(image_source_dir).iterdir():
@imanabu
imanabu / ClassAndInstanceInheritance.ts
Created March 4, 2019 22:48
Do Not Confuse Class and Instance Inheritance With TypeScript
/**
* Combined class and instance inheritance in TypeScript
* This looks deceptively simple, but there are two layers of inheritance that's happening
* One is the Class inheritance. Another is the actual instance inheritance that's chained
* through the children array. The parent has its' instance based factory to generate its
* own children either daughters of sons
*/
class person {
constructor(name, parent = null) {
this.name = name;
@imanabu
imanabu / classLoaderDemo.java
Last active August 9, 2019 22:19
Read a Java8 Reousrce File and then Parse into String in 3 lines
ClassLoader classLoader = getClass().getClassLoader();
String fn = classLoader.getResource("some-file.txt").getFile();
String txt = new String(Files.readAllBytes(Paths.get(fn.substring(1)))); // Skips the first / of /c:/ in Windows
@imanabu
imanabu / WebStormAngularJS2TypescriptCommandLineOptions.txt
Created August 18, 2015 03:10
WebStorm AngularJS2 Typescript Command Line Options
--watch -m commonjs -t es5 --emitDecoratorMetadata --experimentalDecorators