Skip to content

Instantly share code, notes, and snippets.

@daskol
daskol / mp.py
Last active April 6, 2016 16:21 — forked from ei-grad/mp.py
Mixpanel API client with python2/python3 support and data export API support
#! /usr/bin/env python
#
# Mixpanel, Inc. -- http://mixpanel.com/
#
# Python API client library to consume mixpanel.com analytics data.
#
# Copyright 2010-2013 Mixpanel, Inc
# Copyright 2016 Edadeal, LCC
#
# Licensed under the Apache License, Version 2.0 (the "License");
@daskol
daskol / nlsio.py
Created April 11, 2016 23:38
Common routines in order to share solutions of NLSe
# nlsio.py
# This module provide common routines in order to share solutions of NLSe.
# (c) Daniel Bershatsky, 2016
# See LICENSE for details
from __future__ import absolute_import, print_function
from datetime import datetime
from scipy.io import savemat, loadmat
from operator import itemgetter
from collections import OrderedDict
def word2index(model):
"""Extract word2index mapping from Word2Vec model.
"""
word2index = OrderedDict((v, k) for k, v in sorted(model.index2word, key=itemgetter(1)))
return word2index
def density_plot(subplot_number, value, label, name, labels):
extent = (gx[0, 0], gx[-1, -1], gy[0, 0], gy[-1, -1])
ax = fig.add_subplot(120 + subplot_number, aspect='equal')
ax.set_xlabel(labels[0])
ax.set_ylabel(labels[1])
ax.set_title(name)
ax.imshow(value[0], extent=extent)
ax.contour(gx, gy, value[1].real, [0.0], colors='red', extent=extent)
ax.contour(gx, gy, value[1].imag, [0.0], colors='blue', extent=extent)
@daskol
daskol / vortex_detection.py
Last active May 29, 2016 21:34
Routines for finding vortex in Bose-Einstein condensate.
# vortex_detection.py
# (c) Daniel Bershatsky, 2016
# See LICENSE for details.
from __future__ import absolute_import, division
import skimage.measure as measure
import numpy as np
def fit_segment(contour, index):
@daskol
daskol / frozen-lake.py
Created April 9, 2017 13:02
RandomPolicyAgent for FrozenLake-v0
#!/usr/bin/env python3
# frozen-lake.py
"""FrozenLake игрушечная задача для обучения с подкреплением.
"""
import click
import gym
import gym.wrappers.monitoring
import logging
import numpy as np
@daskol
daskol / inject-metrica.sh
Created January 19, 2018 22:40
Inject Yandex Metrica counter into all HTML files after <body> tag.
#!/bin/bash
# inject-metrica.sh
# Inject Yandex Metrica counter into all HTML files after <body> tag.
COUNTER='<put Yandex Metrica one-line counter here>'
COUNTER=$(sed 's/\//\\\//g' <<< $COUNTER)
for file in $(ls *.html); do
echo "processing $file"
sed -i "s/<body>/<body>\n$COUNTER/g" $file
@daskol
daskol / listem.c
Created February 9, 2018 20:49
IPv4 and IPv6 sockets on Linux.
// listen.c
//
// This is small tool that helps to clarify how to listen IPv6 socket and it
// is nessesary or not listen IPv4 socket at the same time.
//
// Compile `gcc -std=c11 -o listen listen.c`
//
// Run binary with option `-4` or `-6` and connect to port(default is 5489)
// with netcat in the following way.
// 1. `nc -4 127.0.0.1 5489`
@daskol
daskol / jpg2png.py
Created February 21, 2018 20:40
JPG to PNG converter in python with pillow
#!/usr/bin/env python3
import click
import PIL.Image
@click.command()
@click.argument('input', type=click.Path(exists=True, dir_okay=False))
@click.argument('output', type=click.Path(exists=False))
def main(input, output):
img = PIL.Image.open(input)
@daskol
daskol / jpg2png.go
Last active February 21, 2018 20:43
JPG to PNG converter in pure Go
package main
import (
"flag"
"io"
"log"
"os"
jpg "image/jpeg"
"image/png"