Skip to content

Instantly share code, notes, and snippets.

@0x5d
0x5d / ruby-hello-world
Created July 8, 2015 19:20
A hello world for my first Medium entry.
puts 'Hello world.'
@0x5d
0x5d / machine-epsilon.go
Last active August 29, 2015 14:26
Machine epsilon calculation in some languages.
package main
import "fmt"
func main() {
x := 1.0
for ; (1 + x) > 1; x = x / 2 { }
fmt.Printf("%v\n", x * 2)
}
@0x5d
0x5d / configuration_example.rb
Last active August 29, 2015 14:28
An example demonstrating the block configuration pattern in Ruby.
require 'singleton'
# The gem's main module.
module AwesomeGem
# A class method which yields the configuration to a block.
def self.configure
yield Configuration.instance if block_given?
end
# A class method to access the configuration instance.
@0x5d
0x5d / awesome_gem_config.rb
Created August 24, 2015 20:07
A gist to show how a block configuration can be used.
require 'awesome_gem'
AwesomeGem.configure do |config|
config.do_magic = true
config.awesome_string = 'The most awesomest string.'
end
# OtherModule has the methods do_stuff_with and do_magic,
# which are like, super important, ok?
require 'other_module'
module AwesomeGem
class AwesomeClass
include OtherModule
do_stuff_with AwesomeGem.configuration.awesome_string
do_magic if AwesomeGem.configuration.do_magic?
require 'singleton'
# The gem's main module.
module AwesomeGem
# A class method which yields the configuration to a block.
def self.configure
yield Configuration.instance if block_given?
# Call all the registered listeners after configuration has taken place!
Configuration.instance.listeners.each { |listener| listener.call }
end
@0x5d
0x5d / awesome_gem_class_v2.rb
Created August 24, 2015 20:55
The updated version of the class retrieving AwesomeGem's configuration, with the event implementation.
# OtherModule has the methods do_stuff_with and do_magic,
# which are like, super important, ok?
require 'other_module'
module AwesomeGem
class AwesomeClass
include OtherModule
# Pass our method calls on a block, so they're called
# after the configuration has taken place.
{
"coord": {
"lon": -0.13,
"lat": 51.51
},
"weather": [
{
"id": 800,
"main": "Clear",
"description": "Sky is Clear",
package com.mycompany.myfirstapp.model.weather;
public class WeatherInfo {
private Weather[] weather;
private String name;
public Weather[] getWeather() {
return weather;
}
package com.mycompany.myfirstapp.model.weather;
public class Weather {
private String description;
public String getDescription() {
return description;
}