Skip to content

Instantly share code, notes, and snippets.

@numpde
numpde / histo.py
Last active May 29, 2017 13:08
Histograms for the number of types V(N) within the first N tokens
#!/usr/bin/python3
# Histograms for the number of types V(N) within the first N tokens.
# Comparison of natives vs learners.
# R. Andreev, 2017-05-11 (first version), CC BY 4.0
# Designed for the ANGLISH corpus [Tortel 2008, via N. Ballier & P. Lisson]
# The texts are expected to be located in ./ANGLISH/*.txt
@numpde
numpde / peer_learning.md
Last active July 7, 2017 16:46
Reinforcement learning through imitation of successful peers

Reinforcement learning through imitation of successful peers

Introduction

Reinforcement learning is a mode of machine learning driven by the feedback from the environment on how good a string of actions of the learning agent turns out to be.

We consider here a reinforcement learning mechanism for neural networks

@numpde
numpde / binary_rank.py
Last active November 8, 2017 09:23
Find the rank of a binary matrix over Z/2Z
# Find the rank of a binary matrix over Z/2Z
# (conceptual implementation)
#
# RA, 2017-11-07 (CC-BY-4.0)
#
# Adapted from
# https://triangleinequality.wordpress.com/2014/01/23/computing-homology/
#
def binary_rank(M) :
@numpde
numpde / rndseg.py
Last active November 9, 2017 03:56
Segment extraction and expansion by words
#!/usr/bin/python3
# CC-BY-4.0
import sys, argparse
from random import shuffle, randrange, choice
# Collate lines, separating them by a space
s = ' '.join(sys.stdin.readlines())
# Remove non-text
@numpde
numpde / renice.m
Last active November 9, 2017 03:58
Try to make a MATLAB plot a little nicer
function h = renice(h)
% function h = renice(h)
%
% h is a handle returned by PLOT and such
%
% RA, Apr 2008 -- Aug 2016
%
% License: CC-BY-4.0
set(0, 'DefaultTextInterpreter', 'tex');
@numpde
numpde / add_path_by_variable.sh
Last active November 9, 2017 04:00
Write [addpath PATH "/some/path"] instead of [export PATH="/some/path:$PATH"]
#/bin/bash
# License-free
# Example: addpath PATH "/usr/bin"
addpath() {
varname=$1
export $1="$2:${!varname}"
}
@numpde
numpde / tunnel.sh
Last active January 17, 2018 12:35
Create an ssh tunnel using a local port
#!/bin/bash
# Suppose you wish to connect to a server X on port 23
# but you have to do this via another server Y like this:
#
# localhost> ssh -p 22 username@Y
# Y> ssh -p 23 username@X
#
# Instead, you can create an ssh tunnel on a local port, say 9999:
# localhost> ssh -nNT -L 9999:X:23 -p 22 username@Y
@numpde
numpde / template_for_datascience.py
Last active October 25, 2018 03:57
A python template for a data science script
#!/usr/bin/python3
# AUTHOR, DATE
## ================== IMPORTS :
pass
import inspect
@numpde
numpde / update_ip.py
Created January 20, 2019 16:37
Alibaba DNS record update python script
#!/usr/bin/env python3
#coding=utf-8
import subprocess
IP = subprocess.run("dig +short myip.opendns.com @resolver1.opendns.com".split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.decode('UTF-8').split()[0]
print("IP:", IP)
# https://api.aliyun.com/new#/?product=Alidns&api=UpdateDomainRecord&params={}&tab=DEMO&lang=PYTHON
@numpde
numpde / makefile
Created January 22, 2019 07:22
A mechanism to .gitignore large files but keep a list of them on git
help:
@echo Put this script at the root of the git project.
@echo
@echo Add the following lines to the .gitignore file:
@echo " ""**/UV/**"
@echo " ""!**/UV/unversioned"
@echo
@echo Run
@echo " ""make unversioned"
@echo to create the listings of unversioned files in