Skip to content

Instantly share code, notes, and snippets.

View gaborbata's full-sized avatar

Gabor Bata gaborbata

  • Szeged, Hungary
View GitHub Profile
@gaborbata
gaborbata / gen_busybox_batch.rb
Last active August 29, 2015 14:05
Generate separate Windows batch files for BusyBox
#!/usr/bin/env ruby
# encoding: UTF-8
list = `busybox.exe --list`
list.split("\n").each do |command|
file = File.new("#{command.strip}.bat", "w:UTF-8")
file.puts("@echo off")
file.puts("busybox.exe #{command} %*")
file.close
end
@gaborbata
gaborbata / plist.rb
Created September 2, 2014 21:47
Creates m3u playlists and sfv compatible checksum list from list of music files in the current directory.
#!/usr/bin/env ruby
# Creates m3u playlists and sfv compatible checksum list
# from list of music files in the current directory.
require 'zlib'
entries = Dir.glob('*.{mp3,ogg,m4a,flac}').sort
if entries.size > 0 then
require 'openssl'
require 'digest/sha2'
content = "Super secret content."
sha256 = Digest::SHA2.new(256)
aes = OpenSSL::Cipher.new("AES-256-CBC")
iv = rand.to_s
key = sha256.digest("secret123")
@gaborbata
gaborbata / boxbot4k.html
Last active August 29, 2015 14:10
BoxBot4k - Sokoban game in 4 kB of JavaScript (for pouët.net)
<!DOCTYPE html><html><title>B4K</title><canvas id="c" width="448" height="384"></canvas><script>function D(t){var x,o=t.split("|"),e=o.shift();for(x=o[N];x--;)e=e.replace(RegExp(o[x].charAt(0),"g"),o[x].substring(1));return e}function g(t,x,o,e){for(e=o[N];e--;)o[e]=t.charCodeAt(x*o[N]+e)-Z}function l(x,o){for(0>v?v=49:v>49&&(v=0),m=0,h=0,f=!1,g(L,v,t),x=W;x--;)for(o=H;o--;)4==t[W*o+x]&&(t[W*o+x]=1,u.x=x,u.y=o)}function p(x,o,e){for(x=3;x--;){for(o=W;o--;)for(e=H;e--;)q?2!=x||t[W*e+o]>2?1==x&&t[W*e+o]>2?w[M](z[8],o*Z+4,e*Z+4):0==x&&t[W*e+o]>2&&w[M](z[t[W*e+o]],o*Z,e*Z):w[M](z[t[W*e+o]],o*Z,e*Z):w[M](z[0],o*Z,e*Z);1==x&&q?w[M](z[7],u.x*Z+4,u.y*Z+4):0==x&&q&&w[M](z[4],u.x*Z,u.y*Z)}if(w.font="bold 14px sans-serif",w[S]="rgba(255,255,255,.4)",w.textAlign="center",q)f&&w[F](E[0],C,19),w[F](E[11]+(v+1)+E[10]+E[12]+m+E[10]+E[13]+h,C,376);else{for(x=1;x<E[N]-5;x++)w[F](E[x],C,19*x+106);w[F](E[9],C,376)}}function B(x,o,e,r,n,y){for(w=O.c[X]("2d"),z=Array(P[N]),o=Array(256),x=z[N];x--;){for(g(I,P[x][3],o),e=document.cr
@gaborbata
gaborbata / gerrit.rb
Last active August 29, 2015 14:26
Script to help gerrit usage
#!/usr/bin/env ruby
DEFAULT_GERRIT_PORT = '29418'
if ENV['GERRIT_USER'] && ENV['GERRIT_HOST']
gerrit_uri = "#{ENV['GERRIT_USER']}@#{ENV['GERRIT_HOST']}"
gerrit_port = ENV['GERRIT_PORT'].nil? ? DEFAULT_GERRIT_PORT : ENV['GERRIT_PORT']
# %1$s and %2$s etc. denotes the command line arguments
supported_commands = {
@gaborbata
gaborbata / color_console.rb
Last active November 16, 2015 09:16
Colorize console output
#!/usr/bin/env ruby
require 'open3'
require 'colorize'
Open3.popen3(ARGV[0]) do |stdin, stdout, stderr, wait_thr|
while line = stdout.gets
if line.start_with?('WARN')
print line.colorize(:yellow)
elsif line.start_with?('ERROR')
@gaborbata
gaborbata / ProgrammersDay.java
Last active September 12, 2016 12:28
ProgrammersDay.java
import java.time.LocalDate;
public class ProgrammersDay {
private static void message() {
System.out.println("Happy International Programmers' Day :)");
}
public static void main(String[] args) {
LocalDate date = LocalDate.now();
@gaborbata
gaborbata / programmers_day.rb
Created September 12, 2016 12:28
programmers_day.rb
require 'date'
current_date = DateTime.now
year = current_date.year
month = current_date.month
day = current_date.day
leap_year = Date.leap?(year)
def message
puts "Happy International Programmers' Day :)"
@gaborbata
gaborbata / dockerw.rb
Last active September 12, 2017 15:01
Docker Wrapper
#!/usr/bin/env ruby
# Wrapper for docker command, which extends that with more commands:
# - docker rm all : removes all containers
# - docker rmi all : removes all images
# - docker stop all : stops all containers
# - docker clean : stops and removes all containers and images
def remove_all_containers
ids = `docker ps -a -q`.each_line.map {|line| line.chomp}.join(' ')
@gaborbata
gaborbata / urlchecker.rb
Created September 22, 2017 09:33
Sitemap URL Checker
#!/usr/bin/env ruby
# Sitemap URL Checker
#
# MIT License
#
# Copyright (c) 2017 Gabor Bata
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal