Skip to content

Instantly share code, notes, and snippets.

@ukoloff
ukoloff / maybe.cpp
Created May 20, 2018 13:14
Polymorphic Maybe monad
#include <cmath>
#include <iostream>
template <class T>
class Maybe {
public:
Maybe(T val) : value(val), ok(true) {}
Maybe() : ok(false) {}
explicit operator bool() const { return ok; }
@ukoloff
ukoloff / FarMenu.ini
Last active February 17, 2018 10:48
Node.js & Python integrations to Far Manager menu
N: Node
{
I: Install dependencies
npm install -new_console
}
--:
P: Python
{
I: Idle here
"C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\Scripts\idle.exe" -new_console:b
@ukoloff
ukoloff / russian.tex
Created December 15, 2017 06:35
Minimal russian LaTeX document
\documentclass{article}
% General document formatting
\usepackage[margin=0.5in]{geometry}
\usepackage[parfill]{parskip}
\usepackage[utf8]{inputenc}
\usepackage[T2A]{fontenc}
\usepackage[english,russian]{babel}
% Related to math
\usepackage{amsmath,amssymb,amsfonts,amsthm}
@ukoloff
ukoloff / unfold.py
Last active November 30, 2017 19:17
Tensor unfolding
# https://jeankossaifi.github.io/tensorly/unfolding.html
def unfold(tensor, mode=0):
"""
Returns the mode-`mode` unfolding of `tensor`
"""
return np.rollaxis(tensor.T, -mode-1).reshape((tensor.shape[mode], -1))
# Then goto http://www.alexejgossmann.com/tensor_decomposition_tucker/
@ukoloff
ukoloff / posh.js
Created September 15, 2017 15:56
Call PowerShell from JScript
var sh = WScript.CreateObject("WScript.Shell")
var posh = sh.Exec('powershell -Command -')
var i=posh.StdIn;
i.WriteLine('Get-PSProvider')
i.Close()
var o = posh.StdOut.ReadAll()
var e = posh.StdErr.ReadAll()
WScript.Echo('1>', o)
WScript.Echo('2>', e)
@ukoloff
ukoloff / git-credentials.bat
Last active March 6, 2017 10:40
Setup Git credentials on Windows
REM Allow git credentials to be saved in Windows Credential Manager
git config --global credential.helper wincred
@ukoloff
ukoloff / admin.js
Last active June 25, 2023 20:07
WMI samples using JScript
// Check Admin rights
var out = GetObject("winmgmts://./root/default:StdRegProv") .EnumKey(1 << 31 | 3, "S-1-5-20")
WScript.Echo("Admin =", !out)
@ukoloff
ukoloff / Vagrantfile
Last active January 26, 2017 06:38
Remove some packages on fresh debian/jessie64
Vagrant.configure("2") do |config|
config.vm.box = "debian/jessie64"
config.vm.provider "virtualbox" do |v|
v.linked_clone = true
end
config.vm.provision "shell", inline: <<-SHELL
sudo apt-get remove -y rpcbind exim4-base
SHELL
@ukoloff
ukoloff / ecc.sh
Created October 16, 2016 18:32
Generate ECC
openssl ecparam -genkey -name secp384r1 -param_enc explicit -out key.pem
openssl req -new -sha256 -key key.pem -batch -subj /CN=test -out csr.csr
openssl req -x509 -sha256 -days 365 -key key.pem -in csr.csr -out certificate.pem
@ukoloff
ukoloff / npm-dev.bat
Created October 8, 2016 18:06
Install DevKit for Node.js @Windows
REM https://github.com/felixrieseberg/windows-build-tools
npm install --global windows-build-tools