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 / json_array_to_lines.go
Created November 28, 2019 13:09
Convert large JSON array to lines
package main
import (
"encoding/json"
"fmt"
"log"
"os"
)
func main() {
WS: /[ \t\f\r\n]/+
DIGIT: "0".."9"
INT: DIGIT+
FLOAT: DIGIT? "." DIGIT+
| DIGIT+ "."
int: INT
float: FLOAT
// simple types
from pathlib import Path
from urllib.parse import quote
index = []
for i in sorted(Path('.').iterdir()):
index.append(i)
with open('index.html', 'w') as f:
f.write('<html><body><center>')
@ei-grad
ei-grad / coordconv.py
Created August 6, 2019 14:42
Neat CoordConv channels injection implementation as a tensorflow.keras layer.
from tensorflow.keras import backend as K
from tensorflow.keras.layers import Layer
class CoordinateChannel2D(Layer):
def call(self, inputs):
x = K.cast(K.arange(0, K.shape(inputs)[1]), K.floatx())
x /= K.cast(K.shape(inputs)[1], K.floatx())
@ei-grad
ei-grad / speech2text
Created May 18, 2019 14:27
speech2text command using Yandex SpeachKit
#!/bin/bash
if [ -z "$YC_API_KEY" ]; then
cat << EOF
Yandex Cloud API Key is needed:
https://cloud.yandex.ru/docs/iam/concepts/authorization/api-key
it would require some hustle with service account and roles:
https://cloud.yandex.ru/docs/speechkit/security/
@ei-grad
ei-grad / decode-mime-headers.pl
Created March 30, 2019 22:14
Some exim ugly hacks
#!/usr/bin/env perl
use open qw(:std :utf8);
use Encode qw(decode);
while (my $line = <STDIN>) {
print decode("MIME-Header", $line);
}
#!/bin/sh
find -name .git -a -type d -prune -o -type f -print0 | du --bytes -h --files0-from=- | sort -rh
@ei-grad
ei-grad / convert-to-h264-ffmpeg-cuda.sh
Created February 23, 2019 13:53
Generate index.html to watch video files from current directory in browser
for i in *; do
echo "Converting $i..."
ffmpeg -nostdin -i $i -c:v h264_nvenc -preset slow -cq 10 -bf 2 -g 150 ${i%.*}.mp4.tmp && \
rm $i && \
mv ${i%.*}.mp4.tmp ${i%.*}.mp4
echo
done
@ei-grad
ei-grad / reset_weights.py
Created January 24, 2019 11:49
Reset Keras model weights
from keras import backend as K
import keras
def reset_weights(model):
session = K.get_session()
for layer in model.layers:
if isinstance(layer, keras.engine.network.Network):
reset_weights(layer)
continue
for v in layer.__dict__.values():
@ei-grad
ei-grad / dfs.py
Created January 24, 2019 11:46
DFS (DataFrames Storage) - a handy container to reduce global namespace pollution and utilize autocomplete in Jupyter notebooks
class DFS(dict):
def __getattr__(self, key):
return self[key]
def __setattr__(self, key, value):
self[key] = value
def __dir__(self):
return list(self)