Skip to content

Instantly share code, notes, and snippets.

View coldfix's full-sized avatar
:octocat:
Wrrrao!

Thomas G. coldfix

:octocat:
Wrrrao!
View GitHub Profile
@coldfix
coldfix / ZSH.md
Created October 20, 2021 10:31 — forked from YumaInaura/ZSH.md
Zsh — print command examples ( with help document )

Zsh — print command examples ( with help document )

print is zsh law layer command.

For example it probably build zle command behaviour.

If you master it you will get so beautifule zsh style.

Examples

Recovering deleted files in Ubuntu with ext4 filesystem

Recently, I deleted some files by mistake in a Ubuntu machine with an ext4 fs. These notes document the steps I took to get them back.

Important

  • this procedure assumes that the partition that contained the deleted files is different from the root partition, as that was the scenario with which I had to deal (deleted files were in my home dir). The procedure needs that the partition that contained the files is unmounted, so if the deleted files were in the root partition, the process would be a bit different (e.g. storing the fs journal in a USB stick, using a live CD/USB to boot and issue the commands, etc.)
  • if something is not clear, you need more information, etc. check the sources below

With that out the way, let's begin.

@coldfix
coldfix / template.sh
Created August 28, 2020 11:15
Simple `sh` template substitution script
#! /usr/bin/env bash
# Substitutes shell-like templates in input files.
#
# Usage:
# template.sh [-x COMMAND] [-f FILE] [VAR=value]...
#
# Options:
# -f FILE Read template from this file [default: -]
# -x COMMAND Send output to this command [default: cat]
#!/bin/ash
#ash shell for openwrt, it also works with bash
#curl -s 192.168.44.1/logout
rURL=`curl -s -I "http://192.168.44.1" | grep "Location:" | cut -d : -f 2- | cut -c 2-`
if echo $rURL | grep -q "res=notyet"; then
echo "notyet"
challenge=`echo $rURL | cut -d '&' -f 4 | cut -d= -f2`
echo "challenge=$challenge"
@coldfix
coldfix / pre-commit
Last active September 7, 2018 13:22
pyflakes precommit hook, checks the index directly, needs importable pyflakes
#!/usr/bin/env python
import sys
import re
from subprocess import check_output, PIPE
import pyflakes.api
def git_file_content(fname):
@coldfix
coldfix / alttexdoc
Last active February 6, 2017 00:04
primitive texdoc replacement for when you don't have latex documentation installed on disk
#! /bin/zsh
prefix=$HOME/.texdoc
pkg=$1
doc=$(hrefbytext http://ctan.org/pkg/$pkg 'Pack­age doc­u­men­ta­tion') &&
mkdir -p $prefix
cache=$prefix/$(basename $doc) && (
if [[ ! -e $cache ]]; then
wget $doc -O $cache
fi
) &&
import numpy as np
from timeit import timeit
def timing(neg_ratio=0.5):
a0 = np.random.uniform(0, 1, 20000000) - neg_ratio
globals = {
'a0': a0,
'np': np,
}
@coldfix
coldfix / msys2.reg
Last active August 29, 2024 02:58 — forked from magthe/msys2.reg
MSYS2 "Open Here" registry settings
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\mingw32]
@="MinGW &32 Bash Here"
"Icon"="\"C:\\msys64\\mingw32.exe\""
[HKEY_CLASSES_ROOT\Directory\Background\shell\mingw64]
@="MinGW &64 Bash Here"
"Icon"="\"C:\\msys64\\mingw64.exe\""
@coldfix
coldfix / monitor_process_ram.zsh
Created March 22, 2016 16:28
Monitor RAM usage and runtime of a previously started process (using ugly hardcoding)
#! /usr/bin/zsh
if [[ $# = 0 ]]; then
echo "Usage: $0 PID [INTERVAL]"
exit
fi
pid=$1
pgid=$(ps -o pgid= $pid)