I have an example YAML file:
---
- foo:
- 1
- 2
- 3
- bar: test123
- lol: test456
I have an example YAML file:
---
- foo:
- 1
- 2
- 3
- bar: test123
- lol: test456
#include <unistd.h> | |
#include <stdio.h> | |
#include <time.h> | |
#include <stdlib.h> | |
#include <string.h> | |
char *foo2 () | |
{ | |
return "FOO"; | |
} |
def evaluate(expression) | |
stack = [] | |
expression.split.each do |word| | |
case word | |
when "+" | |
stack << (stack.pop + stack.pop) | |
when "-" | |
arg1 = stack.pop | |
arg2 = stack.pop |
class Hash | |
def map_value | |
each_pair.with_object({}) { |(key, value), result| result[key] = yield value } | |
end | |
def map_key | |
each_pair.with_object({}) { |(key, value), result| result[yield key] = value } | |
end | |
def map_pair(&blk) |
def replace_line_in_file(old,new,file) | |
File.open(file) do |f| | |
File.open(file + ".new", "w") do |f2| | |
f.each_line do |line| | |
f2.puts line.gsub(old, new) | |
end | |
end | |
end | |
File.rename(file + ".new", file) | |
end |
class PokerGame | |
include Enumerable | |
include Comparable | |
attr_reader :hands, :deck | |
RANKS = %w{ 2 3 4 5 6 7 8 9 T J Q K A } | |
SUITS = %w{ S H D C } | |
def initialize(hands, cards) | |
@deck = RANKS.product(SUITS).map(&:join) |
def events_all_accounts(time) | |
self.accounts.flat_map do |account| | |
account.events.send(time, account.now).where(:client_id => self.id) | |
end.uniq.sort_by { |a| a.start_time } | |
end | |
private :events_all_accounts | |
# all upcoming events for a client | |
def future_events_all_accounts | |
events_all_accounts(:in_future) |
primes = [2] | |
current_number = 3 | |
while primes.length < 10 | |
primes.push(current_number) unless primes.any? { |p| current_number % p == 0 } | |
current_number += 2 | |
end | |
puts primes |
attr_writer :full_name | |
def full_name | |
@full_name || "#{@first_name} #{@last_name}" | |
end |
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 |