Skip to content

Instantly share code, notes, and snippets.

@andreyshuster
andreyshuster / gist:4f1dd6cc0289746e95a8
Created March 7, 2016 08:05
delete emacs temp files
find ./ -name '*~' -exec rm '{}' \; -print -or -name ".*~" -exec rm {} \; -print
@andreyshuster
andreyshuster / gist:1264c8502ce0fa6b2206c75602b116c1
Created August 13, 2017 09:23
oneliner rename files in folder to sequental numbers
a=1; for file in *.jpg; do mv "$file" "${a}.jpg"; let a=a+1; done
@andreyshuster
andreyshuster / gist:ea5e79d06ff6e36680f2608306b4b2be
Last active February 20, 2019 14:09
top ten shell commands
#!/usr/bin/env sh
history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n 10

Convert all ebooks in folder to mobi

for file in *.fb2; do ebook-convert "$file" "$file.mobi"; done

Add all untracked files to .gitignore

git status -s | grep -e "^\?\?" | cut -c 4- >> .gitignore

Find all folders older than certain date(Useful to find old projects)

find . -type d  -d 1 -not -newermt "2020-09-01 00:00:00"
@andreyshuster
andreyshuster / psql.md
Last active May 24, 2022 02:56
[PGSQL]Get rows count from all tables
SELECT schemaname,relname,n_live_tup
FROM pg_stat_user_tables
ORDER BY n_live_tup DESC;
@andreyshuster
andreyshuster / rotate_matrix.md
Last active July 27, 2022 16:41
Rotate matrix oneliner
list(zip(*original[::-1]))
@andreyshuster
andreyshuster / gist:27ccc3a2d8537c817df3a6d60af23109
Last active May 4, 2022 18:56
How to output result of psql query to a file

From PSQL console

$ psql <postgres connection string>
=> \o result-filename.txt
=> SELECT * from the table

Another variant (CSV export)

@andreyshuster
andreyshuster / import-csv-to-sqlite.md
Last active July 27, 2022 16:53
import csv to sqlite db
> .mode csv
> .import file_name.csv table_name