Skip to content

Instantly share code, notes, and snippets.

View nickangtc's full-sized avatar

Nick Ang nickangtc

View GitHub Profile
@nickangtc
nickangtc / scikit_setup.md
Created October 27, 2016 06:04 — forked from undramatized/scikit_setup.md
Setup and Installation of Scikit Learn

Written with StackEdit.

##Machine Learning with Scikit ###Setup and Installation

For this tutorial we will be working with a Python framework called Scikit Learn. This is a free machine learning library that will allow us to execute multiple ML techniques and methodologies.

/*
 * Basically my own implementation of JavaScript's built-in Set object
 * but only accepting integers
 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
 *
 * Create a MySet object that contains an array of integers
 * Check for intersection and union between 2 MySet objects
*/
@nickangtc
nickangtc / binary-search-tree-javascript.js
Last active November 21, 2017 13:26
Binary search tree implemented in JavaScript (tree not balanced)
/**
* Binary search tree implementation in JavaScript.
*
* Note: the BST created here is a BST that is not "balanced,"
* meaning it has a lot of nodes on one side,
* which degrades the BST's O(log n) time complexity.
*
* Note 2: I'll be adding a balancing function in another snippet.
*/
@nickangtc
nickangtc / bubble-sort-javascript.js
Created December 3, 2017 14:01
Bubble sort implementation in JavaScript
/**
* Sort an array in ascending order.
* Delete null values before output.
* @param {number[]} array
* @return {number[]}
*/
function bubbleSort (array) {
var count = 0
var length = array.length
@nickangtc
nickangtc / layout-engine.js
Last active February 6, 2018 15:33
Layout Engine (coding challenge)
/*
* Complete the function below.
*
* Sample input 1: ['10 0 0 I love monkeys.']
* Sample output 1 (dashes denote trailing spaces):
* ---I love ---
* ---monkeys. -
*
* Sample input 2: ['10 0 0 I love monkeys.', '20 0 0 Good times and bad times.']
* Sample output 2 (dashes denote trailing spaces):
@nickangtc
nickangtc / type-error-handling-conditional-vs-try-except.py
Last active April 16, 2018 06:19
For discussing the best approach for handling type errors in Python 3
def increment_list_by(list, num):
'''Increment all items in a list by `num`
provided all items are `int` types.
Return modified list if successful, or original list otherwise.'''
incremented_list = []
# =============
# Note: below are 2 separate approaches to implement this function
# =============
@nickangtc
nickangtc / homemade-each-reduce.js
Last active April 26, 2018 08:35
Homemade version of the built-in forEach() and reduce() in JavaScript
/**
* each()
*
* Apply an action to every item in an array.
*/
const list = [1, 2, 3];
const each = function (array, action) {
for (let i = 0; i < array.length; i++) {
action(array[i]);
@nickangtc
nickangtc / nativeJavaScript.js
Created May 10, 2018 08:14 — forked from alexhawkins/nativeJavaScript.js
Implementation of Native JavaScript Methods (forEach, Map, Filter, Reduce, Every, Some)
'use strict';
/*****************NATIVE forEACH*********************/
Array.prototype.myEach = function(callback) {
for (var i = 0; i < this.length; i++)
callback(this[i], i, this);
};
//tests
@nickangtc
nickangtc / iterm2-solarized.md
Created May 11, 2018 02:02 — forked from kevin-smets/iterm2-solarized.md
iTerm2 + Oh My Zsh + Solarized color scheme + Meslo powerline font + [Powerlevel9k] - (macOS)

Default

Default

Powerlevel9k

Powerlevel9k

@nickangtc
nickangtc / binary-search-javascript.js
Last active October 24, 2018 19:32
Binary search in JavaScript
/**
* Binary search in JavaScript.
*
* For detailed explanation about binary search
* read my original blog post:
* http://www.nickang.com/binary-search-javascript/
*/
function binarySearch(array, key) {
var lower = 0;