Skip to content

Instantly share code, notes, and snippets.

@verdimrc
verdimrc / bash.sh
Last active May 13, 2025 08:50
Various bash commands
# Convert ^M to \n in tqdm log file litterred with ^M
tr "\015" "\n" < inputfile > outputfile
# AWS CLI to handle utf-8 in S3 files.
# https://github.com/aws/aws-cli/issues/3902#issuecomment-513842630
export PYTHONIOENCODING=utf-8
aws s3 ls s3://...
# Exclude chars to generate random string that's compatible with expect.
EXCLUDED_CHAR="'\"\`\\[]{}()*#"
@verdimrc
verdimrc / sqlite.sh
Created November 18, 2016 05:03
Examples of sqlite commands
#!/bin/bash
cat << EOF > loadcsv.sql
.bail on
.load ./csv
EOF
rm hahadb.sqlite
sqlite3 hahadb.sqlite < 00-create-table.sql
sqlite3 -init loadcsv.sql hahadb.sqlite
@verdimrc
verdimrc / sqlite.sql
Created November 18, 2016 05:05
sqlite SQL
-- Show all tables
.schema
-- Show DDL of a specific table
.schema table1
-- Show columns
pragma table_info(t1)
@verdimrc
verdimrc / sqlite-csvtab.sh
Created November 18, 2016 05:06
Patched csv module for sqlite ('\t' as field separator)
#!/bin/bash
wget -O csv.c https://www.sqlite.org/src/raw/ext/misc/csv.c?name=531a46cbad789fca0aa9db69a0e6c8ac9e68767d
PATCH_FILE=$(mktemp)
cat << EOF > $PATCH_FILE
--- csv.c 2016-11-17 18:41:12.567483787 +0000
+++ csv-patched.c 2016-11-17 18:41:03.931517320 +0000
@@ -226,7 +226,7 @@
continue;
def printcall(f):
def f_wrapper(*args, **kwargs):
print('Running {}...'.format(f.__name__))
retval = f(*args, **kwargs)
print('Finished {}.'.format(f.__name__))
return retval
return f_wrapper
# The rest are based on http://stackoverflow.com/a/14349742
class Foo(object):
@verdimrc
verdimrc / py36-conda.sh
Last active August 14, 2017 06:51
Install py36 on Ubuntu 17.04
#!/bin/bash
# Ubuntu 17.04, 16.10
# Download Miniconda3*.sh from miniconda website, then follow the installation
# instruction.
# NOTE:
# - do NOT sudo pip install conda, as this will not work with the latest conda!
# - we choose NOT to prepend miniconda3 to PATH.
@verdimrc
verdimrc / chnpropdeco.py
Last active May 4, 2017 07:23
A Python property decorator that can chain decorated property.
#!/home/verdi/miniconda3/bin/python3.6
'''
Demonstrate a property decorator that can chain decorated property.
For chaining to work, decoratee must be a plain function or a property with
fget attribute.
Sample outputs:
(py36) verdi@verdi-VirtualBox:/tmp$ ./haha.py
@verdimrc
verdimrc / config-nvidia-on-g3.4xlarge.sh
Last active October 2, 2017 08:40
config-nvidia-on-g3.txt
# g3.4xlarge has 1 GPU (NVIDIA M60).
# 1. Install nvidia grid driver: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-nvidia-driver.html
# 2. Activate grid feature: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/activate_grid.html
# 3. [OPTIONAL] Power mgmt & freq: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/optimize_gpu.html
# Verify the M60 gpu is running in graphics mode.
# See: https://virtuallyvisual.wordpress.com/2016/04/19/nvidia-m60-m6-problems-check-your-card-in-graphics-mode/
#
# If 0300 then graphics, else compute.
@verdimrc
verdimrc / deco.py
Last active December 22, 2017 21:13
Parameterized decorator that works on functions, and methods (instance, class, or static).
#!/usr/bin/env python3
'''
$ ./deco.py
Test methods...
self.rstate: type=<class 'str'>, value=asdf
self.rstate: type=<class 'int'>, value=123
Unknown rstate.payload: <class 'int'>
Unknown rstate.payload: <class 'str'>
Unknown rstate.payload: <class 'int'>
@verdimrc
verdimrc / ms-office-tips.txt
Created April 4, 2018 15:38
Various tips with MS Office
Insert a field for custom date property "Date completed", and display with the default format:
{ DOCPROPERTY "Date completed" \* MERGEFORMAT }
Insert a field for custom date property "Date completed", and display with a custom format:
{ DOCPROPERTY "Date completed" \@ "dd-MMMM-YYYY" }