Skip to content

Instantly share code, notes, and snippets.

@shaybensasson
shaybensasson / gnome-terminal
Last active November 7, 2021 14:45
Opening a new tab in an existing GNOME terminal window
#!/bin/bash
# from here: https://planet.jboss.org/post/opening_a_new_tab_in_an_existing_gnome_terminal_window
# Path: /usr/local/bin/gnome-terminal
if [ "x$*" != "x" ]; then # any args?
/usr/bin/gnome-terminal "$@"
exit 0
fi
# first, inspect the current window
@shaybensasson
shaybensasson / extract_filename_and_ext.sh
Created July 6, 2020 06:40
bash script that extract filename and extension from a parameter
#!/bin/bash
set -e
# Any subsequent(*) commands which fail will cause the shell script to exit immediately
input=$1
#filename=$(basename -- "$fullfile")
#extension="${filename##*.}"
#filename="${filename%.*}"
@shaybensasson
shaybensasson / my_snippets.js
Last active June 14, 2022 17:54
My Jupyter nbextension "Snippets Menu" json configuration
var MY_SNIPPETS = {
'name': 'Snippets',
'sub-menu': [
{
'name': 'config file',
'snippet': ['!cat ~/.local/share/jupyter/nbextensions/snippets_menu/my_snippets.js']
},
'---',
{
'name': 'Header',
@shaybensasson
shaybensasson / tmuxcolors.sh
Created April 18, 2020 08:25
print all tmux configurable colors
# https://superuser.com/a/1104214/362338
for i in {0..255}; do printf "\x1b[38;5;${i}mcolor%-5i\x1b[0m" $i ; if ! (( ($i + 1 ) % 8 )); then echo ; fi ; done
@shaybensasson
shaybensasson / tmuxcolors.sh
Created April 18, 2020 08:25
print all tmux configurable colors
# https://superuser.com/a/1104214/362338
for i in {0..255}; do printf "\x1b[38;5;${i}mcolor%-5i\x1b[0m" $i ; if ! (( ($i + 1 ) % 8 )); then echo ; fi ; done
@shaybensasson
shaybensasson / avascriptBeautify.sublime-settings
Created April 10, 2020 02:06
/home/shay/.config/sublime-text-3/Packages/User/JavascriptBeautify.sublime-settings
{
"indent_size": 4,
"indent_char": " ",
"indent_level": 0,
"indent_with_tabs": false,
"preserve_newlines": true,
"max_preserve_newlines": 10,
"jslint_happy": false,
"brace_style": "expand",
"keep_array_indentation": false,
@shaybensasson
shaybensasson / stdout_console_file.py
Created April 3, 2020 18:32
When using print() write to console and file
#from here: https://stackoverflow.com/a/49197110/1640414
from contextlib import closing
from IPython.utils.io import Tee
print('This is not in the output file.')
with closing(Tee("/tmp/outputfile.log", "w", channel="stdout")) as outputstream:
print('This is written to the output file and the console.')
@shaybensasson
shaybensasson / pprint_color.py
Last active March 16, 2021 08:18 — forked from EdwardBetts/pprint_color.py
Python pprint with color syntax highlighting for the console (adapted for python3.6)
from pprint import pformat
from pygments import highlight
from pygments.formatters.terminal256 import Terminal256Formatter
from pygments.lexers.python import PythonLexer
def pprint_color(obj):
print(highlight(pformat(obj), PythonLexer(), Terminal256Formatter()))
@shaybensasson
shaybensasson / tqdm_interval_report.py
Last active April 1, 2020 19:04
tqdm that updates only when an interval is reached
import time
from tqdm.auto import tqdm
class TqdmIntervalReport(tqdm):
"""
`tqdm` that updates only when an interval is reached
based on snippet from https://github.com/tqdm/tqdm
@shaybensasson
shaybensasson / hfnano.sh
Last active March 23, 2020 21:56
edit HUGE text files selectively using nano
#!/bin/sh
# From here: https://stackoverflow.com/a/29269913
# by: https://stackoverflow.com/users/122422/b-t
# based on: https://stackoverflow.com/a/6874645/1640414
# Usage: hfnano.sh yourHugeFile 3 8
# hint: put in your /usr/bin
if [ "$#" -ne 3 ]; then
echo "Usage: $0 hugeFilePath startLine endLine" >&2
exit 1