Skip to content

Instantly share code, notes, and snippets.

@elle
elle / gol.rb
Last active Feb 27, 2022
Conway's game of life
View gol.rb
class LiveCell
TRANSITION_RULES = {
2 => LiveCell.new,
3 => LiveCell.new,
}
def next_generation(living_neighbours_count)
TRANSITION_RULES.fetch(living_neighbours_count) { DeadCell.new }
end
end
View gist:c06c554f78daefe09631beaa4227c1c4
# Ways to execute a shell script in Ruby
# Example Script - Joseph Pecoraro
cmd = "echo 'hi'" # Sample string that can be used
# 1. Kernel#` - commonly called backticks - `cmd`
# This is like many other languages, including bash, PHP, and Perl
# Returns the result of the shell command
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111
@elle
elle / basic_authentication.rb
Last active Dec 8, 2017
Using Rack::Auth::Basic
View basic_authentication.rb
# config/staging.rb
Rails.application.configure do
config.middleware.use "::Rack::Auth::Basic" do |u, p|
[u, p] == [ENV["BASIC_AUTH_USERNAME"], ENV["BASIC_AUTH_PASSWORD"]]
end
end
# .env
BASIC_AUTH_USERNAME = some_value
BASIC_AUTH_PASSWORD = some_password
@elle
elle / modules.md
Created Aug 21, 2017 — forked from JoshCheek/modules.md
Modules (lesson from 29 July 2015) covers object model, namespaces, mixins, and functions.
View modules.md

Modules

To understand modules, we first have to understand a little bit about how Ruby works. So, lets define the things that exist in Ruby and see how they work together. Then, we will be able to understand how modules fit into this, and what they are here for.

Definitions

View vim cheatsheet.md

#Vim Cheat Sheet

  • gqip - Reformats paragraph to textwidth
  • gq - Reformats selection
  • :Tab /= - Equally spaces based on the = symbol (requires Tabular vim plugin)
  • :setf language - Changes current language
  • :set language=language - Changes current language
  • <C-a> - Increments the number under the cursor
  • <C-x> - Decrements the number under the cursor
  • ~ - Toggles case and moves to next character in normal mode
@elle
elle / nyc-recommendations.md
Last active Oct 2, 2022
NYC Recommendations
View nyc-recommendations.md
View code-problems.md

Coding Problems

Evaluation criteria

  • Code demonstrates knowledge of Ruby syntax, style, organisation, and refactoring
  • Code is divided into logical components and methods with clear responsibility.
  • Code meets all requirements as laid out per the specification.

In one sentence: we are looking for simplicity, readability, and good practices

@elle
elle / playing-with-structs.rb
Last active Mar 7, 2016
playing-with-structs
View playing-with-structs.rb
# POODR page 28
Wheel = Struct.new(:rim, :tire)
def wheelify(data)
data.collect {|cell| Wheel.new(cell[0], cell[1])}
end
# POODR Page 32
class Gear
attr_reader :chainring, :cog, :wheel
def initialize(chainring, cog, rim, tire)
@elle
elle / 2015-poodnyc-notes.md
Last active Sep 12, 2021
Notes from Poodnyc 2015 workshop
View 2015-poodnyc-notes.md

Rules for Horizontal Refactoring

  • If you go red, undo
  • Only change one line at a time
  1. Find two strings that are the most alike
  2. Find the smallest difference
  3. Make the smallest change that make the tests pass

How to make a small change

@elle
elle / data_retriever.rb
Last active Aug 29, 2015
cipher-movies-sugestions
View data_retriever.rb
require "json"
require "net/http"
class DataRetriever
include ActiveModel::Model
attr_reader :search_param, :search_by_id
def get_data(search_param, options = {})
@search_by_id = options.fetch([:search_by_id], false)
@search_info = search_info