Skip to content

Instantly share code, notes, and snippets.

Avatar

Jean van Kasteel vankasteelj

View GitHub Profile
View jquery-clickhold
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 Aug 23, 2018
Gamepad chrome API implementation in nodejs
View gamepad.js
'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 Nov 18, 2017
Single touch KeyboardVisualizerVC executable start/stop
View startstop.bat
@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%"
View gist:f148eb5526580c8dec910fdd16057310
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 Jul 24, 2016
find the multiplicative persistence of a number
View mult_persistence.js
// 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 Mar 21, 2021
gzip without header and base 64 encode, in Node
View gunzipbase64.js
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 Nov 30, 2015
merge 2 srt files, using 1's timecodes and 2's text lines. nodejs.
View merge2subs.js
/* 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 Nov 17, 2015
multiplatform code to find a local binary on user input.
View search_bin.js
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 Nov 10, 2015
transcode .ass, .ssa, .txt to SRT
View ssa2srt.js
//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 Mar 16, 2021
Javascript - Seconds to Time (hh:mm:ss,ms) -> sec2time(593.685038) becomes 00:09:53,685
View sec2time.js
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);
}