Skip to content

Instantly share code, notes, and snippets.

View mkocikowski's full-sized avatar

Mik Kocikowski mkocikowski

View GitHub Profile
@mkocikowski
mkocikowski / gist:aeca878d58d313e902bb
Last active January 22, 2024 05:35
Setting up Redis to run as a daemon under systemd

This can be used to daemonize anything that would normally run in the foreground; I picked Redis. Put this in /etc/systemd/system/redis.service:

[Unit]
Description=Redis
After=syslog.target

[Service]
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
RestartSec=5s
@mkocikowski
mkocikowski / .vimrc
Last active April 18, 2017 21:54
.vimrc
syntax on
filetype indent plugin on
map <C-\> {gq}
execute pathogen#infect()
" yaml
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
" always display status line
@mkocikowski
mkocikowski / ca.cnf
Last active May 19, 2016 19:07
openssl CA configuration file
[ ca ]
default_ca = ca_default
[ ca_default ]
base_dir = $ENV::HOME/.ssh
certificate = $base_dir/datapipe-ca.crt
copy_extensions = copy
database = $base_dir/index.txt
default_days = 365
default_md = sha256
@mkocikowski
mkocikowski / mem.py
Created May 13, 2016 20:27
Check amount of RAM used by current python process
#!/usr/bin/python
import os
# pip install psutil
import psutil
mb = psutil.Process(os.getpid()).memory_info()[0]>>20
print(mb)
@mkocikowski
mkocikowski / ip.sh
Last active February 9, 2016 03:46
get IP of eth1 on Vagrant private network (DHCP)
vagrant ssh -c 'ifconfig eth1' | awk '/inet addr/{print substr($2,6)}'
@mkocikowski
mkocikowski / gist:8325452
Last active January 2, 2016 15:48
esbench 100gb macbookpro test dump
curl -XPUT 'http://localhost:9200/esbench_stats/bench/351b0aa5' -d '{"cluster": {"cluster_name": "mik_local", "node_count": 1, "ok": true, "nodes": {"eQDp6TjSQ8C-9_5ktiyLDA": {"thread_pool": {"index": {"max": 8, "queue_size": "200", "type": "fixed", "min": 8}, "search": {"max": 24, "queue_size": "1k", "type": "fixed", "min": 24}, "management": {"max": 5, "keep_alive": "5m", "type": "scaling", "min": 1}, "get": {"max": 8, "queue_size": "1k", "type": "fixed", "min": 8}, "generic": {"keep_alive": "30s", "type": "cached"}, "suggest": {"max": 8, "queue_size": "1k", "type": "fixed", "min": 8}, "refresh": {"max": 4, "keep_alive": "5m", "type": "scaling", "min": 1}, "bulk": {"max": 8, "queue_size": "50", "type": "fixed", "min": 8}, "merge": {"max": 4, "keep_alive": "5m", "type": "scaling", "min": 1}, "snapshot": {"max": 4, "keep_alive": "5m", "type": "scaling", "min": 1}, "percolate": {"max": 8, "queue_size": "1k", "type": "fixed", "min": 8}, "flush": {"max": 4, "keep_alive": "5m", "type": "scaling", "min": 1}, "warm
@mkocikowski
mkocikowski / cluster-health.sh
Last active November 10, 2015 21:10
Check elasticsearch cluster status
curl -XGET 'http://localhost:9200/_cluster/health?pretty=true' -s \
| grep 'status' \
| test 'green' == `awk -F '"' '{ print $4 }'` ;
@mkocikowski
mkocikowski / gist:37114a5232bd3fa2d145
Last active August 29, 2015 14:23
Delete all closed indexes from Elasticsearch cluster
curl -s 'localhost:9200/_cat/indices' | grep close | awk '{ printf "http://localhost:9200/%s\n", $2 }' | xargs -n 1 curl -i -XDELETE
@mkocikowski
mkocikowski / gist:8fd2728a9c66e5bb9aa2
Created June 3, 2015 14:30
Iterable chunker with no batch size limits
def chunker(iterable=None, chunklen=None):
"""Collects data into fixed-length chunks.
Returns: iterator of iterators. Does not pad the last chunk.
Raises: TypeError on bad iterable or chunklen
Example: chunker("abcde", 2) returns (('a', 'b'), ('c', 'd'), ('e'))
This is better than the functools 'grouper' recipe (using izip on
[iter(iterable)] * n) in that there is no performance penalty for
$ foo='() { echo not patched; }' bash -c foo
bash: foo: command not found
w00t! Not vulnerable.