Skip to content

Instantly share code, notes, and snippets.

@knrt10
knrt10 / command.js
Created May 11, 2018 05:36
Command for practice mode
program
.command('practice')
.alias('p')
.description('Starts typeracer in practice mode')
.action(() =>
{
game()
})
@knrt10
knrt10 / keyevents.js
Created May 11, 2018 05:39
Enabling keypress
const stdin = process.stdin
const stdout = process.stdout
stdin.setRawMode(true)
stdin.resume()
require('readline').emitKeypressEvents(stdin)
@knrt10
knrt10 / wpm.js
Created May 11, 2018 05:41
words per mintue
/**
* @function updateWpm
*/
function updateWpm () {
if (stringTyped.length > 0) {
wordsPermin = stringTyped.split(' ').length / (time / 60)
}
}
@knrt10
knrt10 / color.js
Last active May 11, 2018 05:44
See correct wrods
/**
* @function color
* @param {String} quote
* @param {String} stringTyped
*/
function color (quote, stringTyped) {
let colouredString = ''
let wrongInput = false
@knrt10
knrt10 / time.js
Created May 11, 2018 05:46
Time of user
/**
* @function Time
*/
function Time () {
time = (Date.now() - timeStarted) / 1000
}
@knrt10
knrt10 / crypto.js
Created May 11, 2018 07:27
Create random string
const roomNumber = crypto
.randomBytes(12)
.toString('base64')
.replace(/[+/=]+/g, '')
@knrt10
knrt10 / room.js
Created May 11, 2018 07:50
emit events when client joins
// Emitting client info on joining the room
_socket.on('room', function (val) {
_socket.emit('join', {roomName: val.value, username: data.username, number: data.number, randomNumber: data.randomNumber})
})
@knrt10
knrt10 / randomPara.js
Created May 11, 2018 07:54
random paragraph when on every connection
/**
* @function randomNumRetry
*/
function randomNumRetry () {
randomNumber = Math.floor((Math.random() * paras.length))
quote = paras[randomNumber].para
if (quote.length < 100) {
quote = paras[randomNumber].para + ' ' + paras[randomNumber - 1].para
}
@knrt10
knrt10 / top10.js
Last active May 13, 2018 19:19
top 10 scores of user
// Getting documents from databse
Score.findOne({_id: process.env.ID}, (err, players) => {
if (err) throw new Error(err)
let playersArray = players.players.sort(function (a, b) {
return b.score - a.score
})
let lowestScore = []
lowestScore.push(playersArray[playersArray.length - 1].score)
@knrt10
knrt10 / gulpfile.js
Created December 26, 2018 07:55
Gulpfile for minifying code from TS to JS
const gulp = require("gulp");
const ts = require("gulp-typescript");
const sourcemaps = require("gulp-sourcemaps");
const tsProject = ts.createProject("tsconfig.json", {
typescript: require("typescript")
});
gulp.task("build", () => {
gulp.src("process.yml")
.pipe(gulp.dest("dist"));