Hey everyone,
For a long time I've been writing boilerplate classes that have basically the same structure of initialization:
class UserRegistrationForm
def initialize(access_code)
@access_code = access_code
end
Hey everyone,
For a long time I've been writing boilerplate classes that have basically the same structure of initialization:
class UserRegistrationForm
def initialize(access_code)
@access_code = access_code
end
| require "rails_helper" | |
| RSpec.describe PokemonsController do | |
| describe "GET #index" do | |
| it "renders the index template" do | |
| get :index | |
| expect(response.status).to eq(200) | |
| expect(response).to render_template('index) | |
| end | |
| end |
| ### Rails app generator template. Run it: | |
| ### rails new _app_name_ -m https://gist.githubusercontent.com/DamirSvrtan/28a28e50d639b9445bbc/raw/app_template.rb | |
| remove_file "README.rdoc" | |
| create_file "README.md", "Development: run ./bin/setup" | |
| run 'mv app/assets/stylesheets/application.css app/assets/stylesheets/application.scss' | |
| database_type = ask("Do you want to use postgres or mysql?", limited_to: ["pg", "mysql"]) | |
| adapter = if database_type == 'pg' |
| pretty_echo() { | |
| echo_length=${#1} | |
| stars="" | |
| star_length=$(($echo_length+8)) | |
| for i in $(seq 1 $star_length); do | |
| stars="$stars*" | |
| done | |
| echo "\n"; echo "$stars"; echo "*** $1 ***"; echo "$stars"; echo "\n" | |
| }; |
| ```ruby | |
| "SERVER_SOFTWARE"=>"thin 1.6.2 codename Doc Brown", | |
| "SERVER_NAME"=>"localhost", | |
| "rack.version"=>[1, 0], | |
| "rack.errors"=>#<IO:<STDERR>>, | |
| "rack.multithread"=>false, | |
| "rack.multiprocess"=>false, | |
| "rack.run_once"=>false, | |
| "REQUEST_METHOD"=>"GET", | |
| "REQUEST_PATH"=>"/", |
| stormpath_client = Stormpath::Client.new(api_key: api_key, cache: { | |
| regions: { | |
| applications: { store: Stormpath::Cache::RedisStore, ttl_seconds: 300, tti_seconds: 300, store_opts: {:host => uri.host, :port => uri.port, :password => uri.password} }, | |
| directories: { store: Stormpath::Cache::RedisStore, ttl_seconds: 300, tti_seconds: 300, store_opts: {:host => uri.host, :port => uri.port, :password => uri.password} }, | |
| groups: { store: Stormpath::Cache::RedisStore, ttl_seconds: 300, tti_seconds: 300, store_opts: {:host => uri.host, :port => uri.port, :password => uri.password} } | |
| } | |
| }) |
| Returning an array as a response: | |
| [200, {'Content-Type' => 'text/html'}, ["<h1>Hello!</h1>"]] | |
| Benchmark: | |
| 10000 runs | |
| 0.037738 seconds total | |
| 0.0037738 millisec/run | |
| With a controller rendering a template with erb: |
| def flash_messages | |
| content_tag :div, class: "flash-messages" do | |
| flash.map do |key, value| | |
| content_tag :div, class: "alert alert-dismissable alert-#{key}" do | |
| content_tag(:span, '×'.html_safe, class: :close, 'data-dismiss' => 'alert') + value | |
| end | |
| end.join().html_safe | |
| end | |
| end |
| alias productive='git log --since="today" --oneline | sed "s/^\w\+/*/g"' |
| #!/usr/bin/env ruby | |
| require 'open3' | |
| class NojzError < StandardError | |
| def initialize(msg) | |
| @msg = msg | |
| super(msg) | |
| end |