Skip to content

Instantly share code, notes, and snippets.

View universome's full-sized avatar
💭
༼∩☉ل͜☉༽⊃━☆゚. * ・ 。゚

Ivan Skorokhodov universome

💭
༼∩☉ل͜☉༽⊃━☆゚. * ・ 。゚
View GitHub Profile
@universome
universome / rename.sh
Created January 15, 2016 10:08
Renames everything (filenames and file contents) recursively inside a folder
#!/bin/bash
forbidden_extensions=( "jpg" "jpeg" "png" "gif" "swf" "svg" )
# Usage: includes 'blabla' $arr
includes () {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
return 1
}
@universome
universome / count_lessons_left.js
Last active May 3, 2016 20:00
How to count, how much lessons are left in duolingo?
$(".lessons-left")
.map((i,el) => $(el).text())
.toArray()
.filter(Boolean)
.map(s => s.split('/')[1])
.map(Number)
.reduce((a,b) => a + b);
@universome
universome / shuffle.sh
Last active March 17, 2018 11:20
Shuffle contents of a csv file without breaking headers
sed -n '1!p' data.csv | perl -MList::Util=shuffle -e 'print shuffle(<STDIN>);' > shuffled.csv
head -1 data.csv >> tmp & cat shuffled.csv >> tmp
mv tmp shuffled.csv
# You can also use "awk 'NR>1' data.csv", but it will be slower
###
# Stop and remove all containers
docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q)
###
###
# Run docker daemon (if you see stupid error "Cannot connect to the Docker daemon. Is the docker daemon running on this host?")
# Ubuntu 14.04:
sudo service docker start
@universome
universome / virtualenv_install.sh
Created July 3, 2016 15:29
Installing virtualenv on ubuntu
sudo apt-get update
sudo apt-get install python3-pip python-virtualenv virtualenv
# and now you can use it via:
# virtualenv -p python3 kek
@universome
universome / deploy.sh
Last active October 1, 2017 08:59
Deploy new ubuntu 14.04 instance with virtualenv and some useful packages
sudo apt-get update
sudo apt-get -y install python3-pip python-virtualenv python-dev
mkdir virtualenvs
virtualenv -p python3 virtualenvs/kek
git clone git@github.com:kek/kek-repo.git kek
cd kek
source ~/virtualenvs/kek/bin/activate
# I dunno why, but we should specify 0.0.0.0 IP address for jupyter
# when we want to login remotely (for example, aws ec2 or docker)
jupyter-lab --ip=0.0.0.0 --no-browser --port=10000
# In case HTTP ports are not open in the server —
# use ssh forwarding on local machine
ssh -N -f -L localhost:8888:localhost:10000 user@host
@universome
universome / setup.sh
Last active February 21, 2018 17:58
Setting up pytorch on AWS DL AMI with pyvenv (cause preinstalled conda sucks again)
# Creating pyvenv
python3.6 -m venv --without-pip ~/pyvenvs/zoo
source ~/pyvenvs/zoo/bin/activate
# Getting pip inside
curl https://bootstrap.pypa.io/get-pip.py | python
# Reactivating to obtain pip from venv (without it we would use global pip)
deactivate && source ~/pyvenvs/zoo/bin/activate
from torch.distributions import MultivariateNormal
from torch.distributions import kl_divergence
mean = torch.rand(10, 100)
logstds = torch.rand(10, 100)
x = torch.rand(10, 100)
dist = MultivariateNormal(mean, scale_tril=torch.stack([torch.diag((ls).exp()) for ls in logstds]))
print('Testing LL')
print(dist.log_prob(x).mean())
@universome
universome / jupyter-lab-shorcuts.json
Created September 3, 2019 07:10
Disable Cmd+F behaviour in Jupyter Lab
{
"shortcuts": [
{
"command": "documentsearch:start",
"keys": [
"Accel F"
],
"selector": ".jp-mod-searchable",
"disabled": true
}