This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Address | |
include Minimapper::Entity | |
attribute :street | |
attribute :postalcode | |
attribute :city | |
attribute :country | |
validates :street, presence: true | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
UNICORN_CONF="/data/<%= @app_name %>/shared/config/unicorn.rb" | |
UNICORN_EXEC="bundle exec unicorn" | |
UNICORN_PID="/var/run/<%= @app_name %>/unicorn.pid" | |
UNICORN_MAX_RELOAD_WAIT_TIME=60000 # 60 seconds | |
RAILS_ENV="<%= @rails_env %>"; export RAILS_ENV | |
RACK_ENV="<%= @rails_env %>"; export RACK_ENV | |
APP_ROOT=/data/<%= @app_name %>/current |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Written for this gist, but inspired by production code (I haven't run this code). | |
# Imperative shell | |
class Timer | |
def initialize(record) | |
@record = record | |
end | |
def start | |
save_changes clock.start |
Single core cpu performance.
echo 'int main() { double i = 0; for(i = 0; i < 5000000000; i++) { 20%7 * i; } }' > /tmp/test.c && gcc /tmp/test.c -o /tmp/test && time /tmp/test && rm /tmp/test.c && rm /tmp/test
NOTE: It's not 100% reliable since it differs depending on compiler version.
Platform CPU Time
PC 14g i7-14700k (2023) 7.2
DELL Latitude 7430 (2022) 12g i5-1235U 9.4
MacBookPro15,1 (Mid 2018) i9 2.4 ghz 11.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copy and paste this into a terminal: | |
gem install minimapper | |
gem install activemodel # required for Minimapper::Entity[::Rails] (you can use Minimapper::Entity::Core without it) | |
curl https://gist.github.com/joakimk/3904952/raw/56b592e6eaa5a0206bf9207b0ee53aa0114a53eb/minimapper_example.rb > minimapper_example.rb | |
ruby minimapper_example.rb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env rake | |
# If the code below fails, uncomment this. There are no known issues now, but we had one. | |
#require File.expand_path('../config/application', __FILE__) | |
#Auctionet::Application.load_tasks | |
#require File.expand_path('../lib/tasks/no_rails', __FILE__) | |
#__END__ | |
# Load all non-rails tasks. | |
path = File.expand_path('../lib/tasks/no_rails', __FILE__) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Very simple CPU test. Not ideal. | |
# Setup (where possible): | |
# Ubuntu 11.04 | |
# apt-get install ruby # 1.8.7 | |
# ci:jocke $ ruby -v | |
# ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux] | |
ruby -e 't=Time.now;100000000.times { 22%5 };puts Time.now-t' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Filter | |
include FormObject | |
# Proc because Date.yesterday changes every day :) | |
attribute :from, Date, default: Proc.new { Date.yesterday } | |
attribute :to, Date, default: Proc.new { 1.month.from_now - 1.day } | |
end | |
# in controller | |
@filter = Filter.new(params[:filter]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# Command to run the specs the correct way when triggered from the turbux vim plugin. | |
# | |
# - non-rails unit tests should be run without bundler env and have extra options. | |
# - rails tests should run with drb and retry if it exists right away (sometimes unreliable). | |
rails_spec = ARGV.first.start_with?("spec/") || ARGV.first.include?('/spec/') | |
if rails_spec | |
command = "rspec --drb" |