Skip to content

Instantly share code, notes, and snippets.

@jadon1979
jadon1979 / fizz_buzz.rb
Last active June 17, 2024 20:19
Fizz buzz test
#!/usr/bin/env ruby
# frozen_string_literal: true
# Readable and fast
require 'benchmark'
class FizzBuzz
FIZZ = 'Fizz'.freeze
BUZZ = 'Buzz'.freeze
@jadon1979
jadon1979 / Game.rb
Created April 19, 2024 17:06
A code test for a working command line version of Battleship.
require_relative './player.rb'
# Represents the game. Manages the flow of the game and players' turns.
class Game
attr_reader :player1, :player2
# Initializes a new game with two players and a specified board size.
#
# @param board_size [Integer] the size of the game board.
def initialize(board_size = 10)
@jadon1979
jadon1979 / explained.txt
Created August 6, 2020 15:15
public, private, protected
bob = Person.new('Bob', 'Smith', 'bob@example.com', '444-333-4444')
john = Person.new('John', 'Smith', 'john@example.com', '555-444-3333')
# full_nane is a public method
bob.full_name
# => "Smith, Bob"
john.full_name
# => "Smith, John"
# email is a protected method.
@jadon1979
jadon1979 / bursty.rb
Last active August 9, 2017 18:26
bursty.rb, securities.rb, data.csv: Show growth spikes for a given period of time (per test req).
require 'forwardable'
require_relative 'securities'
class Bursty
extend Forwardable
def_delegators :securities, :companies, :symbols
MONTHS = %w(January February March April May June July August September October November December)
YEARS = (2007..2017).map(&:to_s)
@jadon1979
jadon1979 / Dockerfile
Last active August 11, 2017 18:50
quick and dirty docker setup..
FROM ubuntu:16.04
RUN apt-get update && \
apt-get -y upgrade && \
apt-get install -y build-essential && \
apt-get install -y software-properties-common && \
apt-get install -y vim curl git man unzip wget && \
apt-get install -y net-tools iputils-ping apache2 apache2-utils
RUN apt-get purge `dpkg -l | grep php| awk '{print $2}' |tr "\n" " "` & \
@jadon1979
jadon1979 / customer.rb
Created November 30, 2016 16:02
# /v1/customers?inactive=false&states=FL
class Customer < ActiveRecord::Base
include Concerns::ResourceBuilder
self.ref_type_key = :customer
self.table_name = "D_customer"
self.primary_key = 'pkId'
scope :states, -> (list) { where(state: list.split(',').map(&:strip)) }
end
tree = [
// branch eles
[
// spouse ele
[]
// spouse ele
[],
// spouse ele
[],
// branch eles
// relation = ['Mother', 'Father', 'Son', 'Daughter', etc]
{
"name": "",
"relation": "",
"branch": [
"name": "",
"relation": "",
"branch": [
"name": "",
"relation": "",
@jadon1979
jadon1979 / block.rb
Created October 10, 2014 15:16
Another block example for you
def create_tag(tag, **args)
attributes = args.map { |k,v| " #{k}=\"#{v}\"" }.join
block = yield if block_given?
"<%s%s>%s</%s>" % [tag, attributes, block, tag]
end
=begin
a
/ \
b c
/ / \
d e f
tree = ['a', ['b', 'd' ], ['c', 'e', 'f']]