Skip to content

Instantly share code, notes, and snippets.

@yuryshulaev
yuryshulaev / let_chain.rs
Last active January 29, 2023 14:43
Rust macro to conveniently bind temporary value in a chain to a temporary variable
// error[E0716]: temporary value dropped while borrowed
// --> src/main.rs:21:14
// |
// 21 | let upper = "abc".to_uppercase().as_str();
// | ^^^^^^^^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
// | |
// | creates a temporary which is freed while still in use
// 22 | println!("{}", upper);
// | ----- borrow later used here
// |
[
{
"type": "template",
"name": "about",
"parameters": {},
"positionalParameters": [
["domestic cats"],
["the cat family"],
["Felidae"],
["the musical"],
Cats, also called domestic cats (Felis catus), are small, carnivorous mammals, of the family Felidae.
Domestic cats are often called 'house cats' when kept as indoor pets. Cats have been domesticated (tamed) for nearly 10,000 years.
They are one of the most popular pets in the world. They are kept by humans for hunting rodents and as companions.
There are also farm cats, which are kept on farms to keep rodents away; and feral cats, which are domestic cats that live away from humans.
A cat is sometimes called a kitty. A young cat is called a kitten. A female cat that has not had its sex organs removed is called a queen. A male cat that has not had its sex organs removed is called a tom.
@yuryshulaev
yuryshulaev / apk-large.py
Last active November 6, 2021 16:20
Alpine Linux: List installed apk packages sorted by size
#!/usr/bin/env python3
import subprocess
UNITS = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB']
def human_readable_size_to_bytes(size_str):
size, unit = size_line.split()
return int(size) * (1 << (UNITS.index(unit) * 10))
def chunks(lst, n):
@yuryshulaev
yuryshulaev / kill-sticky.js
Created October 23, 2015 00:28 — forked from alisdair/kill-sticky.js
Kill sticky headers.
// ==UserScript==
// @name Kill Sticky Headers (Ctrl/Cmd+Shift+K)
// @homepage http://alisdair.mcdiarmid.org/kill-sticky-headers/
// @version 0.1
// @description Kill sticky headers
// @match *://*/*
// @grant none
// ==/UserScript==
function killSticky() {
@yuryshulaev
yuryshulaev / youtube-global-shortcuts.user.js
Last active May 20, 2021 12:52 — forked from stefansundin/youtube-global-shortcuts.user.js
Makes the YouTube shortcuts work even if the player is not focused. Install Greasemonkey/Tampermonkey first, then click [Raw] to install.
// ==UserScript==
// @name YouTube global shortcuts
// @namespace https://gist.github.com/stefansundin/
// @homepage https://gist.github.com/stefansundin/65e3d6db697636d8e7f1
// @downloadURL https://gist.github.com/stefansundin/65e3d6db697636d8e7f1/raw/youtube-global-shortcuts.user.js
// @version 1.1
// @author Stefan Sundin
// @description Makes the YouTube shortcuts work even if the player is not focused.
// @icon https://www.youtube.com/favicon.ico
// @match https://www.youtube.com/*
'use strict'
// babel countfiles_es7.js -o countfiles_es7.out.js --optional runtime --source-maps inline
require('source-map-support').install();
import Promise from 'bluebird';
import path from 'path';
let fs = Promise.promisifyAll(require('fs'));
@yuryshulaev
yuryshulaev / DragScroll.user.js
Last active May 11, 2020 04:42
Greasemonkey drag-style scrolling userscript
// ==UserScript==
// @name DragScroll
// @include *
// @version 1
// @grant none
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js
// ==/UserScript==
(function ($) {
var dragging = false;
@yuryshulaev
yuryshulaev / .zshrc
Last active December 19, 2017 11:28
.zshrc with parent directory traversal shortcuts (Ctrl+Up — pushd .., Ctrl+Down — popd)
cd_parent_dir() {
[[ $(dirs | cut -f 1 -d ' ') != $(readlink -f `pwd`/..) ]] && pushd -q ..
zle reset-prompt
# print -Pn "\e]0;%~\a" # Tab title
}
cd_back() {
[[ $(dirs -v | wc -l) -ne 1 ]] && popd -q
zle reset-prompt
# print -Pn "\e]0;%~\a" # Tab title