Skip to content

Instantly share code, notes, and snippets.

View vadimkantorov's full-sized avatar
💭
looking for an internship for summer/fall 2021

Vadim Kantorov vadimkantorov

💭
looking for an internship for summer/fall 2021
View GitHub Profile
@vadimkantorov
vadimkantorov / backup_gmail.py
Last active October 20, 2018 11:30
Backups all GMail emails+attachments from a given label AND from a given sender.
import argparse
import imaplib
import email
import os
parser = argparse.ArgumentParser(description = 'Backup GMail mailbox. Turn on less secure apps before running https://www.google.com/settings/security/lesssecureapps')
parser.add_argument('--username', required = True)
parser.add_argument('--password', required = True)
parser.add_argument('-o', default = '.')
parser.add_argument('--label', default = 'INBOX')
import sys
import psutil
import subprocess
import datetime
import time
bashScriptPath = sys.argv[1]
stdoutPath, stderrPath = sys.argv[2:] or (None, None)
peakRssBytes = 0
@vadimkantorov
vadimkantorov / scan_png.ps1
Created February 10, 2015 01:02
A PowerShell script to acquire an image from a scanner and to save it in PNG
$deviceManager = new-object -ComObject WIA.DeviceManager
$device = $deviceManager.DeviceInfos.Item(1).Connect()
$wiaFormatPNG = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}"
foreach ($item in $device.Items) {
$image = $item.Transfer($wiaFormatPNG)
}
if($image.FormatID -ne $wiaFormatPNG)
{
@vadimkantorov
vadimkantorov / install_ubuntu_package_locally_without_root.sh
Last active September 12, 2016 19:35
A script to download and unpack and use Ubuntu packages without root permissions
#! /bin/bash
# Usage example: bash install_ubuntu_package_locally_without_root.sh libopencv-dev ~/deb
# Author: Vadim Kantorov
# Add the following exports to your .bashrc or .profile to use the unpacked packages
# export PATH=$HOME/deb/usr/bin:$PATH
# export LD_LIBRARY_PATH=$HOME/deb/usr/lib:$HOME/deb/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH
# export CPATH=$HOME/deb/usr/include:$CPATH
# export LIBRARY_PATH=$LIBRARY_PATH:$LD_LIBRARY_PATH
@vadimkantorov
vadimkantorov / pip.sh
Created March 25, 2015 14:09
A script to install pip packages locally
#! /bin/bash
# Usage example: bash pip.sh ipython
# Add the following export to your .bashrc or .profile to use the unpacked packages
# export PYTHONPATH=$HOME/user_lib/pip_user/lib/python2.7/site-packages:$PYTHONPATH
INSTALL_DIR=$HOME/user_lib/pip_user
mkdir -p $INSTALL_DIR
PYTHONUSERBASE=$INSTALL_DIR pip install --user "$@"
open Microsoft.FSharp.Data.UnitSystems.SI.UnitNames
open Microsoft.FSharp.Data.UnitSystems.SI.UnitSymbols
[<Measure>]
type mm =
static member perMeter = 1e+3<mm/m>
let pi = System.Math.PI
let epsilon_0 = 8.854187817e-12<F m^-1>
let elementary_charge = 1.602176565e-19<coulomb>
@vadimkantorov
vadimkantorov / matlab_embed_figure_in_html.m
Last active August 19, 2016 15:46
A Matlab snippet to output Base64-encoded img's to be used for HTML visualizations
f = figure();
plot(1:10, 1:10);
rgbData = figToImStream('figHandle', f, 'imageFormat', 'jpg', 'outputType', 'uint8');
%print(f, '-djpg', '/tmp/vis.jpg'); rgbData = fread(fopen('/tmp/vis.jpg'), 'uint8=>uint8'); % replace previous line by this line in case of failure
fprintf('<img src="data:image/jpeg;base64,%s" />', char(org.apache.commons.codec.binary.Base64.encodeBase64(rgbData))');
close(f);
@vadimkantorov
vadimkantorov / loadmatconvnet.lua
Last active October 29, 2017 20:47
A routine to convert some MatConvNet layers to Torch
-- example for an AlexNet-like model
--model, unconverted = loadmatconvnet('/path/to/somemodel.mat', {
-- conv2 = {groups = 2},
-- conv4 = {groups = 2},
-- conv5 = {groups = 2},
-- fc6 = {fc_kH = 6, fc_kW = 6, type = 'nn.Linear'}, --ONE MAY NEED TO BE CAREFUL, these fc_kH, fc_kW are for 1x36 (or 36x1, don't remember) saved weights
-- fc7 = {type = 'nn.Linear'},
--})
matio = require 'matio'
@vadimkantorov
vadimkantorov / debug_repl.lua
Last active January 3, 2022 15:41
A Lua repl that copies local variables onto globals for inspection
local torch_repl = repl
function repl(restoreGlobals)
-- copied from http://stackoverflow.com/questions/33068607/how-can-i-use-the-torch-repl-for-debugging
require 'trepl'
restoreGlobals = restoreGlobals or false
-- optionally make a shallow copy of _G
local oldG = {}
if restoreGlobals then
@vadimkantorov
vadimkantorov / timejson.sh
Last active February 3, 2023 23:11
A Bash alias that wraps /usr/bin/time to produce parsable JSON format output.
alias timejson='/usr/bin/time -f '"'"'{"exit_code" : %x, "time_user_seconds" : %U, "time_system_seconds" : %S, "time_wall_clock_seconds" : %e, "rss_max_kbytes" : %M, "rss_avg_kbytes" : %t, "page_faults_major" : %F, "page_faults_minor" : %R, "io_inputs" : %I, "io_outputs" : %O, "context_switches_voluntary" : %w, "context_switches_involuntary" : %c, "cpu_percentage" : "%P", "signals_received" : %k}'"'"