Skip to content

Instantly share code, notes, and snippets.

View hejmsdz's full-sized avatar

Mikołaj Rozwadowski hejmsdz

View GitHub Profile
@hejmsdz
hejmsdz / giveaway.py
Last active August 29, 2015 14:16
Lingot giveaway
import json
import re
import pyduo
give = 15
mock = False
duo = pyduo.Duolingo()
duo.login("username", "password")
require "json"
require "mechanize"
def results
agent = Mechanize.new
credentials = {
pesel: ENV['PESEL'],
password: ENV['CKE_PASSWORD']
}
@hejmsdz
hejmsdz / ipcchat.h
Last active January 14, 2017 15:15
Zwiększenie limitu długości wiadomości do 2048
/*
MR & JP
ver. 1.3.0
16:15 14.01.2017 (w razie jakby coś się zmieniło jeszcze)
*/
#ifndef IPCCHAT_IPCCHAT_H
#define IPCCHAT_IPCCHAT_H
// maksymalna liczba użytkowników
@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 != ' ') {
clearInterval(intvl);
alert(tr);
} else console.log('jeszcze nie ma');
@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 / 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 / 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 / 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 / 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 / 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