Skip to content

Instantly share code, notes, and snippets.

def blocks_double_render_error
@books = Book.all
render 'index' and return
render 'show'
@books.last.update_column(:title, 'Or am I?')
end
#=> Rendering books/index.html.haml within layouts/application
#=> Book.last.title
#=> "Surprise Surprise"
@Schwad
Schwad / deploy
Created December 5, 2017 16:19
bin/deploy deployment of a Ruby on Rails application to Heroku
# Sets up APPLICATION_NAME_HERE and deploys to Heroku. This should be run while on master
# NOTE: if you get a permission denied error, try running `chmod u+x bin/deploy` in the terminal
# Fails script if any commands fail
set -e
echo '== Installing dependencies =='
bundle install
class Current < ActiveSupport::CurrentAttributes
attribute :account, :user
attribute :request_id, :user_agent, :ip_address
resets { Time.zone = nil }
def user=(user)
super
self.account = user.account
Time.zone = user.time_zone
class AttributesApiExample < ApplicationRecord
attribute :start_date, :date, default: -> { 1.day.from_now }
attribute :end_date, :date, default: -> { 8.days.from_now }
attribute :my_attribute, :my_type, default: -> { 'My Default Value' }
end
@Schwad
Schwad / Sandbox.rb
Created May 11, 2018 12:43
Description to self about certain ruby methods. For safe keeping really. If you've stumbled on here for some reason, hello!
# Enumerable's Detect
# - returns first element for which block returns true and then stops. If none returns nil.
(1..100).detect { |i| i % 5 == 0 and i % 7 == 0 } #=> 35
# Find All
(1..10).find_all { |i| i % 3 == 0 } #=> [3, 6, 9]
# Reject
@Schwad
Schwad / update-chrome-driver.sh
Last active February 6, 2019 14:56 — forked from fantactuka/update-chrome-driver.sh
Update Chrome driver for mac os to 2.46
#!/bin/bash
# bash < <(curl -s https://gist.githubusercontent.com/fantactuka/3228898/raw/f0806a64306426ca72f16734ae7cd16c1f84bd87/update-chrome-driver.sh)
echo "Updating Chrome Driver"
sudo su
if [ -e /usr/bin/chromedriver ]; then
rm /usr/bin/chromedriver
echo "Removing current Chrome Driver from /usr/bin"

Keybase proof

I hereby claim:

  • I am schwad on github.
  • I am schwad (https://keybase.io/schwad) on keybase.
  • I have a public key whose fingerprint is 3C9A 6DC1 2573 C25F BE23 22FF AB00 9D50 E34A E076

To claim this, I am signing this object:

@Schwad
Schwad / destroyer.rb
Last active November 25, 2019 14:30
@apotonick Tesla Truck implementation
module Tesla
module Truck
module Destroyer
def self.call(human_name:)
puts "Das #{human_name} wurde zerstört."
end
end
end
end
class NilClass
def method_missing(method, *args)
<<~EOAA
Somebody once told me the world is gonna roll me
I ain't the sharpest tool in the shed
She was looking kind of dumb with her finger and her thumb
In the shape of an "L" on her forehead
Well, the years start coming and they don't stop coming
Fed to the rules and I hit the ground running
Didn't make sense not to live for fun