Skip to content

Instantly share code, notes, and snippets.

View hejmsdz's full-sized avatar

Mikołaj Rozwadowski hejmsdz

View GitHub Profile
import fs from 'fs';
import fetch from 'node-fetch';
import { JSDOM } from 'jsdom';
import YAML from 'yaml'
async function loadDocument(url) {
const response = await fetch(url);
const body = await response.text();
const { document } = new JSDOM(body, { url }).window;
return document;

Sposób użycia

# pobierz skrypt
wget https://gist.githubusercontent.com/hejmsdz/bb4acc23df5a2613bf7abc7e7753f48b/raw/hrnest.py

# opcjonalnie ustaw wirtualne środowisko
python3 -m venv .venv && . .venv/bin/activate

# zainstaluj Selenium
@hejmsdz
hejmsdz / settings.json
Created May 6, 2021 19:11
some visual studio code configuration
{
"vim.vimrc.enable": true,
"vim.vimrc.path": "~/.config/nvim/init.vim",
"vim.normalModeKeyBindings": [
{
"before": ["<leader>", "\\"],
"commands": ["workbench.files.action.showActiveFileInExplorer"],
},
{
"before": ["<leader>", "1"],
@hejmsdz
hejmsdz / client.py
Last active November 13, 2018 19:10
#!/usr/bin/env python3
import argparse
import base64
import json
import hashlib
import os
import stat
import requests
@hejmsdz
hejmsdz / check_format.py
Created February 20, 2018 22:00
Data structure format checker
# Simple recursive function that checks the format of a data structure,
# which can consist of dicts, lists, tuples and primitive types.
def check_format(struct, obj):
if isinstance(struct, dict):
return isinstance(obj, dict) and all(check_format(substruct, obj[key]) for key, substruct in struct.items())
if isinstance(struct, tuple):
return isinstance(obj, tuple) and all(check_format(substruct, obj[i]) for i, substruct in enumerate(struct))
elif isinstance(struct, list):
return isinstance(obj, list) and all(check_format(struct[0], item) for item in obj)
@hejmsdz
hejmsdz / linprog.rb
Created July 1, 2017 11:48
Linear programming problems representation in Ruby
require "matrix"
class Variable
attr_accessor :name
def initialize(name)
@name = name
end
def to_s
@hejmsdz
hejmsdz / matrix.rb
Last active July 1, 2017 11:19
Matrix inversion helper
require "matrix"
require "readline"
class Rational
# convert to integer if is actually an integer
def try_to_i
to_i == self ? to_i : self
end
end
@hejmsdz
hejmsdz / gra.py
Last active July 1, 2017 11:01
Gra w makao
#!/usr/bin/python
#-*- coding: utf-8 -*-
"""
Gra w makao
Mikołaj Rozwadowski, 2014
Zasady:
- karty dokładamy tak, żeby zgadzały się kolorem lub figurą
- jeśli na ręce nie ma pasujących kart, bierzemy jedną z talii
- karty o tych samych figurach można kłaść w jednym ruchu
@hejmsdz
hejmsdz / resistors.rb
Last active July 1, 2017 10:06
Resistance calculator with LaTeX-compatible step by step derivation
require 'set'
def ohm(value, decimals=2)
value.round(decimals).to_s.sub('.', ',').sub(/,0+$/, '') << " \\Omega"
end
def frac(num, den)
"\\frac{#{num}}{#{den}}"
end
@hejmsdz
hejmsdz / mp.js
Last active July 1, 2017 09:56
Oczekiwanie na wyniki z MP
(function(album) {
var intvl = setInterval(function() {
fetch('Metody_probabilistyczne_-__wiczenia_2016_17.html').then(x => x.text()).then(function(data) {
var dom = new DOMParser().parseFromString(data, "text/html");
document.body.innerHTML = dom.getElementsByTagName('body')[0].innerHTML;
var tr = [].slice.call(dom.querySelectorAll('tr')).filter(tr => tr.firstChild.innerHTML == album)[0].lastChild.innerHTML;
if (tr != '&nbsp;') {
clearInterval(intvl);
alert(tr);
} else console.log('jeszcze nie ma');