Skip to content

Instantly share code, notes, and snippets.

View vankasteelj's full-sized avatar

Jean van Kasteel vankasteelj

  • Belgium
View GitHub Profile
@vankasteelj
vankasteelj / jquery-clickhold
Created April 11, 2020 14:56
Jquery click & hold
var timeOut = 0;
$('.button').on('mousedown', function(e) {
console.log('click');
//start hold
var i = 0;
timeOut = setInterval(function(){
console.log('hold for', i++);
}, 150);
}).bind('mouseup mouseleave', function(e) {
@vankasteelj
vankasteelj / gamepad.js
Created August 23, 2018 20:51
Gamepad chrome API implementation in nodejs
'use strict'
const Gamepad = {
API: {
controller: {},
connect: (e) => {
Gamepad.API.controller = e.gamepad;
console.log('Gamepad (id:%d) connected:', e.gamepad.index, e.gamepad.id);
},
disconnect: (e) => {
@vankasteelj
vankasteelj / startstop.bat
Created November 18, 2017 22:01
Single touch KeyboardVisualizerVC executable start/stop
@echo off
Set "Path=%~d0%~p0"
Set "MyProcess=KeyboardVisualizerVC.exe"
tasklist /NH /FI "imagename eq "%MyProcess%"" 2>nul |find /i "%MyProcess%" >nul
If not errorlevel 1 (
taskkill /im "%MyProcess%"
) else (
start "" "%Path%""%MyProcess%"
var freezeGif = function (img) {
return new Promise(function (resolve) {
var i = new Image();
i.src = img;
i.onload = function () {
var c = document.createElement('canvas');
var w = c.width = i.width;
var h = c.height = i.height;
@vankasteelj
vankasteelj / mult_persistence.js
Created July 24, 2016 11:47
find the multiplicative persistence of a number
// EN:calculate a given number's multiplicative persistence
// FR:calculer la persistance multiplicative d'un nombre donné
// Start number | nombre de départ
var n = 277777788888899;
var y = n;
var pst = 0;
while (y >= 10 && isFinite(y)) {
@vankasteelj
vankasteelj / gunzipbase64.js
Last active June 15, 2021 21:41
gzip without header and base 64 encode, in Node
var fs = require('fs');
var zlib = require('zlib');
// Read local subtitle, gunzip it, encode to base64
var toUpload; // future gunzipped/base64 encoded string
var path = 'foo/bar.srt'; // path to subtitle
fs.readFile(path, function(err, data) { // read subtitle
if (err) throw err; // handle reading file error
zlib.deflate(data, function(err, buffer) { // gunzip it
if (err) throw err; // handle compression error
@vankasteelj
vankasteelj / merge2subs.js
Created November 30, 2015 15:35
merge 2 srt files, using 1's timecodes and 2's text lines. nodejs.
/* merge2subs
*
* Resync subtitle with another sub's timecodes
*
* @file_tc is the file you extract timecodes from;
* @file_lines is the one you extract text from;
*
* both arguments are absolute path to SRT files
*
* @xpath is an absolute path to a directory, to save mixed.srt
@vankasteelj
vankasteelj / search_bin.js
Created November 17, 2015 01:17
multiplatform code to find a local binary on user input.
var fs = require('fs');
var async = require('async');
var path = require('path')
var DEBUT = Date.now();
var USER_INPUT = process.argv[2],
FOUND_BINARY,
PATH_TO_BINARY;
@vankasteelj
vankasteelj / ssa2srt.js
Created November 10, 2015 20:31
transcode .ass, .ssa, .txt to SRT
//transcode .ass, .ssa, .txt to SRT
var convert2srt = function (file, ext, callback) {
var readline = require('readline'),
counter = null,
lastBeginTime,
//input
orig = /([^\\]+)$/.exec(file)[1],
origPath = file.substr(0, file.indexOf(orig)),
@vankasteelj
vankasteelj / sec2time.js
Last active February 2, 2024 11:08
Javascript - Seconds to Time (hh:mm:ss,ms) -> sec2time(593.685038) becomes 00:09:53,685
function sec2time(timeInSeconds) {
var pad = function(num, size) { return ('000' + num).slice(size * -1); },
time = parseFloat(timeInSeconds).toFixed(3),
hours = Math.floor(time / 60 / 60),
minutes = Math.floor(time / 60) % 60,
seconds = Math.floor(time - minutes * 60),
milliseconds = time.slice(-3);
return pad(hours, 2) + ':' + pad(minutes, 2) + ':' + pad(seconds, 2) + ',' + pad(milliseconds, 3);
}