# Clipboard
To copy text to the local clipboard, pipe data to the appropriate command.
## Local shells
- macOS: `echo "text" | pbcopy`
- Linux (X11): `echo "text" | xclip -selection clipboard`
- Windows: `echo "text" | clip`
- WSL2: `echo "text" | clip.exe`
During a collaborative session with ChatGPT, I came up with a modern MySQL query to calculate the median value of a set of data. It leverages the window function ROW_NUMBER() introduced in MySQL 8.0. For this reason, it won't run on MySQL 5.7 or older versions.
The median is an extremely useful metric, especially when analyzing data sets representing response times, latencies or error rates. Unlike the average, it is resistant to being skewed by outliers.
To get the median of a data set, we need to sort the data and take the value of the middle row (if the number of rows is odd), or the average of the two middle numbers (if the number of rows is even).
All the median calculation MySQL queries I found online seemed crude, relying on user-defined variables, string concatenation via GROUP_CONCAT() and/or multiple subqueries. I find this approach much cleaner.
As of June 2023, [MariaDB is currently the only fork of MySQL that has native MEDIAN() and PERCENTILE_CONT() functions](https://mariadb.com/kb/en/media
| // A package for running jobs synchronized across multiple processes | |
| // Based on percolate:synced-cron, but modified to use MySQL | |
| // https://github.com/percolatestudio/meteor-synced-cron | |
| /*You must create a cron_history table in your MySQL database with the following schema: | |
| CREATE TABLE `cron_history` ( | |
| `id` int(10) unsigned NOT NULL AUTO_INCREMENT, | |
| `intendedAt` timestamp NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | |
| `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, |
| #!/bin/sh | |
| # Files with the following extensions will be compressed with gzip | |
| GZFILETYPES=( "*.html" "*.css" "*.js" "*.ico" "*.xml" "*.json" "*.svg" "*.otf" "*.ttf" "*.eot" ) | |
| # The base directory of the Meteor production bundle assets that are served to the client | |
| DIRECTORIES="/var/www/meteor/production/bundle/programs/web.browser/" | |
| # Files smaller than this size (in bytes) will NOT be compressed as the gzip overhead usually makes them larger | |
| GZMINSIZE=150 | |
| for currentDir in $DIRECTORIES; do | |
| for f in "${GZFILETYPES[@]}"; do | |
| files="$(find $currentDir -iname "$f")"; |
| # Copy this file to /etc/systemd/system/ | |
| # Then run: | |
| # systemctl enable disable_transparent_huge_pages.service | |
| # systemctl start disable_transparent_huge_pages.service | |
| [Unit] | |
| Description=Disable transparent huge pages | |
| [Service] | |
| Type=oneshot | |
| ExecStart=/bin/sh -c "/usr/bin/echo never | /usr/bin/tee /sys/kernel/mm/transparent_hugepage/enabled" |
| //JavaScript implementation of winding number algorithm to determine whether a point is inside a polygon | |
| //Based on C++ implementation of wn_PnPoly() published on http://geomalgorithms.com/a03-_inclusion.html | |
| function pointInPolygon(point, vs) { | |
| const x = point[0], y = point[1]; | |
| let wn = 0; | |
| for (let i = 0, j = vs.length - 1; i < vs.length; j = i++) { | |
| let xi = vs[i][0], yi = vs[i][1]; | |
| let xj = vs[j][0], yj = vs[j][1]; |
| //Is Node.js reporting warning messages like this?: | |
| // | |
| // "Warning: Possible EventEmitter memory leak detected. 11 wakeup listeners added. Use emitter.setMaxListeners() to increase limit" | |
| // | |
| //The following code will intercept calls to addListener() and on() and print the type of event and generate an Error exception | |
| //With a stack trace to help you find the cause | |
| var EventEmitter = require('events').EventEmitter; | |
| const originalAddListener = EventEmitter.prototype.addListener; |