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
# Download Makefile and .gitignore to a new project: | |
# wget -O Makefile -nv --no-check-certificate https://gist.githubusercontent.com/vadimkantorov/27ee19d130c413073bedd627c1b6a41e/raw/ && wget -O .gitignore -nv --no-check-certificate https://gist.github.com/vadimkantorov/27ee19d130c413073bedd627c1b6a41e/raw/.gitignore | |
# To install TexLive (including on WSLv1): sudo apt-get install -y texlive-latex-base texlive-latex-extra texlive-fonts-recommended make | |
# https://gist.github.com/vadimkantorov/27ee19d130c413073bedd627c1b6a41e | |
NAME = $(notdir ${CURDIR})# conferenceYEAR | |
$(NAME).pdf $(NAME).bbl: $(NAME).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
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) |
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: python thumbnail_video_collection.py /path/to/video/dir > thumbnail.html | |
import os | |
import sys | |
import json | |
import subprocess | |
import datetime | |
import argparse | |
parser = argparse.ArgumentParser() |
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
-- A is a matrix n x d, B is a matrix m x d, i.e. data points are row vectors; returns a matrix n x m | |
function pdist(A, B) | |
local eps = 1e-6 | |
local pdist2 = A * B:t() | |
local normA = torch.sum(torch.cmul(A, A), 2):view(pdist2:size(1), 1):expandAs(pdist2) | |
local normB = torch.sum(torch.cmul(B, B), 2):t():view(1, pdist2:size(2)):expandAs(pdist2) | |
return torch.sqrt(normA - 2.0 * pdist2 + normB + eps) | |
end |
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
attrdict = type('attrdict', (dict, ), dict(__getattr__ = dict.__getitem__, __setattr__ = dict.__setitem__)) | |
# d = attrdict(a = 1, b = 2) | |
# print(d.a, d['b']) |
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
# Bash aliases. | |
# Usage: pytrace my.py --myarg1 | |
# cprofile my.py --myarg1 | |
# lineprofile my.py # requires "pip install line_profiler" | |
# | |
# pytrace() { python -m trace --ignore-dir=$(python -c "import sys, os; print(os.pathsep.join(sys.path))") --trace "$@"; } | |
# cprofile() { python -m cProfile -s cumulative "$@" 2>&1 &> log.txt; } | |
# lineprofile() { python $(python -c 'import kernprof; print(kernprof.__file__.strip("c"))') -l -v "$@"} | |
def pytrace(func): |
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
cjson = require 'cjson' | |
local Ffmpeg = torch.class('Ffmpeg') | |
function Ffmpeg:__init(path) | |
local ffprobeCmd = 'ffprobe -v quiet -print_format json -show_streams ' .. path | |
local output = io.popen(ffprobeCmd, 'r'):read('*a') | |
j = cjson.decode(output) | |
video_st = j['streams'][1] |
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 base64 | |
import random | |
import cv2 | |
import torch | |
import torchvision | |
def svg(points, labels, thumbnails, legend_size = 1e-1, legend_font_size = 5e-2, circle_radius = 5e-3): | |
points = (points - points.min(0)[0]) / (points.max(0)[0] - points.min(0)[0]) | |
class_index = sorted(set(labels)) | |
class_colors = [360.0 * i / len(class_index) for i in range(len(class_index))] |
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_lookup_choices.py --lookup key1 | |
# Namespace(lookup='1') | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--lookup', choices = dict(key1 = '1', key2 = '2'), default = '1', action = type('', (argparse.Action, ), dict(__call__ = lambda a, p, n, v, o: setattr(n, a.dest, a.choices[v])))) | |
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
#! /bin/bash | |
#Usage: | |
# 1. Download the script to Home folder and open the Terminal | |
# 2. Put in your e-mail and SendGrid bearer token to get a notification of success | |
# 3. Open the Terminal and run the script: "$ bash ~/rdv_echange_permis_conduire_paris.sh" | |
# 4. Get your RDV! Right now the script will exit once it found a RDV available. It would dump the HTML of the page to "~/rdv_naturalisation_saint_denis.sh.html". Comment the line 38 to continue checking. | |
set -e |