Skip to content

Instantly share code, notes, and snippets.

@theptrk
theptrk / README.md
Last active Jun 23, 2020
pyenv - get available versions for installation
View README.md

First check the python downloads page to view the current releases

$ open https://www.python.org/downloads/

This produces the list of ALL available pyenv versions

$ pyenv install --list

  ...
  pypy3-dev
@theptrk
theptrk / openweather_api_example.html
Last active Jun 3, 2020
This uses the OpenWeather current weather data API: https://openweathermap.org/current
View openweather_api_example.html
<!DOCTYPE html>
<html>
<head>
<title>Open Weather API</title>
<style type="text/css">
pre {
background-color: #f1f1f1;
padding: 5px;
margin: 5px;
border-radius: 5px;
@theptrk
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 = adventurer.dog?.name;
console.log(dogName);
@theptrk
theptrk / app.js
Created May 18, 2020
This is a starter html snippet
View app.js
// js goes here
console.log("hello js")
@theptrk
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>
<html>
<head>
<title>Hello onsubmit</title>
</head>
<body>
<h1>Hello onsubmit</h1>
<form onsubmit="handleForm()">
<input type="text" name="todo" autocomplete="off">
<button type="submit">Create Todo</button>
@theptrk
theptrk / sublime-text-vim-remap-jj.md
Last active May 10, 2020
Sublime Text vim (vintage) remap `jj` to exit
View sublime-text-vim-remap-jj.md
  • Go to Sublime Text -> Preferences -> Key Bindings and add this to your Default (OSX).sublime-keymap
[
    {
        "keys": ["j", "j"],
        "command": "_enter_normal_mode",
        "args": {
            "mode": "mode_insert"
        },
        "context": [{"key": "vi_insert_mode_aware"}]
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, :);
You can’t perform that action at this time.