Skip to content

Instantly share code, notes, and snippets.

View Konstantinusz's full-sized avatar

konstantinusz Konstantinusz

View GitHub Profile
@Konstantinusz
Konstantinusz / imagebam_dl
Created June 11, 2017 10:05
Save gallery from imagebam by its GID. It handles filename collisions by renaming.
#!/usr/bin/ruby
require "pry"
require "peach" rescue nil
gallery=ARGV[0].chomp("/")
page_num=1
gallery_id=gallery.split("/").last
%x{mkdir "#{gallery_id}"}
@Konstantinusz
Konstantinusz / save_imagebam
Last active April 28, 2019 09:09
Script to save your photos from imagebam (site will be closed soon). It uses the script imagebam_dl to download the galleries, just put it on the path. It also saves meta informations of galleries into JSON file. You must provide your login and password as arguments in this order.
#!/usr/bin/ruby
require "json"
require "peach" rescue nil
felh=ARGV[0]
jelsz=ARGV[1]
%x{curl 'http://www.imagebam.com/login' -s -c ~/imagebam-cookie.txt -H 'User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36' -H 'Referer: http://www.imagebam.com/login' --data "action=true&nick=#{felh}&pw=#{jelsz}"}
ret=%x{curl 'http://www.imagebam.com/sys/gallerybrowser/getData/' -b ~/imagebam-cookie.txt -H 'Pragma: no-cache' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36 OPR/43.0.2442.806' -H 'Content-Type: text/plain; charset=utf-8' -H 'Accept: */*' -H 'Referer: http://www.imagebam.com/gwt/gallerybrowser/FC785CCD0E5C531F9C9EB53A9C0334E9.cache.html' -H 'Connection: keep-alive' -H 'Cache-Control: no-cache' --compressed -L}
@Konstantinusz
Konstantinusz / vigenere.rb
Last active August 24, 2020 21:46
2005-ös érettségi - Vigenére
H=("ÖÜÓŐÚŰÁÉÍ".split(//).zip("OUOOUUAEI".split(//))).to_h
t=('A'..'Z').to_a
tt={}
tt.merge!({t[0]=>t.zip(t).to_h})
for p in 0..t.size-2 do
tt.merge!({t[p+1]=>t.zip(t[p+1..-1]+t[0..p]).to_h})
end
@Konstantinusz
Konstantinusz / Magyarország_települései.json
Created August 25, 2020 01:20
településnév, helyhatározó, irányhatározó, város/község, megye, járás, lakosság, irányítószám
[
[
"Aba",
"Abán",
"Abára",
"város",
"Fejér",
"Abai",
4574,
"8127"
[
[
"Baks",
"Bakson",
"Baksra",
"község",
"Csongrád",
"Kisteleki",
2294,
"6768"
File.write "inode.txt",Dir["**/*.*"].reject{|z| z !~ /\.mp3$/i}.map{|z| [z,File.stat(z).ino]
}.sort_by{|z| z[1]
}.collect.with_index.map{|z,i| [i+1,z[0]].join(" -> ")
}.join("\n")
require "nokogiri"
require "json"
require "open-uri"
url=ARGV[0]||"https://hu.wikipedia.org/wiki/Magyarorsz%C3%A1g_v%C3%A1rosai"
d=Nokogiri::HTML(URI.open(url).read)
table=d.css(".wikitable").max_by{|z| z.to_html.size}
th=table.css("tr").css("th").map{|z| z.text.chomp.strip.scan(/([[:alpha:]]+)/).flatten[0]}
puts %Q{/*#{th.join("|")}*/\n}+JSON.pretty_generate(table.css("tr")[1..-1].map{|row| row.css("td").map{|cell| data=cell.text.chomp.strip;data=~/^[0-9\s\u00a0]+$/ ? data.gsub(/[\s\u00a0]+/,"").to_i : data}}.reject{|row| row.size==0})
@Konstantinusz
Konstantinusz / nevnapok.json
Last active February 3, 2025 14:36
Magyar névnapok és becenevek JSON formátumban
{
"Aba": {
"n": {
"11-12": 1
},
"s": "F"
},
"Abád": {
"n": {
"04-16": 1,
{
"Andor": {
"n": {
"11-30": 1
},
"s": "F"
},
"Apollinár": {
"n": {
"01-08": 1,
@Konstantinusz
Konstantinusz / nevnapok.rb
Created September 7, 2020 09:59
Redundancia csökkentése
nevnapok=nevnapok.map{|k,v| [k,v["t"] ? {"t"=>v["t"]} : {"n"=>v["n"],"s"=>v["s"]}]}.sort_by{|k,v| k.unicode_normalize(:nfd)}.to_h