Skip to content

Instantly share code, notes, and snippets.

View kasimte's full-sized avatar

Kasim kasimte

View GitHub Profile
@kasimte
kasimte / sample-gym.py
Created November 5, 2019 08:38
Sample script for OpenAI's gym environment familiarization.
# Requirements:
# - Python 3
# - gym
#
# This is a sample script that familiarizes one with OpenAI's gym
# environment.
#
# It is modified from:
#
# https://github.com/vmayoral/basic_reinforcement_learning/tree/master/tutorial3
@kasimte
kasimte / for-with-index.py
Last active November 5, 2019 13:18
Example for loop with index in Python.
# Neural Network config
CONV_FILTERS = [32, 48]
CONV_KERNEL_SIZES = [6, 5]
CONV_STRIDES = [2, 2]
for c, (filters, kernel_size, strides) in enumerate(zip(CONV_FILTERS, CONV_KERNEL_SIZES, CONV_STRIDES)):
print("index")
print(c) # this is the index
# everything else is just unpacked
print(filters)
@kasimte
kasimte / tf-reduce_sum-example.py
Last active November 25, 2019 09:48
Example of TensorFlow's reduce_sum.
import tensorflow as tf
a = tf.constant([[0, 1], [2, 0], [0, 3]])
b = tf.reduce_sum(a)
c = tf.reduce_sum(a, 0) # reduce by column
d = tf.reduce_sum(a, 1) # reduce by row
for tensor in [b, c, d]:
result = tf.Session().run(tensor)
print(result)
@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 / 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 / .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 / 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 / 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 / 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 / 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])