Skip to content

Instantly share code, notes, and snippets.

View coderxin's full-sized avatar
🦀

Andrejs Eisaks coderxin

🦀
  • Zürich, Switzerland
  • 18:24 (UTC +02:00)
  • X @coderxin
View GitHub Profile
Failures:
1) Pricing should require circle_vehicle_id to be set
Failure/Error: it { is_expected.to validate_presence_of(field) }
Expected errors to include "muss ausgefüllt werden" when circle_vehicle_id is set to nil,
got no errors
# ./spec/support/model_macros.rb:9:in `block (2 levels) in validates_presence_of'
# ./spec/spec_helper.rb:114:in `block (3 levels) in <top (required)>'
# /Users/andrew/.rvm/gems/ruby-2.2.2@car_share/gems/i18n-0.7.0/lib/i18n.rb:257:in `with_locale'
# ./spec/spec_helper.rb:114:in `block (2 levels) in <top (required)>'
@coderxin
coderxin / reduce_validator.rb
Last active August 29, 2015 14:27
Reduce validation messages
class ReduceValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return until record.errors.to_hash.has_key?(attribute)
record.errors[attribute].slice!(-1) until record.errors[attribute].size <= 1
end
end
@coderxin
coderxin / list_of_countries.rb
Created June 9, 2012 18:23 — forked from Aupajo/list_of_countries.rb
List of countries in a handy Ruby array
COUNTRIES = [
"Afghanistan",
"Aland Islands",
"Albania",
"Algeria",
"American Samoa",
"Andorra",
"Angola",
"Anguilla",
"Antarctica",
# Amadeusz Juskowiak <amadeusz@amanointeractive.com> 2012 - MIT License
# 1. Put inside helpers do .. end
# 2. Set CACHE_DIR to somewhere writable and private (like CACHE_DIR=File.dirname(__FILE__) + '/tmp'
# 3. Use it! You can use fragment_expire to remove cache with given name.
#
# Example:
# %h1 foo
# = cache_fragment(:report, 300) do
# - data = get_data_slowly

An incomplete cheatsheet for rails 3. Things are added as they are required.

Active Record validations

# http://guides.rubyonrails.org/active_record_validations_callbacks.html

class SomeClass < ActiveRecord::Base

  # length

Copied from http://code.lancepollard.com/complete-list-of-html-meta-tags/

Basic HTML Meta Tags

<meta charset='UTF-8'>
<meta name='keywords' content='your, tags'>
<meta name='description' content='150 words'>
<meta name='subject' content='your website's subject'>
<meta name='copyright' content='company name'>
@coderxin
coderxin / decode_session_cookie.rb
Created January 31, 2017 11:24 — forked from pdfrod/decode_session_cookie.rb
A simple script to decode Rails 4 session cookies
@coderxin
coderxin / GitHub protocol comparison.md
Created February 14, 2017 14:10
A comparison of protocols offered by GitHub (for #git on Freenode).

Primary differences between SSH and HTTPS. This post is specifically about accessing Git repositories on GitHub.

Protocols to choose from when cloning:

plain Git, aka git://github.com/

  • Does not add security beyond what Git itself provides. The server is not verified.

    If you clone a repository over git://, you should check if the latest commit's hash is correct.

@coderxin
coderxin / README-Template.md
Created December 11, 2017 00:06 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@coderxin
coderxin / Gemfile
Last active May 31, 2018 12:34
Factories from FactoryGirl in rails console
gem 'factory_girl_instruments'