Skip to content

Instantly share code, notes, and snippets.

View Masa331's full-sized avatar
🤠

Premysl Donat Masa331

🤠
View GitHub Profile
@Masa331
Masa331 / xterm-font-configuration.md
Last active August 29, 2015 14:24
Configuring XTerms font

Configuring linux XTerms font

XTerm can be widely configured with with use of ~/.Xresources

Font particularly can be set with line xterm*font [options]. For example mine looks like:

xterm*font: -misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso10646-1

It configures different aspects of displayed font but it's hard to generate(and understand) manually.

@Masa331
Masa331 / how_many_symbols.rb
Created July 22, 2015 15:03
How many symbols can you create on your system?
counter = 0
alphabet = %w(a b c d e f g h i j k l m n o p q r s t u v w x y z)
alphabet.permutation.each do |permutation|
permutation.join.to_sym
counter += 1
if counter % 100000 == 0
puts Symbol.all_symbols.size
end
@Masa331
Masa331 / internal_iterator.rb
Last active August 29, 2015 14:25
Simple internal iterator
class PrimeNumbers
def self.each
yield 1
yield 2
yield 3
yield 5
yield 7
yield 11
end
end
@Masa331
Masa331 / external_iterator.rb
Created July 25, 2015 10:36
Simple external iterator
class UnderFiveIterator
def initialize(collection)
@collection = collection
end
def each_under_five
@collection.each do |item|
if item < 5
yield item
end
collection = [1, 2, 3]
collection.each # or other Enumerable method without block
# => #<Enumerator: ...>
collection.to_enum # or collection.enum_for which is alias
# => #<Enumerator: ...>
enum = [1, 2, 3].each
enum.each do { |number| puts number }
# 1
# 2
# 3
# => [1, 2, 3]
enum = [1, 2, 3].each
enum.next
# => 1
enum.next
# => 2
enum.next
# => 3
enum.next
# => StopIteration: iteration reached an end
enum = Enumerator.new do |yielder|
yielder.yield 1
end
enum.each { |item| puts item }
# 1
enum = Enumerator.new do |yielder|
10.times do
yielder.yield 1
end
end
enum = Enumerator.new do |yielder|
loop do
yielder.yield 1
end
end