This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math/rand" | |
) | |
const N_WORKERS = 10 | |
func producer(c chan int) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
## | |
# List & hash references. | |
package Class | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
# Decorator. Same idea as the Python decorators. In this case it takes a | |
# function as the only argument and returns a closure that returns the result | |
# of the originally passed function plus two. | |
sub plus_two | |
{ | |
my ($f_ref) = @_; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file shows a somewhat rare feature of Ruby with the .. operator. | |
# It's a a perlism called "flip-flop". This feature will make it into Ruby 2.0 | |
# but its future is uncertain (probably removed in a future Ruby 3.0 ?). | |
# | |
# More on flip-flops here: https://bugs.ruby-lang.org/issues/5400 | |
# Prints all the lines between begin..end in the DATA section. | |
DATA.each_line do |line| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# This file describes some topics regarding the Ruby Object Model. | |
# | |
require 'pp' | |
## | |
# First of all, let's take a look at the very basics. | |
module Modul |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# This files shows some possible implementations of the Singleton pattern | |
# in Ruby. I'm not a huge fan of the Singleton pattern, but it's nice | |
# in some cases. In this file I'm going to implement a simple logger. | |
# | |
## | |
# The first implementation that can come to our minds is to create a class | |
# that holds an instance as a class variable that can be accessed through |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# This is a simple script that creates a TCP server and then transfers | |
# the info via streaming. It's not too fancy, I'm just testing the HTTP's | |
# Transfer-Encoding: chunked; | |
# | |
require 'socket' | |
# This is the message to be sent. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# This file describes a simple way to implement the idea of pure virtual | |
# methods (abstract methods in Java, C#,...) in Ruby. Personally, I haven't | |
# used this pattern while programming in Ruby, but I thought it could be fun. | |
# | |
## | |
# This class provides a fancy way to show an error when a virtual method | |
# is being used but the subclass hasn't implemented it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Persistent(type): | |
def __new__(self, name, bases, dct): | |
self.tables = dict() | |
return super(Persistent, self).__new__(self, name, bases, dct) | |
def __init__(self, name, bases, dct): | |
table = name.lower() + 's' | |
self.tables[self] = table | |
super(Persistent, self).__init__(name, bases, dct) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
g6Rib2R5hqhkZXRhY2hlZMOpaGFzaF90eXBlCqNrZXnEIwEgG3AOLgwYvl6HQqL7124aTV4apRoR5vP1Vd/S1PASk0UKp3BheWxvYWTFAuh7ImJvZHkiOnsia2V5Ijp7ImVsZGVzdF9raWQiOiIwMTIwYzJlYTViODFkNjYxMjNkMGI3NDIzNWNlNjZmY2RlZGFmZjRkYTFmODg0MjZhMmQ3MjkyY2FhMTdhOGZjNzkxNDBhIiwiaG9zdCI6ImtleWJhc2UuaW8iLCJraWQiOiIwMTIwMWI3MDBlMmUwYzE4YmU1ZTg3NDJhMmZiZDc2ZTFhNGQ1ZTFhYT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