Skip to content

Instantly share code, notes, and snippets.

require 'delegate'
class HiddenDelegator < SimpleDelegator
def initialize(obj)
super
end
def class
__getobj__.class
end
@Hanmac
Hanmac / 03-lottery.rb
Last active December 16, 2015 10:28 — forked from repomaa/03-lottery.rb
def draw n=6
to_enum(__method__) unless block_given?
draw_all(n).each do |number|
break unless number
yield number
end
end
def draw_sorted n=6
to_enum(__method__) unless block_given?
@Hanmac
Hanmac / regex.rb
Last active December 18, 2015 03:19 — forked from bricker/regex.rb
m = query.query_url.match(Regexp.union(
/form_code=(?<id>[a-zA-Z0-9]+)/,
/form\/.+?\/(?<id>[a-zA-Z0-9]+)/,
/iframe\/(?<id>[a-zA-Z0-9]+)/))
class ReadIngredients
def perform
while input = gets.chomp
break if input == 'done'
yield input
end
end
end
ingredients = []
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
#
# Copyright (c) 2014 Marvin Gülker
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
@Hanmac
Hanmac / gemtree.rb
Last active August 29, 2015 14:04
GemTree
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'optparse'
require 'ostruct'
# using list from graph gem
COLOR_SCHEME_MAX = {
accent: 8, blues: 9, brbg: 11, bugn: 9,
dark2: 8, gnbu: 9, greens: 9, greys: 9,
@Hanmac
Hanmac / test.rb
Last active March 13, 2016 21:02
def snapshot_description
initialization
@resp.snapshots.each do |n|
if name = n.tags.find { |t| t.key == 'Name' }
desc = name.value
end
if n.start_time < @threshold
@count += 1
snapshot_list(n, desc)
end
id, group_by_column1, group_by_column2, group_by_column3, class_id, value
1, "A", "1", "0", 6, 17
2, "A", "1", "1", 6, 17
3, "A", "1", "2", 6, 17
4, "A", "1", "3", 6, 17
5, "A", "1", "0", 5, 10
6, "A", "1", "1", 5, 10
7, "A", "1", "2", 5, 10
8, "A", "1", "3", 5, 10