This file contains 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 mapAsync(iterable, callback, concurrency, results) { | |
if (!iterable.length) | |
return Promise.all(results).then(results => console.log(results)); | |
const queue = iterable.splice(0, concurrency - 1); | |
while (queue.length) { | |
const task = queue.shift(); | |
callback(task, iterable, callback, concurrency, results); | |
} |
This file contains 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
class TaskQueue { | |
constructor(concurrency) { | |
this.taskQueue = []; | |
this.consumerQueue = []; | |
for (let i = 0; i < concurrency; i++) { | |
this.consumer(); | |
} | |
} |
This file contains 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
import { readdir, stat } from 'fs'; | |
import { basename, join, resolve } from 'path'; | |
import { TaskQueue } from './TaskQueue.js'; | |
import { searchFile, processFile } from './searchFiles.js'; | |
let results = [], | |
allFiles = [], | |
processed = null, | |
readFiles = false; |
This file contains 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 { EventEmitter } = require('events'); | |
const ticker = (num, cb) => { | |
const emitter = new EventEmitter(); | |
const counters = { timePassed: 0, count: 0 }; | |
const timestamp = () => { | |
const time = Date.now(); | |
return time % 5 === 0; |
This file contains 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 { EventEmitter } = require('events'); | |
const ticker = (num, cb) => { | |
let timePassed = 0, | |
count = 0; | |
const emitter = new EventEmitter(); | |
const repeat = () => { | |
if (timePassed >= num) return process.nextTick(() => cb(count)); |
This file contains 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
class Car { | |
constructor(doors = 4, state = "brand new", color = "silver") { | |
this.doors = doors | |
this.state = state | |
this.color = color | |
} | |
} | |
class Truck { |
This file contains 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
# route - | |
get '/pag' do | |
@all_album_links = paginate | |
@pages = {} | |
@all_album_links.each_slice(10).with_index do |x,i| | |
@pages.store("page #{i+1 }", "#{x}") | |
end | |
slim :pag | |
#end | |
end |
This file contains 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
- num_links = @albums.page_count | |
- link_first_part = %q[<li class="page-item"><a class="page-link" href="#">] | |
- link_second_part = %q[</a></li>] | |
<nav aria-label="Page navigation example"> | |
<ul class="pagination"> | |
<li class="page-item"><a class="page-link" href="#">Previous</a></li> | |
- num_links.times do |i| | |
- i = 1 |
This file contains 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
# is it possible to have an if statement in the insert | |
# dataset and map works in bin/sequel so that is not the problem | |
check_ids = DB.fetch("SELECT * FROM album_sub_folders WHERE album_id = {@album_id}") | |
..... | |
..... | |
MUSIC_FILES.insert(file_name: File.basename(entry), | |
album_id: @album_id, | |
album_sub_folder_id: @asf_id if check_ids.map.count > 0, |
NewerOlder