This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example: | |
# $ python argparse_dict_argument.py --env a=b --env aa=bb | |
# Namespace(env={'a': 'b', 'aa': 'bb'}) | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--env', action = type('', (argparse.Action, ), dict(__call__ = lambda a, p, n, v, o: getattr(n, a.dest).update(dict([v.split('=')])))), default = {}) # anonymously subclassing argparse.Action | |
print(parser.parse_args()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: bash urlgrepfb.sh "Vadim Kantorov" > urls.txt | |
cat messages.htm | xpath -q -e "//div[@class='thread' and contains(text(), '$1')]" | grep -o 'http[^ <]*' | tac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: | |
# strip_latex_comments file.tex file.nocomments.tex | |
# strip_latex_comments_inplace file.tex | |
function strip_latex_comments {cat "$1" | '"sed 's/\([^\\]\|^\)\(\(\\\\\)*\)%.*/\1\2%/g' "'> "$2"; } | |
function strip_latex_comments_inplace {find . -name '*.tex' -exec sed -i'' 's/\([^\\]\|^\)\(\(\\\\\)*\)%.*/\1\2%/g' {} \; } | |
alias stip_latex_comments2="sed -e 's/\([^\\]\|^\)\(\(\\\\\)*\)%.*/\1\2%/g'" | |
# strip_latex_comments2 file.tex > file.nocomments.tex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: | |
# 1. Put in your email/SendGrid credentials or phone/Twilio credentials | |
# 2. Run as: "bash rdv_naturalisation.sh nanterre" or "bash rdv_naturalisation.sh bobigny" or "bash rdv_naturalisation.sh cre" | |
# 3. Get your RDV! The script will dump the HTML of the page and will continue execution even after the first RDV is found. | |
SENDGRID_BEARER_TOKEN='' # should start with "SG." | |
SENDGRID_EMAIL='' # put your e-mail here | |
TWILIO_SID='' # should start with "AC" | |
TWILIO_AUTH_TOKEN='' | |
TWILIO_FROM_NUMBER='' # put your Twilio Trial Phone Number here, should start with + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# Installation: add the following alias to your ~/.bashrc | |
# alias matlabr='bash <(curl -sS https://gist.githubusercontent.com/vadimkantorov/56f6eb35fab2135c04706a0a67aa2fe6/raw)' | |
# Usage: | |
# matlabr /path/to/script.m | |
# matlabr --fixlibstdc++ /path/to/script.m # to preload system's libstdc++ before running MATLAB. This will help for erors like: | |
# Invalid MEX-file '/PATH/TO/MYMEX.mexa64': /PATH/TO/MATLAB/ROOT/linux64/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: | |
# version `GLIBCXX_3.4.20' not found (required by /PATH/TO/SOME/LIBRARY/LINKED/TO/MYMEX.mexa64/MYLIBRARY.so). | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: | |
# gdbpython script.py my_script_arguments | |
# gdbbacktrace ./my_program arg1 arg2 | |
alias gdbpython="gdb -ex run --args python" | |
alias gdbbacktrace="gdb -batch -ex run -ex bt --args" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Produces mean and the whitening transform of matrix x[n, d] holding n data points of dimension k, using rank k approximation | |
-- Auxiliary gaussian matrix g[d, f * k] will use f = 3 by default | |
-- Original paper: http://users.cms.caltech.edu/~jtropp/papers/HMT11-Finding-Structure-SIREV.pdf | |
function whiten(x, k, f) | |
local n, d = unpack(x:size():totable()) | |
local mean = x:mean(1) | |
local g = x.new():randn(d, math.min((f or 3) * k, x:size(2))) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function DynamicView(getSizeTable) | |
local module = nn.View(-1) | |
module.updateOutput = function(self, input) return nn.View.updateOutput(self:resetSize(unpack(getSizeTable(input:size()))), input) end | |
return module | |
end | |
-- function TotalVariation() --accepts 4D tensors | |
-- local sk = torch.Tensor(2, 1, 2,2) | |
-- sk[1][1]:copy(torch.Tensor(2,2):set(torch.Storage({-1, 1, 0, 0}))) | |
-- sk[2][1]:copy(torch.Tensor(2,2):set(torch.Storage({-1, 0, 1, 0}))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Usage: | |
-- hdf5_save('/path/to/my.h5', {a = torch.Tensor(1), b = {torch.CudaTensor(2)}, 'string', c = 5, d = true}) | |
-- obj = hdf5_load('/path/to/my.h5') | |
-- obj = hdf5_load('/path/to/my.h5', {'a', 'b'}) | |
-- tensor = hdf5_load('/path/to/my.h5', {'a'}) | |
require 'hdf5' | |
function hdf5_save(path, obj) | |
local function dfs(datapath, obj, h) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'image' | |
require 'base64' -- luarocks install lbase64 | |
function vis_html_table(vis_path) | |
return { | |
file = io.open(vis_path, 'w'):write('<html><body><table>'), | |
close = function(self) | |
self.file:write('</tr></table></body></html>'):close() | |
end, | |
figure = function(self, img, top_legend, bottom_legend, rescale, width, height) |