Skip to content

Instantly share code, notes, and snippets.

@lac5
lac5 / twitter-id-redirect.meta.js
Last active June 17, 2024 15:04
Automatically redirects to a user's Twitter page when viewing from the ID page
// ==UserScript==
// @name Twitter ID Redirect
// @namespace larryc5
// @version 1.0
// @description Automatically redirects to a user's Twitter page when viewing from the ID page.
// @author Larry Costigan
// @match https://twitter.com/intent/user?*
// @grant none
// @run-at document-end
// @downloadURL https://gist.github.com/larryc5/551ceee80e95213964900f285a41d2ad/raw/twitter-id-redirect.user.js
// ==UserScript==
// @name Twitter auto-refresh
// @namespace larryc5
// @version 1.3
// @description Refreshes the timeline items automatically every 10 sec. (Original from <https://greasyfork.org/en/scripts/16553-twitter-auto-refresh/code?locale_override=1%27A%3D0%27>)
// @author Larry Costigan
// @match https://twitter.com/*
// @grant none
// @downloadURL https://gist.github.com/larryc5/0605f29df9e4dcf2dd8608c13f87f231/raw/twitter-auto-refresh.user.js
// @updateURL https://gist.github.com/larryc5/0605f29df9e4dcf2dd8608c13f87f231/raw/twitter-auto-refresh.meta.js
@lac5
lac5 / youtube-playlist-info.meta.js
Last active June 17, 2024 15:04
Utility for getting information about a playlist. Type `window[Symbol.for('userscript::PlaylistInfo')]` in your console to use the functions.
// ==UserScript==
// @name YouTube - Playlist Info
// @namespace larryc5
// @version 1.0
// @description Utility for getting information about a playlist. Type `window[Symbol.for('userscript::PlaylistInfo')]` in your console to use the functions.
// @author Larry Costigan
// @match http://www.youtube.com/*
// @match https://www.youtube.com/*
// @grant none
// @downloadURL https://gist.githubusercontent.com/larryc5/585b4bd176385894900a81d53a7dec7f/raw/youtube-playlist-info.user.js
@lac5
lac5 / youtube-anti-anti-afk.meta.js
Last active June 17, 2024 15:04
Stops YouTube from automatically pausing the video.
// ==UserScript==
// @name YouTube - Anti-Anti-AFK
// @namespace larryc5
// @version 1.0
// @description Stops YouTube from automatically pausing the video.
// @author Larry Costigan
// @include /^https?:\/\/(?:[^\/?#]*\.)?youtube.com\/.*$/
// @downloadURL https://gist.githubusercontent.com/larryc5/95c3ae2abbd37b35e2a35ac2c49d9996/raw/youtube-anti-anti-afk.user.js
// @updateURL https://gist.githubusercontent.com/larryc5/95c3ae2abbd37b35e2a35ac2c49d9996/raw/youtube-anti-anti-afk.meta.js
// ==/UserScript==
%YAML1.2
---
# Put this file somewhere Sublime Text can find it.
# For example: `%APPDATA%\Sublime Text 3\Packages\User` on Windows.
# Then replace `comments` in whatever sublime-syntax file with this:
#
# comments:
# - match: (?=/\*)|(?=//)
# push: Packages/User/{name of this file}
#
export function now() {
let time = process.hrtime();
let date = BigInt(Date.now() - time[0] * 1000 - Math.floor(time[1] / 1000000));
date *= 1000000n;
date += BigInt(time[0]) * 1000000000n;
date += BigInt(time[1]);
return date;
}
/**
* Turns standard callback functions into promises.
* Useful for async functions.
*
* Example:
* (async ()=> {
* var file = await p(f => fs.readFile('file.txt', f));
* file += 'modified';
* console.log(file);
* await p(f => fs.writeFile, 'file-modified.txt', f));
@lac5
lac5 / node-handlebars-worker.js
Created September 17, 2019 15:51
`worker_thread` example
/**
* @file This creates a worker thread that only handles template rendering.
* The purpose is to keep the main thread free so that processes like
* rendering don't block the event loop.
*/
const {
Worker, isMainThread, parentPort
} = require('worker_threads');
export function getWeek() {
let date = this;
let thisThu = new Date(date.valueOf() + ((7 - date.getDay()) % 7 - 3) * 86400000);
let firstDay = new Date(thisThu.getFullYear(), 0, 1);
return Math.ceil((thisThu.valueOf() - firstDay.valueOf() + 86400000) / 604800000);
}
export function getUTCWeek() {
let date = new Date();
if (date.getHours() < 5) {
date.setDate(date.getDate() - 1);
}
let thisThu = new Date(date.valueOf() + ((7 - date.getDay()) % 7 - 3) * 86400000);
let firstDay = new Date(thisThu.getFullYear(), 0, 1);
let year = thisThu.getFullYear();
let week = Math.ceil((thisThu.valueOf() - firstDay.valueOf() + 86400000) / 604800000);
let dow = date.getDay() || 7;