Skip to content

Instantly share code, notes, and snippets.

@starwels
starwels / linux-setup.sh
Created May 16, 2024 13:07 — forked from dhh/linux-setup.sh
linux-setup.sh
# CLI
sudo apt update -y
sudo apt install -y \
git curl \
docker.io docker-buildx \
build-essential pkg-config autoconf bison rustc cargo clang \
libssl-dev libreadline-dev zlib1g-dev libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev libjemalloc2 \
libvips imagemagick libmagickwand-dev mupdf mupdf-tools \
redis-tools sqlite3 libsqlite3-0 libmysqlclient-dev \
rbenv apache2-utils
require 'benchmark'
array = []
array2 = []
CONST = 100_000
TEMPLATE = [[1,2],[1,2]]
time2 = Benchmark.measure do
CONST.times do
@starwels
starwels / rspec_model_testing_template.rb
Created April 13, 2020 15:01 — forked from thadeu/rspec_model_testing_template.rb
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
class PostsController < ApplicationController
def index
@posts = PostPresenter.new.index
end
end
class PostPresenter
def index
posts = Post.includes(:comments).order(id: :asc).as_json(include: [:comments])
posts.map { |post| post['status'] = post['created_at'] < post['updated_at'] ? '(edited)' : '(first version)' }
end
end
<div>
posts: <%= @posts.size %> <br>
<% @posts.each do |post| %>
<%= post['title'] %>
<hr>
<%= post['body'] %>
<%= post['status'] %>
<hr>
comments: <%= post['comments'].size %> <br>
<% post['comments'].each do |comment| %>
class Post < ApplicationRecord
has_many :comments
end
class Comment < ApplicationRecord
belongs_to :post
end
class PostsController < ApplicationController
def index
@posts = Post.all.order(id: :asc)
end
end
<div>
posts: <%= @posts.count %> <br>
<% @posts.each do |post| %>
<%= post.title %>
<hr>
<%= post.body %>
<% if post.created_at < post.updated_at %>
(edited)
<% else %>
(first version)
10.times do |num|
Post.create(title: "Ruby is Awesome #{num}", body: 'Indeed it is') do |post|
5.times { Comment.create(body: "Comment #{num}", post: post) }
end
end