Skip to content

Instantly share code, notes, and snippets.

View nonogram_read_file.py
def initialize_from_file(self, filename):
with open(filename) as f:
# Board size
row_count = int(f.readline())
col_count = int(f.readline())
self.initialize(row_count, col_count)
# Read row hints, one row per line
self.row_hints = []
for i in range(0, self.no_rows):
line = f.readline()
View nonogram_datastructure.py
class Nonogram:
no_rows = None
no_cols = None
board = None
col_hints = None
row_hints = None
def initialize(self, row_count, col_count):
self.no_cols = col_count
self.no_rows = row_count
View fia_doc_trigger_complete.py
import requests
import os
from bs4 import BeautifulSoup
from urllib.parse import quote
IFTTT_KEY = '<YOUR API KEY>'
STATUS_FILE = "status_fia.dat"
BASE_LINK = "https://www.fia.com"
DOCS_URL = BASE_LINK + "/documents/season/season-2021-1108/championships/fia-formula-one-world-championship-14"
View fia_doc_trigger.py
import requests
IFTTT_KEY = '<YOUR KEY HERE>'
def trigger_ifttt(trigger, data):
requests.post("https://maker.ifttt.com/trigger/" + trigger + "/with/key/" + IFTTT_KEY, data=data)
trigger_ifttt('FIA_document', {'value1': desc, 'value2': link})
View fia_doc_parser.py
import requests
from bs4 import BeautifulSoup
from urllib.parse import quote
BASE_LINK = "https://www.fia.com"
DOCS_URL = BASE_LINK + "/documents/season/season-2021-1108/championships/fia-formula-one-world-championship-14"
content = requests.get(DOCS_URL)
soup = BeautifulSoup(content.text, features='lxml')
@lmeulen
lmeulen / gpx_elevation_v2.py
Last active Aug 24, 2021
gpx_elevation_v2
View gpx_elevation_v2.py
df['elev_ma'] = df['elevation'].rolling(window=30, min_periods=1, center=True).mean()
df.loc[0, 'delev_ma'] = 0.0
for i in range(1, len(df)):
df.loc[i, 'delev_ma'] = (df.loc[i, 'elev_ma'] - df.loc[i-1, 'elev_ma'])
descent = abs(df['delev_ma'].where(df['delev_ma']<0).sum())
ascent = df['delev_ma'].where(df['delev_ma']>0).sum()
minelev = df['elev_ma'].min()
maxelev = df['elev_ma'].max()
print('Minimum elevation : {:4.0f} m'.format(minelev))
@lmeulen
lmeulen / gpx_elevantion_v1.py
Last active Aug 24, 2021
gpx_elevantion_v1
View gpx_elevantion_v1.py
df.loc[0, 'delev'] = 0.0
for i in range(1, len(df)):
df.loc[i, 'delev'] = (df.loc[i, 'elevation'] - df.loc[i-1, 'elevation'])
descent = abs(df['delev'].where(df['delev']<0).sum())
ascent = df['delev'].where(df['delev']>0).sum()
minelev = df['elevation'].min()
maxelev = df['elevation'].max()
print('Minimum elevation : {:4.0f} m'.format(minelev))
print('Maximum elevation : {:4.0f} m'.format(maxelev))
View gpx_speed_ma.py
rows = int(30/int(df.dt.mean()))
df['speed_ma'] = df['speed'].rolling(window=rows, min_periods=1).mean()
df[['speed_ma']].plot(figsize=(15,8))
View gps_speed_v1.py
df.loc[0, 'dt'] = 0.0
df.loc[0, 'speed'] = 0.0
for i in range(1, len(df)):
df.loc[i, 'dt'] = (df.loc[i, 'timestamp'] - \
df.loc[i-1, 'timestamp']).total_seconds()
df.loc[i, 'speed'] = df.loc[i, 'dist'] / df.loc[i, 'dt'] * 3.6
print(df['speed'].mean())
'''
Output:
View gpx_distance_haversine.py
def dist_haversine(lat1, lon1, lat2, lon2):
radius = 6371.0088
lat = lat2 - lat1
lon = lon2 - lon1
d = sin(lat * 0.5) ** 2 + cos(lat1) * cos(lat2) * sin(lon * 0.5) ** 2
return 2 * radius * asin(sqrt(d)) * 1000