Skip to content

Instantly share code, notes, and snippets.

@sethbunke
sethbunke / pytorch-basic-neural-network.py
Created July 3, 2018 00:32
PyTorch Very Basic Neural Network
class Net(nn.Module):
def __init__(self):
super().__init__()
self.conv1 = nn.Conv2d(1, 10, kernel_size=5)
self.conv2 = nn.Conv2d(10, 20, kernel_size=5)
self.conv2_drop = nn.Dropout2d()
self.fc1 = nn.Linear(320, 50)
self.fc2 = nn.Linear(50, 10)
def forward(self, x):
@sethbunke
sethbunke / python-shift-array-right-lambda.py
Last active July 3, 2018 00:33
Python Shift Array Right Lambda
shift_right = lambda arr,n: arr if n == len(arr) else arr[(-1*n):] + arr[:((len(arr)-n))]
print(shift_right([1, 2, 3, 4, 5], 3))
#[3, 4, 5, 1, 2]
@sethbunke
sethbunke / using-generators-in-python-to-reduce-memory-usage
Created November 29, 2017 18:48
Using generators in Python to reduce memory usage
def multiples(input_value=10):
results = []
while 1:
value = input_value if len(results) == 0 else (len(results) + 1) * input_value
results.append(value)
yield results
our_generator = fibonacci()
result = []
@sethbunke
sethbunke / keras-show-training-and-validation-loss-over-time
Created November 29, 2017 01:46
Keras show training and validation loss over time
from keras.models import Model
import matplotlib.pyplot as plt
history_object = model.fit_generator(train_generator, samples_per_epoch =
len(train_samples), validation_data =
validation_generator,
nb_val_samples = len(validation_samples),
nb_epoch=5, verbose=1)
### print the keys contained in the history object
@sethbunke
sethbunke / anaconda-clean-up-downloaded-libs.txt
Last active October 24, 2017 17:16
Anaconda - clean up downloaded libraries (zip, tar ball, etc.)
#Cleanup downloaded libraries (remove tarballs and packages):
conda clean -tp
@sethbunke
sethbunke / build-dotnet-core-docker-image.txt
Last active September 8, 2017 00:52
Build DotNet Core Docker image
#https://dev.to/schwamster/docker-tutorial-with-for-aspnet-core
dotnet new webapi
dotnet restore
dotnet publish -o ./publish
#IN DOCKERFILE
@sethbunke
sethbunke / show-all-stopped-docker-containers
Last active July 17, 2018 01:07
Show all stopped Docker containers
#show all stopped containers
docker ps --filter "status=exited"
docker ps -f "status=exited"
#remove image
docker rmi image-id
#remove container
docker rm container-id
@sethbunke
sethbunke / python-sort-nested-tuples
Created June 7, 2017 20:26
Python - sort nested tuples
data = [(1, ('a','a')), (2, ('z','z')), (3, ('c','c')), (4,('d','d'))]
result = sorted(data, reverse=True)
print(result)
#[(4, ('d', 'd')), (3, ('c', 'c')), (2, ('z', 'z')), (1, ('a', 'a'))]
@sethbunke
sethbunke / duplicate-values-in-array
Created May 25, 2017 01:05
Identify duplicate values in an array
import collections
input = [1,2,3,2,1,5,6,5,5,5]
result = [item for item, count in collections.Counter(input).items() if count > 1]
print(result)
#[1, 2, 5]
@sethbunke
sethbunke / tanh-and-tanh-derivative.txt
Created May 8, 2017 22:26
tanh and tanh derivative
def tanh(x):
return (1.0 - numpy.exp(-2*x))/(1.0 + numpy.exp(-2*x))
def tanh_derivative(x):
return (1 + tanh(x))*(1 - tanh(x))