Skip to content

Instantly share code, notes, and snippets.

View ei-grad's full-sized avatar

Andrew Grigorev ei-grad

View GitHub Profile
@ei-grad
ei-grad / fetcher.py
Created October 4, 2017 09:58
Asyncronously fetch urls in parallel (via tornado) and apply specified function to response
from tornado.ioloop import IOLoop
from tornado.gen import coroutine
from tornado.httpclient import AsyncHTTPClient, HTTPRequest
from tornado.queues import Queue
try:
from tqdm import tqdm
except ImportError:
tqdm = None
var agent = navigator.userAgent.toLowerCase();
if (/iphone|ipad|ipod/i.test(agent)) {
window.location = 'https://{appstore_link}';
}
else if (/android/i.test(agent)) {
window.location = 'https://{gplay_link}';
}
else {
window.location = 'http://{web_version}';
}
@ei-grad
ei-grad / field_types.sh
Created June 1, 2017 22:23
Gather field types from elasticsearch
curl localhost:9200/*/_mapping | jq -S 'map_values(.mappings|map_values(.properties|try map_values(.type)))'
@ei-grad
ei-grad / gitlab-ci-docker-build
Last active April 26, 2017 22:05
Build docker images in Gitlab CI
#!/usr/bin/env bash
set -x
set -e
# allows `docker build ...` to use images cache
# could be installed with: pip install restore_commit_times
#restore_commit_times .
DOCKERFILE_LOCATION="$1"
@ei-grad
ei-grad / upgrade-elasticsearch.yml
Last active May 7, 2017 12:13
Ansible playbook for rolling elasticsearch cluster upgrade
- name: upgrade elasticsearch
hosts: elastic
serial: 1
tasks:
- name: stop elasticsearch
service: name=elasticsearch state=stopped
- name: remove elasticsearch plugins
command: /usr/share/elasticsearch/bin/elasticsearch-plugin remove x-pack
@ei-grad
ei-grad / run_es.sh
Last active April 25, 2017 20:41
Run elasticsearch in docker
# see https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html
docker run -d --restart=always \
--name elasticsearch \
-p 127.0.0.1:9200:9200 \
-v /srv/elasticsearch:/usr/share/elasticsearch/data \
-e ES_JAVA_OPTS="-Xms1g -Xmx1g" \
-e bootstrap.memory_lock=true \
-e cluster.name=edadeal \
-e xpack.security.enabled=false \
@namespace url(http://www.w3.org/1999/xhtml);
@-moz-document domain("samlib.ru") {
* {
background: black;
color: #6af;
}
body {
width: 20cm;
margin: auto;
@ei-grad
ei-grad / jpegsizes.go
Last active March 28, 2017 23:49
Calculate the sizes of many JPEG images fast.
package main
import (
"flag"
"fmt"
"image/jpeg"
"log"
"os"
"path/filepath"
"sync"
import numpy as np
import pygame
def show(a):
global screen
if 'screen' not in globals():
screen = pygame.display.set_mode((0, 0), pygame.RESIZABLE)
@ei-grad
ei-grad / format_money.py
Created January 14, 2017 16:58
Answer to "How to print number with commas as thousands separators?"
# http://stackoverflow.com/a/39301723/2649222
def format_money(f, delimiter=',', frac_digits=2):
'''
>>> format_money(1.7777)
'1.78'
>>> format_money(-1.7777)
'-1.78'
>>> format_money(12.7777)
'12.78'
>>> format_money(-12.7777)