Skip to content

Instantly share code, notes, and snippets.

theptrk /
Last active Jun 23, 2020
pyenv - get available versions for installation

First check the python downloads page to view the current releases

$ open

This produces the list of ALL available pyenv versions

$ pyenv install --list

theptrk / openweather_api_example.html
Last active Jun 3, 2020
This uses the OpenWeather current weather data API:
View openweather_api_example.html
<!DOCTYPE html>
<title>Open Weather API</title>
<style type="text/css">
pre {
background-color: #f1f1f1;
padding: 5px;
margin: 5px;
border-radius: 5px;
theptrk / optional_chaining.js
Last active May 20, 2020
Optional Chaining in javascript - avoid crashing your app
View optional_chaining.js
// This is an example of Optional Chaining
const adventurer = {
name: 'Alice',
cat: {
name: 'Dinah'
const dogName =;
theptrk / app.js
Created May 18, 2020
This is a starter html snippet
View app.js
// js goes here
console.log("hello js")
theptrk / html_onsubmit.html
Created May 17, 2020
HTML onsubmit connected to javascript function using a todo list input example
View html_onsubmit.html
<!DOCTYPE html>
<title>Hello onsubmit</title>
<h1>Hello onsubmit</h1>
<form onsubmit="handleForm()">
<input type="text" name="todo" autocomplete="off">
<button type="submit">Create Todo</button>
View recoverData.m
function X_rec = recoverData(Z, U, K)
% initialize recovered values
X_rec = zeros(size(Z, 1), size(U, 1));
for i = 1:size(X_rec,1)
% projected_x is (1, K)
projected_x = Z(i, :);
% initialize x
View projectData.m
function Z = projectData(X, U, K)
% Initalize
Z = zeros(size(X, 1), K);
% index to create Ureduce
Ureduce = U(:, 1:K)
for i=1:size(Z,1)
View kMeansInitCentroids.m
function centroids = kMeansInitCentroids(X, K)
% initialize placeholder
centroids = zeros(K, size(X, 2));
% use randperm to shuffle the row indices of X
shuffle_X = randperm(size(X,1));
% only use the first K number of shuffled indices
first_K = shuffle_X(1:K, :);
View computeCentriods.m
function centroids = computeCentroids(X, idx, K)
% Initialize to store new centroid values
centroids = zeros(K, n);
% iterate over number of centroids
for i = 1:K
% create a boolean vector that match the current index, then use this to index into X
has_this_centroid = X(idx == i, :);