Skip to content

Instantly share code, notes, and snippets.

View maxpatiiuk's full-sized avatar
🎆
Busy creating matrix

Max Patiiuk maxpatiiuk

🎆
Busy creating matrix
View GitHub Profile
@maxpatiiuk
maxpatiiuk / reduce.js
Created April 1, 2024 02:45
Remove blank, comment-only or import lines from a JavaScript source file
/**
* Remove blank, comment-only or import lines from a JavaScript source file.
*
* Perfect for getting a quick count of how many actual "content" lines there are in a file.
*
* @param {string} javaScript
* @returns string
*/
function reduce(javaScript) {
const reduced = javaScript
@maxpatiiuk
maxpatiiuk / bookPlayerYouTubeToHtml.js
Last active March 17, 2024 20:13
BookPlayer Youtube bookmarks to HTML
/**
* BookPlayer audiobook player for iOS has a bookmark export option.
* BookPlayer can be used to play YouTube videos downloaded using youtube-dl/yt-dlp.
* This small gist converts the txt BookPlayer bookmark export into an HTML page with
* links to the bookmarked YouTube videos to a correct position within the video
*/
// Content of the txt file of your BookPlayer bookmarks exported
// Example:
const textContent = `Chapter 2 / 18:31
@maxpatiiuk
maxpatiiuk / github_to_changelog.js
Created August 23, 2022 18:19
Convert Github Issue list to a markdown changelog
extractNumber = (href)=>href.match(/issues\/(?<number>\d+)/)?.groups.number;
categories = $$('a.markdown-title').map(v=>{
const href = v.href;
const title = v.textContent;
const number = extractNumber(href);
const formattedNumber = typeof number === 'string' ? `#${number}` : href;
const isBug = v.nextElementSibling.textContent.includes('type:bug');
return [isBug ? 'Fixed' : 'Added',`- ${title} ([${formattedNumber}](${href}))`];
}).reduce((total, [type,line])=>{
total[type] ??= [];
@maxpatiiuk
maxpatiiuk / user_agent_string.js
Last active May 20, 2022 20:23
Simple parser for user agent strings
// Using TypeScript here, but GitHub Gist does not have syntax highlighting for TypeScript
const f = {
maybe: <VALUE, RETURN>(
value: VALUE | undefined,
callback: (value: VALUE) => RETURN
): RETURN | undefined =>
typeof value === 'undefined' ? undefined : callback(value),
};
@maxpatiiuk
maxpatiiuk / google_calendar_calculator.js
Last active May 1, 2024 15:30
Calculate the total number of time spent on a given event in a given week
/*
* This sript is now deprecated as it is integrated into my Google Chrome extension,
* along with many Google Calendar power user features:
* https://chrome.google.com/webstore/detail/calendar-plus/kgbbebdcmdgkbopcffmpgkgcmcoomhmh
*/
/*
* Open Google Calendar in a Week view
* Open DevTools
* Paste this script
@maxpatiiuk
maxpatiiuk / goodreads_plotter.js
Last active April 23, 2023 14:31
Export Goodreads reading stats for plotting by Google Sheets
/*
* This script is now deprecated as it integrated into my Google Chrome extension:
* https://chrome.google.com/webstore/detail/goodreads-stats/hdpkeldenopncgodhpjdlpngmnaijpjf?hl=en&authuser=0
*
* The extension adds easy export functionality to Goodreads, along with plotting capabilities
*/
/*
* Open this page:
* https://www.goodreads.com/review/list/83169518?ref=nav_mybooks
@maxpatiiuk
maxpatiiuk / json_to_json_schema.js
Created November 20, 2021 23:16
Basic inference of JSON Schema from a JSON object
const c = require('/usr/local/lib/node_modules/clipboardy');
const resolve = (value) =>
Array.isArray(value)
? { type: 'array', items: resolve(value[0]) }
: typeof value === 'object'
? {
type: 'object',
properties: Object.fromEntries(
Object.entries(value).map(([key, value]) => [key, resolve(value)])
@maxpatiiuk
maxpatiiuk / Cache_query.php
Created June 24, 2020 15:49
A class that will execute the given SQL query, save the resulting data into a file and retrieve it
<?php
/*
* CACHE QUERY
* This class will execute the given SQL query, save the resulting data into a file and retrieve it
*
*
* CONFIGURATION
* Static method `config` accepts the following configuration parameters:
* working_directory - the location where the cache file as well as the misc file would be saved. Example: /Users/mambo/site/stats/
@maxpatiiuk
maxpatiiuk / unix_time_to_human_time.php
Last active April 23, 2023 14:34
Converts a given timestamp from the past into a useful human form
/*
* This script is now deprecated. Find a much better version at
* https://github.com/specify/specify7/blob/393538b081eb797beb502204cdea9311179361f6/specifyweb/frontend/js_src/lib/components/Atoms/Internationalization.ts#L129-L172
*
* Along with tests:
* https://github.com/specify/specify7/blob/393538b081eb797beb502204cdea9311179361f6/specifyweb/frontend/js_src/lib/components/Atoms/__tests__/internationalization.test.ts#L64-L120
*/
function unix_time_to_human_time($time){
@maxpatiiuk
maxpatiiuk / user_agent_strings.php
Last active February 27, 2021 14:37
A small PHP function that gets a browser name and the os from the user agent string
<?php
define('DEFAULT_OS','Unknown OS');
define('DEFAULT_BROWSER','Unknown Browser');
function identify_data_from_user_agent_string($user_agent_string){
$os = '';
$browser = '';