Skip to content

Instantly share code, notes, and snippets.

View nickangtc's full-sized avatar

Nick Ang nickangtc

View GitHub Profile
@nickangtc
nickangtc / simple_calendar_tutorial.md
Created October 15, 2016 02:07
How to use Simple Calendar Rails gem

Using Simple Calendar for Rails

Objectives

  • Use simple_calendar gem to easily generate calendars in a Rails project.
  • Understand how the calendar is generated and how to customise it.

What is simple calendar?

Simple calendar is a Rails gem that generates a calendar for use in your views.

You can use simple calendar to generate monthly and weekly calendars.

@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 / linked-list.js
Last active June 15, 2022 04:37
Linked list in JavaScript
/**
* Read the original blog post for a detailed explanation!
* http://www.nickang.com/linked-list-explained-part-1/
* http://www.nickang.com/linked-list-implementation-part-2/
*/
/**
* Constructor functions
*/
@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;
@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 / queue.js
Created December 25, 2017 04:33
Simple implementation of a Queue in JavaScript - with performance tests
/**
* ============================================
* CUSTOM IMPLEMENTATION OF QUEUE CLASS
* ============================================
*/
/**
* Implementation of Queue.
*/
class Queue {
@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
# =============