start new:
tmux
start new with session name:
tmux new -s myname
# Builds an SQL insert query for a given record | |
# | |
# @param record [ActiveRecord::Base] Record used to build the SQL insert query | |
# @return [String] SQL insert query | |
def build_insert_query(record) | |
columns = record.class.columns.reject { |col| col.name == record.class.primary_key } | |
values = columns.map { |col| record[col.name] } | |
insert_manager = Arel::InsertManager.new | |
insert_manager.into(record.class.arel_table) | |
insert_manager.insert(columns.zip(values)).to_sql |
# Make sure to have prepared statements enabled. | |
# config/database.yml | |
# test: | |
# database: ... | |
# prepared_statements: true | |
# Add this to the top scope of test/test_helper.rb or spec/rails_helper.rb and | |
# run tests as usual. | |
queries = Hash.new(0) |
# syntax = docker/dockerfile:1 | |
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile | |
ARG RUBY_VERSION=3.2.2 | |
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base | |
# Rails app lives here | |
WORKDIR /rails | |
# Set production environment |
# To display flash messages inside XHR responses, | |
# place this file in app/controllers/concerns/ | |
# then include it in ApplicationController | |
module RenderFlashNowForXhr | |
extend ActiveSupport::Concern | |
private | |
# Flash messages are not directly available for XHR requests |
def active_link_to(name = nil, options = nil, **html_options, &block) | |
options = block_given? ? name : options | |
if current_page?(options) | |
html_options[:class] = class_names(html_options[:class], :active) | |
html_options[:aria] = html_options.fetch(:aria, {}).merge(current: :page) | |
end | |
if block_given? | |
link_to options, html_options, &block |
# config/environments/test.rb | |
ActiveSupport.on_load(:active_record_postgresqladapter) do | |
# For this optimization to work, you need to recreate your test database | |
self.create_unlogged_tables = true | |
end |
# Use this validator like this | |
# | |
# class User < ApplicationRecord | |
# validates :profile_link, url: true | |
# end | |
class UrlValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, value) | |
unless valid_url?(value) | |
record.errors.add(attribute, :invalid_url) |
#!/bin/bash | |
### ABOUT | |
### Runs rsync, retrying on errors up to a maximum number of tries. | |
### Simply edit the rsync line in the script to whatever parameters you need. | |
# Trap interrupts and exit instead of continuing the loop | |
trap "echo Exited!; exit;" SIGINT SIGTERM | |
MAX_RETRIES=50 |
<?php | |
/** | |
* Twitter timeline backup | |
* | |
* Required: | |
* - PHP 8.1+ | |
* - cURL extension enabled | |
* - Windows: | |
* - download https://windows.php.net/downloads/releases/php-8.1.12-Win32-vs16-x64.zip (or a newer available version) | |
* - unzip to a folder of your choice |