Skip to content

Instantly share code, notes, and snippets.

View kasimte's full-sized avatar

Kasim kasimte

View GitHub Profile
@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 / 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 / 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 / git-grep-replace.sh
Created June 26, 2019 06:35
How do I replace a string in a git repository on Mac?
# note, this is for mac
# more: https://blog.jasonmeridth.com/posts/use-git-grep-to-replace-strings-in-files-in-your-git-repository/
git grep -l 'original_text' | xargs sed -i '' -e 's/original_text/new_text/g'
@kasimte
kasimte / anaconda-shell-run-python.sh
Last active June 10, 2019 06:35
How do I run a command line script using Anaconda and Python?
source activate environment_name
python script.py
# Example:
#
# Kasim:pytorch-cifar Kasim$ python --version
# Python 2.7.14
# Kasim:pytorch-cifar Kasim$ source activate base
# (base) Kasim:pytorch-cifar Kasim$ python --version
# P ython 3.6.5 :: Anaconda, Inc.
@kasimte
kasimte / matlib_plot.py
Created April 29, 2019 01:02
Simple plot in Python using MatLib.
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot(range(NUM_EPOCH), train_loss1, label="MLP")
ax.plot(range(NUM_EPOCH), train_loss2, label="CNN")
ax.legend()
ax.set(xlabel='Epochs', ylabel='Loss',
title="Training Loss (MLP vs CNN)")
ax.grid()
@kasimte
kasimte / UniqueIdentifier.swift
Created April 22, 2018 02:38
Creating a unique string identifier in Swift based on the current process.
static func uniqueIdentifier() -> String {
let quasiUniqueString = ProcessInfo.processInfo.globallyUniqueString
let index = quasiUniqueString.index(quasiUniqueString.startIndex, offsetBy: 10)
return quasiUniqueString.substring(to: index)
}
@kasimte
kasimte / ConditionalStringOptionalUnwrapping.swift
Last active October 24, 2018 11:36
An example of conditional String optional unwrapping in Swift 3.
var optional: String? = "Hello World"
if let o = optional { // Same as: optional as String!
print(o)
}
// Output: Hello World.
if let o = optional as String! {
print(o)
}
// Output: Hello World.
@kasimte
kasimte / AppDelegateLocalNotificationExample.m
Created April 8, 2017 20:46
An example of receiving UILocalNotifications in the AppDelegate and presenting an UIAlert.
- (void)application:(UIApplication *)application
didReceiveLocalNotification:(UILocalNotification *)notification {
UIViewController *top = [[application keyWindow] rootViewController];
while (top.presentedViewController != nil) {
top = top.presentedViewController;
}
UIAlertController *alert =
@kasimte
kasimte / ConflictingProtocolExtensions.swift
Created April 6, 2017 19:08
This is an example of conflicting protocol implementations in Swift
protocol X {
func myfunc() -> Int
}
protocol Y {
}
protocol Z {
}