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 Button extends React.Component { | |
handleClick = () => { | |
this.props.onClickFunction(this.props.incrementValue); | |
} | |
render() { | |
return ( | |
<button onClick={this.handleClick}> | |
+{this.props.incrementValue} | |
</button> |
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/env ruby | |
require 'pygmentize' # gem install pygmentize | |
require 'selenium-webdriver' # gem install selenium-webdriver | |
exit unless code_path = ARGV.shift | |
file_path = File.absolute_path 'code.html' | |
image_path = File.absolute_path 'code_image.png' | |
code = Pygmentize.process File.read(code_path), :ruby | |
html = <<-EOT |
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
require 'logger' | |
module Logging | |
class MultiDelegator | |
def initialize(*targets) | |
@targets = targets | |
end | |
def self.delegate(*methods) | |
methods.each do |m| |
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 Sale | |
attr_accessor :b2b_total, :webpos_total | |
def initialize(b2b_total, webpos_total) | |
@b2b_total = b2b_total.to_i | |
@webpos_total = webpos_total.to_i | |
end | |
def total | |
@b2b_total + @webpos_total |
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
require 'logger' | |
# Create new log file, or append to existing one. | |
log_file = File.open('log_test.txt', File::WRONLY | File::APPEND) | |
# Create log to rotate at 1MB and keep 10 logs. | |
log = Logger.new(log_file, 10, 1024000) | |
# Set the program name for logging purposes. | |
log.progname = 'Log Test' |
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
# Working function | |
def my_function(parameters): | |
# Body of the function goes here | |
return 'stuff returned' # Note, this has to be indented fourspaces to be inside the function. | |
# This function returns a Syntax Error | |
def my_function(parameters): | |
# Body of function | |
return 'stuff returned' # This returns a Syntax Error as the return statement | |
# is outside the function definition. |
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 Cuttlefish | |
# Because we've defined <=> we can use all the Comparable methods | |
# http://ruby-doc.org/core-2.0/Comparable.html | |
include Comparable | |
attr_reader :name, :ink_capacity | |
def initialize(name, ink_capacity = 0) | |
@name = name | |
@ink_capacity = ink_capacity | |
end |