Skip to content

Instantly share code, notes, and snippets.

View hunan-rostomyan's full-sized avatar

Hunan Rostomyan hunan-rostomyan

View GitHub Profile
@hunan-rostomyan
hunan-rostomyan / getCookie.ts
Created July 19, 2016 22:49
Get a cookie by name in TypeScript
// Given a cookie key `name`, returns the value of
// the cookie or `null`, if the key is not found.
function getCookie(name: string): string {
const nameLenPlus = (name.length + 1);
return document.cookie
.split(';')
.map(c => c.trim())
.filter(cookie => {
return cookie.substring(0, nameLenPlus) === `${name}=`;
})
@hunan-rostomyan
hunan-rostomyan / Scheduler.js
Last active September 30, 2021 06:12
A setTimeout with delay
// Scheduler is setTimeout with an ability to delay
// already scheduled tasks.
// 1. DEFINITION
// -------------
function Scheduler(freq) { // freq in ms
this.freq = freq;
setInterval(this._main.bind(this), this.freq);
}
@hunan-rostomyan
hunan-rostomyan / UniformGuard.py
Last active September 28, 2020 01:50
Implementing Guards using Decorators in Python
"""
Intended to be used as a decorator, UniformGuard
ensures that all of the arguments passed to its
decorated function `_f` satisfy the guard `g`.
"""
def UniformGuard(g, e=TypeError):
def _g(f):
def _f(*args, **kwargs):
if not all(map(g, set(args).union(kwargs.values()))):
if e:
@hunan-rostomyan
hunan-rostomyan / label2mat.m
Created December 26, 2016 23:18
One Hot Encoder/Decoder in Octave/Matlab
function mat = label2mat(label, size)
if ~exist('size', 'var') || isempty(size)
size = 10;
end
if label > size
error('Label (%d) should be < size (%d).', label, size);
end
@hunan-rostomyan
hunan-rostomyan / config.json
Last active May 24, 2019 22:08
GPT-2 345M Config
{
"initializer_range": 0.02,
"layer_norm_epsilon": 1e-05,
"n_ctx": 1024,
"n_embd": 1024,
"n_head": 16,
"n_layer": 24,
"n_positions": 1024,
"vocab_size": 50257
}
@hunan-rostomyan
hunan-rostomyan / download_model.py
Created May 24, 2019 22:02
GPT-2 345M download_model fork
import os
import sys
import requests
from tqdm import tqdm
if len(sys.argv) != 3:
print('You must enter the model name as a parameter, e.g.: download_model.py 117M')
sys.exit(1)
model = sys.argv[1]
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hunan-rostomyan
hunan-rostomyan / statistics.js
Last active December 25, 2017 01:17
Statistics (mean, variance, standard deviation, ...)
function sum(arr) {
return arr.reduce((acm, cur) => acm + cur, 0);
}
function mean(xs, correction) {
var correction = correction || 0;
var total = xs.length - correction;
return sum(xs) / total;
}
@hunan-rostomyan
hunan-rostomyan / complex_using_matrices.js
Last active August 13, 2017 19:43
Complex multiplication using Matrix multiplication
/* In a comment to Problem 6 of Linear Algebra Problem Book,
Halmos notes that the multiplication of complex numbers is a
special case of matrix multiplication via the representation
of complex number a + bi as the 2-by-2 matrix {{a, b}, {-b, a}}.
This is pretty nice because if we have a matrix data type with
a multiplication defined on it, we can just embed the complex
number in a matrix, multiply by another such embedding and
then extract the resulting complex number out.
@hunan-rostomyan
hunan-rostomyan / config_perplexity.ipynb
Last active January 11, 2017 19:17
Configuration vs Perplexity
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.