Skip to content

Instantly share code, notes, and snippets.

@kryptykphysh
kryptykphysh / app.js
Last active June 20, 2017 20:41
Simple React app
class Button extends React.Component {
handleClick = () => {
this.props.onClickFunction(this.props.incrementValue);
}
render() {
return (
<button onClick={this.handleClick}>
+{this.props.incrementValue}
</button>
@kryptykphysh
kryptykphysh / imagise.rb
Created March 13, 2014 09:16
Syntax highlight code and convert to image
#!/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
@kryptykphysh
kryptykphysh / logger.rb
Last active October 10, 2016 16:45
Ruby: Logging module with class names, output to both STDOUT and file
require 'logger'
module Logging
class MultiDelegator
def initialize(*targets)
@targets = targets
end
def self.delegate(*methods)
methods.each do |m|
@kryptykphysh
kryptykphysh / sale_total.rb
Last active January 2, 2016 15:39
Code solution for Suyesh Bhandari
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
@kryptykphysh
kryptykphysh / log_test.rb
Created December 18, 2013 10:15
Messing about with Logger
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'
@kryptykphysh
kryptykphysh / gist:6446380
Created September 5, 2013 05:29
Showing how a Python return value needs to be inside the body of a function.
# 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.
@kryptykphysh
kryptykphysh / cuttlefish.rb
Last active December 17, 2015 04:29
Demonstrating the spaceship operator.
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