Skip to content

Instantly share code, notes, and snippets.

View Konstantinusz's full-sized avatar

konstantinusz Konstantinusz

View GitHub Profile
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")
[
[
"Baks",
"Bakson",
"Baksra",
"község",
"Csongrád",
"Kisteleki",
2294,
"6768"
@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"
@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 / 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 / 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 / check_codepoint.rb
Last active November 1, 2016 09:30
Checks if a ttf file (true type font) supports a given unicode codepoint (must be given as a 4 char hexa code, eg 2666 for BLACK DIAMOND SUIT)
#!/usr/bin/ruby
ttf=ARGV[0]
cp=ARGV[1].rjust(4,"0")
cp1="00"+cp[0..1]
cp2=cp[2..3]
s=%x{fc-query "#{ttf}"}
charset=s.scan(/charset: \n\t(.*?)\n[^\t]/m).flatten[0].split("\n\t")
row=charset.find{|r| r=~/^#{cp1}: /}
@Konstantinusz
Konstantinusz / determinant.rb
Created September 21, 2016 22:47
Linear algebra matrix calculations
require "matrix"
require "benchmark"
def mprint(m)
#pretty-print matrices
puts m.map{|z| z.map{|q| q.round(4).to_s.rjust(7," ")}.join(", ")}.join("\n")
end
#!/usr/bin/ruby
now_a=Time.now
require "cgi"
require "set"
require "json"
Code={"AD"=>"Andorra", "AE"=>"Egyesült Arab Emirátusok", "AF"=>"Afganisztán",
#!/usr/bin/ruby
require "yaml"
require "cgi"
#require "pry"
require_relative "weighted"
cgi=CGI.new(:accept_charset => "UTF-8")
puts "Content-Type: text/plain; charset=\"UTF-8\""