Skip to content

Instantly share code, notes, and snippets.

Patrick Tran theptrk

Block or report user

Report or block theptrk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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, :);
View findClosestCentriods.m
function idx = findClosestCentroids(X, centroids)
% Set K
K = size(centroids, 1);
% Set empty indices vector
idx = zeros(size(X,1), 1);
% for every example in X...
for i = 1:size(X, 1)
View binary-tree-depth-first-search.js
* Depth first search and Breadth first search traverals in JavaScript
* This example uses a binary tree with left and right nodes
* by theptrk <>
function Node(value, opts = {}) {
this.value = value
this.left = opts.left ? opts.left : null
this.right = opts.right ? opts.right : null
You can’t perform that action at this time.