Skip to content

Instantly share code, notes, and snippets.

View svecon's full-sized avatar

Ondřej Švec svecon

View GitHub Profile
WARNING! Be very careful that you do not accidentally disable all ways that you can click. If you have reassigned your left click button to another function, and then you uncheck "Enable" on one finger tapping in the GUI, you will have to plug in an external USB mouse or remote into the machine with remote desktop (or something similar) or use Windows Speech Recognition or figure out some other way to re-check the "Enable" box under one finger tapping in the GUI in order to restore click functionality. I will not be held responsible if you do not have any of these methods available and you end up (temporarily) bricking your laptop. You have been warned. (But really, just don't uncheck that box and you will be fine).
HKEY_CURRENT_USER\Software\Elantech\SmartPad:
Button_Left; Button_Right; Tap_Two_Finger; Tap_Three_Finger; ThreeFingerMoveUp_Func; ThreeFingerMoveDown_Func:
0 Click/Select
Left click default
1 Pop-up Menu
Right Click default
2 Middle Button
@svecon
svecon / Bellet-2014-SML-notes.txt
Created August 28, 2017 12:15
Notes for Bellet 2014 survey
Mahalanobis distance dM(x,x′)^2 = (x − x′)^T M (x − x′)
where M is cone of symmetric PSD d*d matrix
Must-link / cannot-link constraints (sometimes called positive / negative pairs):
S = {(xi, xj) : xi and xj should be similar},
D = {(xi, xj) : xi and xj should be dissimilar}.
Relative constraints (sometimes called training triplets):
R = {(xi, xj , xk) : xi should be more similar to xj than to xk}.
Optimization problem that has the following general form: min M { ℓ(M, S,D,R) + λR(M) }
@svecon
svecon / receptive_field.py
Last active November 13, 2020 07:52
Calculate receptive field and strides for multiple convolutions
# https://medium.com/@nikasa1889/a-guide-to-receptive-field-arithmetic-for-convolutional-neural-networks-e0f514068807#1780
import math
def receptive_field(n, layers):
"""
Parameters
----------
n: int, input size
layers: array of triplets: (k,s,p)
k: kernel size
s: stride
@svecon
svecon / download_multiple_images.py
Created May 29, 2018 19:48
Download multiple images using Python
import requests
def DownloadImage(pic_url_prefix, pic_name):
with open(pic_name, 'wb') as handle:
response = requests.get(pic_url_prefix+pic_name, stream=True)
if not response.ok:
print(pic_url_prefix+pic_name, response)
for block in response.iter_content(1024):
@svecon
svecon / keras_cut_network.py
Created August 29, 2017 12:24
Remove last layers of Keras NN model
def remove_layers(model, n)
for _ in range(n):
model.pop()
model.outputs = [model.layers[-1].output]
model.layers[-1].outbound_nodes = []
model.compile(loss='binary_crossentropy', optimizer='adam')
return model
# Example
new_model = remove_layers(model.layers_by_depth[1][0])
@svecon
svecon / iPython_notebook_styles.py
Created August 29, 2017 12:02
Make the notebook full width and align output on the right
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))
display(HTML("<style> div.cell {display: -webkit-box; -webkit-box-orient: horizontal;-webkit-box-align: stretch;\
display: -moz-box;-moz-box-orient: horizontal;-moz-box-align: stretch;\
display: box;box-orient: horizontal;box-align: stretch;}</style>"))
display(HTML("<style> div.input{min-width:50%;}</style>"))
display(HTML("<style> div.code_cell{width: 70%;float: left;}"
+"div.text_cell{width: 30%;float: right;}"
+"div.text_cell div.prompt {display: none;}</style>"))
@svecon
svecon / logical_puzzles.txt
Created August 28, 2017 12:18
Logical puzzles
A mathematician and a lady strike conversation during a flight. The lady asks the mathematician to guess the age of her three daughters. Mathematician, being unable to answer the questions, asks for some hint(s).
The lady replies: The product of their ages is 36.
Still unable to answer, mathematician asks for another hint.
Hint 2: The sum of their ages is equal to your (i.e. mathematician's) seat number.
Mathematician still cann't answer the question.
Final hint: My (i.e. the lady's) youngest daughter has blue eyes.
Listening to the final hint, mathematician is able to answer the question.
x*y*z = 36 = 2*2*3*3
import tensorflow as tf
class EvoNetwork:
def __init__(self, input_size, weights, use_biases=False):
with tf.Graph().as_default():
self.inputs = tf.placeholder(tf.float32, [None, input_size])
hidden_layer = self.inputs
for i, weight in enumerate(weights):
with tf.variable_scope('hidden_layer_{}'.format(i)):
@svecon
svecon / ValidateDate
Last active December 21, 2015 06:49
Validates user's input date.
protected function checkInputDate($string)
{
$try = date_parse($string);
if ($try['error_count'] > 0)
return false;
try { $try = new DateTime($string); }
catch (Exception $e) { return false; }
$sep = '-.\/';
@svecon
svecon / dateToJND.py
Created December 12, 2015 15:01
Converting date to number of days in Julian Calendar
# Converting date to number of days
# Useful when you need to add few days and get a date
# https://en.wikipedia.org/wiki/Julian_day
def toJND(day,month,year):
a = (14-month)//12
y = year + 4800 - a
m = month + 12*a - 3
return day + (153*m+2)//5 + 365*y + y//4 - 32083