Skip to content

Instantly share code, notes, and snippets.

View heftig's full-sized avatar
🦄
Horsing around

Jan Alexander Steffens heftig

🦄
Horsing around
View GitHub Profile
# encoding: utf-8
require 'rubygems'
require 'yaml'
def maybe_gem(name)
gem name
rescue Gem::LoadError
nil
end
require 'benchmark'
require 'set'
array = (1..10000).to_a
set = array.to_set
probes = 10000.times.map { rand(20000) }
Benchmark.bmbm do |bm|
bm.report("Array") { probes.each { |p| array.include? p } }
bm.report("Set") { probes.each { |p| set.include? p } }
triangle = Enumerator.new do |e|
arr = [1]
loop do
e << arr.join(" ")
arr = [1, *arr.each_cons(2).map { |x| x.inject(:+) }, 1]
end
end
while (depth = gets.to_i) > 0
lines = triangle.take(depth)
#!/usr/bin/env ruby
until (words = gets.chomp.split).empty?
stack = []
words.each do |w|
begin
stack.push Float(w)
rescue ArgumentError
args = stack.pop(Float.instance_method(w).arity + 1)
stack.push args.first.send(w, *args[1..-1])
class Enumerator
class Do < BasicObject
def initialize(enum)
@enum = enum
end
def method_missing(meth, *args, &blk)
@enum.each do |x|
x.send(meth, *args, &blk)
end
require 'java'
url = Java::JavaNet::URL.new("file:///usr/share/sounds/alsa/Front_Center.wav")
clip = Java::JavaApplet::Applet.newAudioClip(url)
clip.play
sleep 3
def fetch_ftp
ftp = Net::FTP.new(self.meta[:host])
ftp.login(user = self.username, passwd = self.password)
buffer = ""
ftp.getbinaryfile(self.url) { |data| buffer << data }
ftp.quit()
MultiXml.parse(buffer) rescue nil
# grub-mkimage -d /usr/lib/grub/x86_64-efi -O x86_64-efi -p /grub -o /boot/EFI/boot/bootx64.efi part_gpt fat normal boot configfile
set color_normal=white/black
set color_highlight=black/white
set menu_color_normal=blue/black
set menu_color_highlight=black/blue
set timeout=1
insmod efi_gop
set default=0
BEGIN {
require "fileutils"
FileUtils.touch("run.old")
$stdout = $stderr = open("run","w")
}
END {
system("diff -u run.old run")
FileUtils.mv("run", "run.old", :force => true)
}
def printgrid(table)
strings = table.map do |row|
row.map { |cell| cell.to_s }
end
column_widths = []
strings.each do |row|
row.each_with_index do |cell,i|
column_widths[i] = [column_widths[i] || 1, cell.length + 2].max
end