Skip to content

Instantly share code, notes, and snippets.

View rahmanda's full-sized avatar
📈
Visualize everything!

Rahmanda Wibowo rahmanda

📈
Visualize everything!
View GitHub Profile
@rahmanda
rahmanda / generate_matrix.r
Created March 24, 2021 14:19
Generate identity-like matrix
# @param m : how many 1s repeated every column
# @param n : number of columns
# @return matrix n x (m * n)
# example:
# input: m = 2, n = 3
# output:
# [,1] [,2] [,3]
# [1,] 1 0 0
# [2,] 1 0 0
# [3,] 0 1 0
@rahmanda
rahmanda / quick-sort.js
Created March 23, 2021 16:18
Quick sort
function quickSort(list) {
if (list.length < 2) {
return list
}
const pivot = list[0]
const arr = list.slice(1)
const less = arr.filter(item => item <= pivot)
const greater = arr.filter(item => item > pivot)
return [...quickSort(less), pivot, ...quickSort(greater)]
}
@rahmanda
rahmanda / binary-search.js
Created March 23, 2021 15:05
Binary search using divide-and-conquer method
// return index of array if item is found
// return -1 if item is not found
function binarySearch(list, item, low, high) {
if (list.length === 0) {
return -1
}
const lowIndex = low !== undefined ? low : 0
const highIndex = high !== undefined ? high : list.length - 1
@rahmanda
rahmanda / multiply.js
Created June 16, 2019 10:43
Multiply big numbers represented by strings
/**
* Multiply big numbers represented by strings
* Complexity O(n)
* @param {number} num1
* @param {number} num2
* @return {number}
*/
function multiply(num1, num2) {
// This map will store number of digits as keys and
// multiplication result as values
@rahmanda
rahmanda / lengthOfLongestSubstring.js
Created June 16, 2019 10:20
Find the longest substring without repeating characters using sliding window
/**
* Find the longest substring without repeating characters using sliding window
* Complexity O(n)
* @param {string} str
* @return {number}
*/
function lengthOfLongestSubstring(str) {
const len = str.length;
const set = new Set();
let max = 0;
@rahmanda
rahmanda / longestPalindrome.js
Created June 16, 2019 10:13
Find the longest palindromic substring using expand-around-center technique
/**
* Find the longest palindromic substring using expand-around-center technique
* Complexity = O(n^2)
* @param {string} str
* @return {string}
*/
function longestPalindrome(str) {
let maxStr = str.length ? str[0] : '';
for (let idx = 0; idx < str.length; idx++ ) {
@rahmanda
rahmanda / longestPalindrome.js
Created June 16, 2019 08:57
Find the longest palindromic substring using dynamic programming
/**
* Find the longest palindromic substring using dynamic programming
* Complexity = O(n^2)
* @param {string} str
* @return {string}
*/
function longestPalindrome(str) {
const len = str.length;
let maxStr = len ? str[0] : str;
let maxLength = 1;
@rahmanda
rahmanda / vueconf-to-2018-materials.md
Created January 22, 2019 14:18
VueConf Toronto 2018 Materials

VueConf Toronto 2018 Materials

Note: Some of talks do not provide the material online. Video is still being updated on VueMastery.

  1. Evan You Keynotes Slides Video
  2. Jacob Schatz Vuex in Action Source Code
  3. Gregg Pollack Reactivity & Rendering Revealed
  4. Colin Bendell (Media) Content Optimization & Perf for Vue Apps
  5. Adam Wathan Advanced Component Patterns Source Code
  6. Tamara Stefanovic Legacy and Vue Slides
@rahmanda
rahmanda / log.txt
Created January 26, 2018 03:41
Npm install on flaki/clouduboy-flasher errors - Ubuntu 14.04
make: Entering directory `/home/tony/projects/clouduboy-flasher/node_modules/macos-alias/build'
CXX(target) Release/obj.target/volume/src/volume.o
../src/volume.cc:9:2: error: #error This platform is not implemented yet
#error This platform is not implemented yet
^
../src/volume.cc: In function ‘void Initialize(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE)’:
../src/volume.cc:16:49: error: ‘MethodGetVolumeName’ was not declared in this scope
Nan::GetFunction(Nan::New<FunctionTemplate>(MethodGetVolumeName)).ToLocalChecked());
^
make: *** [Release/obj.target/volume/src/volume.o] Error 1