Skip to content

Instantly share code, notes, and snippets.

View kasimte's full-sized avatar

Kasim kasimte

View GitHub Profile
@kasimte
kasimte / latest_match_from_path.py
Created February 2, 2021 14:05
Example of reading a directory and returning the latest file matching a string using python.
def latest_match_from(path, match):
# read the modification time
mtime = lambda f: os.stat(os.path.join(path, f)).st_mtime
# read all files from path and sort based on modification time
files = list(sorted(os.listdir(path), key=mtime))
# filter based on match
matches = [a for a in files if match in a]
# return the full path of the most recent match
return os.path.join(path, matches[-1])
@kasimte
kasimte / run_script_with_config.py
Created February 7, 2021 11:40
Run an external python script with object properties
class Config:
def __init__(self, a, b):
self.a = a
self.b = b
config = Config(1, 2)
script = "./my_script.py"
# note the "" around config
command = "python {script} \"{config}\"".format(script=script, config=vars(config))
os.system(command)
@kasimte
kasimte / diffmerge
Last active December 18, 2021 22:09
diffmerge script
#!/bin/sh
## A little script to make it easier to launch DiffMerge from the command line.
## Install this script into a folder in your path, such as /usr/bin or /usr/local/bin.
##
## Version 3.3.0.1001
## Copyright (C) 2003-2009 SourceGear LLC. All Rights Reserved.
##############################################################################
## Change DIFFMERGE_PATH to point to where you installed DiffMerge