This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// `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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module StudentImportWorker | |
class ImportWorker | |
include Sidekiq::Worker | |
def perform(id) | |
StudentCSVHandler::CSVImport.new( | |
id: id | |
).execute | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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(' ') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) { |
NewerOlder