Skip to content

Instantly share code, notes, and snippets.

View Masa331's full-sized avatar
🤠

Premysl Donat Masa331

🤠
View GitHub Profile
@Masa331
Masa331 / rebuild.rb
Created July 26, 2018 20:21
Static site generator
#!/usr/bin/env ruby
files_to_process = Dir.glob('**/*.html')
target_directory = '/home/masa331/code/html_js/masa331.github.io'
files_to_process.each do |file|
content = File.read(file)
modified = content.lines.map do |line|
if line.include? 'INSERT'
@Masa331
Masa331 / mega.rb
Created April 8, 2018 19:51
How to call a same method from all included modules
module ColorParser
def parse
source.select { |k, _| k == :color }
end
end
module BrandParser
def parse
source.select { |k, _| k == :brand }
end
@Masa331
Masa331 / hash_flatten.rb
Created March 16, 2018 20:49
HashFlatten
module HashFlatten
refine Hash do
def squish_levels
each_with_object({}) do |(key, value), squished|
if value.is_a? Hash
value.squish_levels.each { |sub_key, sub_value| squished.store("#{key}.#{sub_key}", sub_value) }
else
squished.store(key.to_s, value)
end
end
@Masa331
Masa331 / ajax.js
Last active February 2, 2018 12:13
var resp = [];
req = new XMLHttpRequest();
req.open('GET', url, false);
req.setRequestHeader('Content-Type', 'application/json');
req.onload = function (response) {
console.log('loaded');
console.log(response);
resp = response;
};
@Masa331
Masa331 / apply.rb
Last active December 10, 2017 11:51
module StringApply
def apply(*funcs)
funcs.inject(self) { |product, func| func.call(product) }
end
end
module ArrayApply
def apply(*funcs)
# funcs.inject(self) { |product, func| func.call(product) }
map { |item| funcs.inject(item) { |product, func| func.call(product) } }
Roger MacBride Allen - Ztracená země
Robert Fabian - Carpe Diem
Robert Fabian - Sepmer Fi
Ian McDonald - Řeka Bohů
Robert Charles Wilson - Spin
Kevin J Anderson - Skrytá Říše
Bruce Sterling - Shismatrix Plus
Kurt Vonnegut - Jatka č. 5
Frederik Pohl - Gateway
Douglas Adams - Sotpařův průvodce po galaxii
require 'nokogiri'
RSpec::Matchers.define :match_xsd do |schema_path|
match do |document|
schema = Nokogiri::XML::Schema(File.open(schema_path))
errors = schema.validate(document)
errors.size == 0
end
Eet::Message
#body
Element '{http://fs.mfcr.cz/eet/schema/v3}Hlavicka', attribute 'dat_odesl': '' is not a valid value of the atomic type '{http://fs.mfcr.cz/eet/schema/v3}dateTime'.
Element '{http://fs.mfcr.cz/eet/schema/v3}Data': The attribute 'dic_popl' is required but missing.
Element '{http://fs.mfcr.cz/eet/schema/v3}Data': The attribute 'id_provoz' is required but missing.
Element '{http://fs.mfcr.cz/eet/schema/v3}Data': The attribute 'id_pokl' is required but missing.
Element '{http://fs.mfcr.cz/eet/schema/v3}Data': The attribute 'porad_cis' is required but missing.
Element '{http://fs.mfcr.cz/eet/schema/v3}Data': The attribute 'dat_trzby' is required but missing.
Element '{http://fs.mfcr.cz/eet/schema/v3}Data': The attribute 'celk_trzba' is required but missing.
Element '{http://fs.mfcr.cz/eet/schema/v3}Data': The attribute 'rezim' is required but missing.
require 'spec_helper'
require 'nokogiri'
RSpec.describe Eet::Message do
describe '#body' do
it "is valid against it's xsd schema" do
message = Eet::Message.new()
schema = Nokogiri::XML::Schema(File.read('./spec/fixtures/EETXMLSchema.xsd'))
errors = schema.validate(message.body)
require 'nokogiri'
require 'securerandom'
module Eet
class Message
def body
Nokogiri::XML::Builder.new('encoding' => 'UTF-8') do |xml|
xml.Trzba(xmlns: 'http://fs.mfcr.cz/eet/schema/v3') do
xml.Hlavicka(dat_odesl: '1.1.2017 10:00', prvni_zaslani: true, uuid_zpravy: SecureRandom.uuid)