Skip to content

Instantly share code, notes, and snippets.

View MaxXx1313's full-sized avatar

Maksim Chartkou MaxXx1313

View GitHub Profile
@MaxXx1313
MaxXx1313 / snap-autoremove.sh
Last active March 12, 2025 08:10
Removes old revisions of snaps
#!/bin/bash
# Removes old revisions of snaps
# CLOSE ALL SNAPS BEFORE RUNNING THIS
set -eu
LANG=C snap list --all | awk '/disabled/{print $1, $3}' |
while read snapname revision; do
snap remove "$snapname" --revision="$revision"
done
@MaxXx1313
MaxXx1313 / expressPromise.ts
Created July 21, 2020 13:14
Can return promise from express middleware
/**
* Can return promise from express middleware
* router.get('/pets', expressPromise(req => {
return db.getAll().then(... do some stuff...); // <it's a Promise!
}));
*/
export function expressPromise(worker: (req: Request) => any) {
return (req: Request, res: Response, next: NextFunction) => {
// wrap with "Promise.resolve()", so if an exception is thrown in "worker" it will be handled with 'catch'
Promise.resolve()
@MaxXx1313
MaxXx1313 / subl
Created June 11, 2020 13:03
run sublime text from terminal on Mac
# /usr/local/bin/subl
open -b com.sublimetext.3 "$@"
@MaxXx1313
MaxXx1313 / script.sh
Created June 4, 2020 21:49
git check if any file is changed
#
hasChanges=$(git diff-index --name-only HEAD --)
if [ -n "$hasChanges" ]; then
echo -e "*** Git repository is not clean!"
gitSha="$gitSha-DIRTY"
fi
@MaxXx1313
MaxXx1313 / get-age.ts
Last active May 20, 2020 11:49
Calculate age in years
/**
*
*/
export function getAge(now: Date, birthday: Date): number {
// trick to ignore year
const backToFuture = new Date(now.getTime());
backToFuture.setFullYear(birthday.getFullYear());
// 'now' and 'dateNoYear' has the same year, so it wouldn't affect the result
// check month to avoid leap year issue
@MaxXx1313
MaxXx1313 / index.js
Created August 5, 2019 09:11
Enable global media keys in vk.com (tampermonkey)
// ==UserScript==
// @name Enable global media keys in vk.com
// @namespace http://github.com/MaxXx1313
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://vk.com/*
// @grant none
// ==/UserScript==
@MaxXx1313
MaxXx1313 / fetchFile.js
Created February 7, 2019 15:57
Cordova read file
window.fetchFile = function(fileName) {
function getFileEntry(fullFileName) {
return new Promise((resolve, reject) => {
window.resolveLocalFileSystemURL(fullFileName, resolve, reject);
});
}
@MaxXx1313
MaxXx1313 / getDPI.js
Created January 29, 2019 16:02
Get DPI from javascript (live at: https://jsfiddle.net/bsorrentino/s8c51jvt/)
//
// inspired by https://stackoverflow.com/a/838755/521197
//
function getDPI() {
var div = document.createElement( "div");
div.style.height = "1in";
div.style.width = "1in";
div.style.top = "-100%";
div.style.left = "-100%";
div.style.position = "absolute";
module.exports.filenameReservedRegex = () => (/[<>:"\/\\|?*\x00-\x1F]/g);
module.exports.windowsNames = () => (/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/i);
@MaxXx1313
MaxXx1313 / restore.sh
Created October 10, 2018 15:49
restore desctop resolution after wine
#!/bin/bash
xrandr -s 0