Skip to content

Instantly share code, notes, and snippets.

@elle
elle / attachment_helper.rb
Created July 21, 2014 10:29
Safe attachments
# in AttachmentsHelper:
def safe_attachment_path(attachment, size=nil)
retrieve_attachment_path(attachment.id, attachment.original_name, :size => size)
end
# and then have a route
match '/files/:id/:filename' => 'attachments#retrieve', :as => :retrieve_attachment
# and a controller action
def retrieve
@elle
elle / gist:b34da3560106027e6da8
Last active August 29, 2015 14:04
static pages
# This controller returns static pages
class PagesController < ApplicationController
end
# routes.rb
get "help", to: "pages#help"
get "about", to: "pages#about"
get "privacy", to: "pages#privacy"
# ApplicationController:
@elle
elle / sequencing.rb
Last active August 29, 2015 14:04
Sequencer
# migration
t.integer :sequence
# controller action
# and the way we've done the method, it's probably logical to put the action in test_scenarios_controller
def sequence
TestScenario.sequence=(params[:sequence])
render :json => { :status => :ok }
end
@elle
elle / data_retriever.rb
Last active August 29, 2015 14:18
cipher-movies-sugestions
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
@elle
elle / 2015-poodnyc-notes.md
Last active September 12, 2021 11:05
Notes from Poodnyc 2015 workshop

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 / playing-with-structs.rb
Last active March 7, 2016 16:14
playing-with-structs
# 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)

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 / nyc-recommendations.md
Last active October 2, 2022 22:56
NYC Recommendations
@elle
elle / vim cheatsheet.md
Created August 19, 2017 11:11 — forked from jessedearing/vim cheatsheet.md
Vim Cheatsheet

#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 / modules.md
Created August 21, 2017 06:18 — forked from JoshCheek/modules.md
Modules (lesson from 29 July 2015) covers object model, namespaces, mixins, and functions.

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