Skip to content

Instantly share code, notes, and snippets.

View kasimte's full-sized avatar

Kasim kasimte

View GitHub Profile
@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
@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 / 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 / capture_output_from_script.py
Created February 2, 2021 05:39
Demo of running separate python script as subprocess and capturing output.
# output.py (separate file)
print(37.234)
# capture_output_from_script.py
import subprocess
# run output.py as subprocess and capture output, format it, convert to float, and print
x = float(subprocess.check_output('python output.py', shell=True, text=True).strip())
print(x)
@kasimte
kasimte / WKScriptMessageHandler+Rx.swift
Created January 2, 2021 03:34
RxSwift extension for WebKit's WKScriptMessageHandler.
import WebKit
import RxSwift
import RxCocoa
public extension Reactive where Base: WKScriptMessageHandler {
func didReceiveMessage() -> Observable<(WKUserContentController, WKScriptMessage)> {
return self.methodInvoked(#selector(Base.userContentController))
.map { args in
guard args.count == 2,
let controller = args[0] as? WKUserContentController,
@kasimte
kasimte / Array+FilterEncodable.swift
Created January 1, 2021 01:16
Swift Array extension to remove uncodable elements.
extension Array where Element: Encodable {
/// - Returns: An array having removed any element of the array which is not encodable itself.
func filterUncodable() -> [Element] {
return self.filter { (el: Element) -> Bool in
let encoded = try? JSONEncoder().encode(el)
return encoded != nil ? true : false
}
}
}
@kasimte
kasimte / .gitconfig-for-diffmerge
Created October 29, 2020 05:18 — forked from YanhaoYang/.gitconfig-for-diffmerge
Using DiffMerge as your Git visual merge and diff tool on Mac
[diff]
tool = diffmerge
[difftool "diffmerge"]
cmd = diffmerge \"$LOCAL\" \"$REMOTE\"
[merge]
tool = diffmerge
[mergetool "diffmerge"]
cmd = "diffmerge --merge --result=\"$MERGED\" \"$LOCAL\" \"$(if test -f \"$BASE\"; then echo \"$BASE\"; else echo \"$LOCAL\"; fi)\" \"$REMOTE\""
trustExitCode = true
@kasimte
kasimte / keybase.md
Created February 25, 2020 02:08
Keybase Proof.

Keybase proof

I hereby claim:

  • I am kasimte on github.
  • I am kasim (https://keybase.io/kasim) on keybase.
  • I have a public key ASAKS4iJvRsfmLAjWOebG4mjHFY3XQTMe86umzEfb7niJQo

To claim this, I am signing this object:

@kasimte
kasimte / add_mathjax_to_jekyll_head.html
Created February 15, 2020 03:22
Snippet to add MathJax to Jekyll Blog.
<!-- From https://github.com/fastai/fast_template/blob/6f72d2957a4e302e437f4437dd6a1e5a1f14274a/_includes/head.html -->
{% if site.use_mathjax %}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css" integrity="sha384-zB1R0rpPzHqg7Kpt0Aljp8JPLqbXI3bhnPWROx27a9N0Ll6ZP/+DiW/UqRcLbRjq" crossorigin="anonymous">
<script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.js" integrity="sha384-y23I5Q6l+B6vatafAwxRu/0oK/79VlbSz7Q9aiSZUvyWYIYsd+qj+o24G5ZU2zJz" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/contrib/auto-render.min.js" integrity="sha384-kWPLUVMOks5AQFrykwIup5lo0m3iMkkHrD0uJ4H5cjeGihAutqP0yW0J6dpFiVkI" crossorigin="anonymous"></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
renderMathInElement( document.body
@kasimte
kasimte / convert-mov-to-mp4.rb
Last active September 29, 2023 05:02
Ruby script to convert MOV files to mp4.
# Usage:
#
# 1) cd <my-directory-with-mov-files>
# 2) ruby convert-mov-to-mp4.rb
#
mov_files = Dir[Dir.pwd() + "/*.MOV"]
mov_files.each do |file|
puts "Processing file: #{ file }"
# extract the basename for renaming