Skip to content

Instantly share code, notes, and snippets.

@fieldse
fieldse / grep_match_count.sh
Created Nov 15, 2020
Grep/zgrep: count matches across multiple files
View grep_match_count.sh
# Count occurences of KEYWORD across all files named [something].log
# Flag: -src
# Credit:
# https://superuser.com/questions/205591/show-the-matching-count-of-all-files-that-contain-a-word
grep -src KEYWORD *.log
# Example output:
# production.20201107.log:12
@fieldse
fieldse / todos-migrate.sh
Created Sep 29, 2020
Daily todo file migrator
View todos-migrate.sh
#!/bin/bash
# todos-migrate.sh
# Generate a todo file from template
template="$HOME/Templates/Todos.template"
target_dir="$HOME/Documents"
archive_dir="$HOME/Documents/todos"
filename="Todos.md"
# Today's file
@fieldse
fieldse / Get git file creation dates.md
Last active Dec 19, 2019
Bash one-liner: Print the file creation dates of all files in a Git repo directory
View Get git file creation dates.md

Situation:

You have a directory of files in a git repository and you want to extract their original creation dates. Git does not track file creation date metadata, but you can get the first time the file was added in a commit.

This one-liner will print the dates and filenames sorted, in column format.

One-liner:

WIDTH=35 ; for filename in * ; do created_date="$(git log -1 --format='%ai' --reverse $filename)" ; printf "%-${WIDTH}s |      %s \n" "$created_date" $filename ; done | sort
@fieldse
fieldse / gnome-plugin-install.sh
Last active Jan 31, 2019
GNOME utility: Install gnome-shell plugins from zip file commandline
View gnome-plugin-install.sh
#!/bin/bash
# gnome-shell-install
# Utility script to install gnome-shell plugin from zip
## Usage:
# Copy this file to your .local/bin directory and chmod +x [filename]
# From the directory where your downloaded GNOME shell plugin zip is, run
# gnome-plugin-install.sh [mypluginfilename.zip]
# License:
@fieldse
fieldse / javascript.json
Created Dec 13, 2018
VSCode snippet for javascript boxed block comment
View javascript.json
{
// Place your snippets for javascript here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
View calendar_ical.rb
# calendar_ical.rb
# Todo - date string format
def get_date_format(time_obj)
# Convert standard ruby datetime obj to ISO 8601 format
# time_obj - should be datetime object
# Time format:
# timestring.to_time.iso8601 # Incorrect format! We need 19970610T172345Z
# 1997 06 10 T 17 23 45 Z
@fieldse
fieldse / Firefox multiple profile setup steps.md
Last active Jul 8, 2021
How to Create a Portable Firefox and Run Multiple Profiles
View Firefox multiple profile setup steps.md
@fieldse
fieldse / Pytest - Capture print statements in Pytest modules from stdout using capsys parameter
Last active Sep 14, 2017
Python pytest + stdout: Capture messages sent to stdout / stderr from your functions with pytest capsys
View Pytest - Capture print statements in Pytest modules from stdout using capsys parameter
# test.py
# Print statements to pytest
# Capture messages sent to stdout / stderr from your functions,
# and test the output with a pytest unit test.
# tl;dr - use the capsys parameter in your test arguments
# extract the messages sent to stdout/stderr with capsys.readouterr()
@fieldse
fieldse / Features of good programming languages.md
Created Sep 13, 2017
Features of good programming languages
View Features of good programming languages.md

Features of good programming languages

Existing languages: Features and weaknesses

Go / simplicity

  • Go is simple, but missing some features
  • No general syntax
  • Had to make exceptional language for certain cases
@fieldse
fieldse / grepmatch.md
Created Sep 4, 2017
Show lines before and after a matching string with grep
View grepmatch.md

Grep to show the surrounding 2 lines before and after your match

grep 'some string to match' -B 2 -A 2 myfile.txt