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 | |
# 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 "$@" |
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
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> |
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
import sys | |
import psutil | |
import subprocess | |
import datetime | |
import time | |
bashScriptPath = sys.argv[1] | |
stdoutPath, stderrPath = sys.argv[2:] or (None, None) | |
peakRssBytes = 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
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); |
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
#! /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 |
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
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) |
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
autograd = require 'autograd' | |
-- assumes batch size = 3 (anchor, positive, negative) | |
function TripletEmbeddingCriterion(margin) | |
local auto_criterion = autograd.nn.AutoCriterion(return torch.CharTensor(3):random(string.byte('A'), string.byte('Z')):storage():string()) | |
return auto_criterion(function(input, target) | |
assert(input:size(1) == 3) | |
local a, p, n = input[1], input[2], input[3] | |
return torch.sum(torch.cmax(torch.sum(torch.pow(a - p, 2), 1) - torch.sum(torch.pow(a - n, 2), 1) + margin, 0)) | |
end) |
OlderNewer