Skip to content

Instantly share code, notes, and snippets.

View miayam's full-sized avatar
🌱
Slow but sure

Muhamad D. R. miayam

🌱
Slow but sure
View GitHub Profile
@miayam
miayam / groupByAnagram.js
Created December 30, 2020 04:25
Collect anagrams in one bucket grouped by unique character combination.
/**
* Split the array into halves until all items completely separated
* from one another and then sort and merge them recursively along
* the way.
* @param {string[]} [array] Array of characters.
* @return {string[]} Sorted array.
*/
function mergeSort(array) {
if (array.length === 1) {
// Return once we hit an array with a single item
@miayam
miayam / cermati.js
Last active May 8, 2019 08:58
Cermati's whiteboard coding test
const CSV = `No,Nama,Kota\n1,Muhammad D. Ramadhan,Bogor\n2,Christian,Jakarta Barat\n3,Roni,Bekasi`
const createSpace = (n) => {
let spaces = ""
for (let i = 0; i < n; i++) {
spaces += " "
}
return spaces;
}
@miayam
miayam / strPos.js
Created July 31, 2018 04:51
strPos.js
const strPos = (source, search) => {
let flag = false;
let indexes = [];
let truthfullness = null;
for (let i=0; i < source.length; i++) {
for (let j=0; j < search.length; j++) {
if (source[i+j] === search[j]) {
flag = true;
} else {
flag = false;
@miayam
miayam / bogusCombineReducers.js
Last active October 25, 2017 10:10
Implement combineReducers of Redux API.
// `combinedReducersObject` is an object like this:
//
// {
// reducer1: reducer1,
// reducer2: reducer2
// }
//
// Each key maps to its corresponding reducer function.
function combineReducers(combinedReducersObject) {
return function combine(state = {}, action) {
@miayam
miayam / bogusCreateStoreRedux.js
Last active March 31, 2019 09:58
Implement createStore of Redux API from scratch using plain old ES5 function.
// It's actually using closure for sure.
function createStore(reducer) {
let state; // Initially, it's undefined of course.
let listeners = [];
// `listener` is usually a React functional component
// that emits the actual DOM when invoked.
function subscribe(listener) {
// That's why we can have multiple
// React components sync with Redux's state.
module StudentImportWorker
class ImportWorker
include Sidekiq::Worker
def perform(id)
StudentCSVHandler::CSVImport.new(
id: id
).execute
end
end
# users_uploader.rb
require 'execjs'
module StudentHandler
class UsersUploader
attr_reader :command
def initialize(emails:, partner_id:)
partner = Partner.find_by(id: partner_id)
emails = emails.join(' ')
# student_import.rb
require 'csv'
module StudentCSVHandler
class CSVImport
def initialize(id:)
@student_import = StudentImport.find_by(id: id)
@file_path = "#{Rails.root}/tmp/#{@student_import.file.path}"
@partner = @student_import.partner
(function (window, undefined) {
var holes = document.querySelectorAll('.hole');
var moles = document.querySelectorAll('.mole');
var scoreBoard = document.querySelector('.score');
var playButton = document.querySelector('.playAgain');
var timeUp = false;
var poppingTimeout = null;
var playTimeout = null;
var score = 0;
var lastHole;
@miayam
miayam / timer.js
Last active September 29, 2017 13:16
(function (timer, window, undefined) {
var buttons = document.querySelectorAll('[data-time]');
var form = document.customForm;
function setTimer() {
var seconds = window.parseInt(this.dataset.time);
timer(seconds);
}
function setCustomTimer(event) {