Skip to content

Instantly share code, notes, and snippets.

@rivmar
rivmar / gist:8169b2353dfcaac85a0e14c6f3e53a99
Created February 27, 2018 06:48
[Python] Recursive search in nested dict by key
def get_all(data, key):
if type(data) is dict:
for jsonkey in data.keys():
if jsonkey == key:
return data[jsonkey]
#Return the first pair only!
break
elif type(data[jsonkey]) in (list, dict):
if get_all(data[jsonkey], key):
return get_all(data[jsonkey], key)
@rivmar
rivmar / gist:f218d27da8ec32c34362a5e687df400c
Created March 23, 2018 09:17
[Python] Get server ping time
import re
import subprocess
host = 'google.com'
try:
output = subprocess.check_output(['ping', '-c', '4', '-q', host])
output = output.decode('utf8')
statistic = re.search(r'(\d+\.\d+/){3}\d+\.\d+', output).group(0)
avg_time = re.findall(r'\d+\.\d+', statistic)[1]
#include<QCoreApplication>
#include<QNetworkAccessManager>
#include<QNetworkReply>
#include<QFile>
int getFile(char str[], char out[])
{
QUrl url(str);
QNetworkAccessManager manager(0);
QNetworkReply * reply = manager.get(QNetworkRequest(url));
@rivmar
rivmar / proxypattern
Created January 29, 2019 07:27
Draft of proxy pattern realisation
from __future__ import print_function
from collections import namedtuple
agx = namedtuple('art', 'label size')
a = agx('gold', 12)
b = agx('silver', 4)
class MyProxy(object):