Skip to content

Instantly share code, notes, and snippets.

@Gosha
Gosha / ranger-insert-files-widget.plugin.zsh
Last active May 14, 2021 22:01
Insert file paths chosen with ranger
# Insert file paths chosen with ranger
# Default bound to <c-p>
# If cursor is on a file, press either <enter> or <a-enter> to finish
# If cursor is on a directory, press <a-enter> to finish
ranger-insert-files-widget () {
local tmpfile=$(mktemp)
ranger --choosefiles=${tmpfile} --cmd "map <a-enter> execute_file a" < $TTY
local files=$(cat $tmpfile | while read line
do
local item=$(realpath --no-symlinks --relative-to=$(pwd) "${line}")
@Gosha
Gosha / build-native.sh
Created June 25, 2020 21:40
repro-segfault-nix-osx-IOKit
#!/bin/bash
set -e
echo ================ build
"/nix/store/71lbsnxpbnqkhndcxg1fcwxvjxmviqlg-clang-7.1.0/bin/clang-7" \
-cc1 \
-triple x86_64-apple-macosx10.12.0 \
-Wdeprecated-objc-isa-usage \
-Werror=deprecated-objc-isa-usage \
-emit-obj \
-disable-free \
@Gosha
Gosha / .dockerignore
Last active November 1, 2018 14:18
Graylog Exception Reproduction
obj/
bin/
out/
.git/
.vscode/
@Gosha
Gosha / higher_order.py
Created February 28, 2015 19:22
Simple example of a higher order function
#!/usr/bin/env python3
# A classic example:
# create_increaser_by(num) returns a new function, the returned function adds num to it's arg
def create_increaser_by(num):
# This function is weirdly named because it's returned later on.
# It's not the name it will be called by
def _return_fun(arg):
return arg + num

Keybase proof

I hereby claim:

  • I am Gosha on github.
  • I am gosha (https://keybase.io/gosha) on keybase.
  • I have a public key whose fingerprint is E33A D016 21C4 5F21 67F3 27AE ED56 EA90 C2BE 6C14

To claim this, I am signing this object:

@Gosha
Gosha / binary-to-text.sh
Created October 7, 2014 00:03
Convert binary to text in bash
#!/bin/bash
BINARY="01001000
01100101
01101100
01101100
01101111"
binaryToText() {
while read line
do
@Gosha
Gosha / image_ratio.sh
Last active August 29, 2015 14:07
Calculate the aspect ratio of an image
#!/bin/bash
# Called with ./image_ratio.sh IMAGEFILE
# convert is from ImageMagick
image_width () {
convert "$1" -format "%w" info:
}
image_height () {
convert "$1" -format "%h" info:
}
@Gosha
Gosha / is_even_odd
Created February 14, 2014 11:40
Mututal recursion from wikipedia
# http://en.wikipedia.org/wiki/Mutual_recursion
bool is_even(unsigned int n)
if (n == 0)
return true;
else
return is_odd(n - 1);
bool is_odd(unsigned int n)
if (n == 0)