Skip to content

Instantly share code, notes, and snippets.

View koffeinfrei's full-sized avatar

Alexis Reigel koffeinfrei

View GitHub Profile
@koffeinfrei
koffeinfrei / README.md
Last active December 11, 2018 09:13
how-to-contribute-a-metaflop-font

Keybase proof

I hereby claim:

  • I am koffeinfrei on github.
  • I am koffeinfrei (https://keybase.io/koffeinfrei) on keybase.
  • I have a public key whose fingerprint is 26F1 300F 4F40 F679 66F0 A62D B0B7 DE56 128A 5B8F

To claim this, I am signing this object:

@koffeinfrei
koffeinfrei / README.md
Last active December 23, 2023 03:43
Idempotent seed helper for rails -> THIS IS NOW A GEM https://github.com/panter/seed_box

Idempotent seed helper for rails

  • The first model argument is the model class
  • The second argument find_or_create_by is a hash of attributes that are used for finding a record. If the record doesn't exist, it will be created. This hash is like the unique identifier of a seed record.
  • The third argument update_with is a hash of attributes that will be always set on the record, whether the record already exists or has to be created. This is useful when the seeds are extended and you want to update existing records with new attributes.

Example usage

@koffeinfrei
koffeinfrei / active_record_base_spec.rb
Last active March 6, 2016 12:01
has_many dependent spec
# File: spec/models/base_spec.rb
require 'rails_helper'
RSpec.describe 'All ActiveRecord::Base models' do
context 'has_many with :dependent key' do
each_active_record_model do |model|
has_many_relations(model).each do |has_many_relation|
it "has :dependent defined on the #{model}##{has_many_relation.name} relation" do
expect(has_many_relation.options[:dependent]).not_to be_nil
@koffeinfrei
koffeinfrei / .ruby-version
Created March 14, 2018 08:11 — forked from aishfenton/serializer_benchmarks.rb
Performance comparison of different ruby serializer methods
2.5.0
@koffeinfrei
koffeinfrei / generate_many_runner_tags.rb
Last active December 11, 2018 09:00
generate a lot of random ActsAsTaggableOn::Tag
require 'bulk_insert'
old_logger = ActiveRecord::Base.logger
ActiveRecord::Base.logger = nil
model = WhateverModel.find_by(whatever: 'something')
tag_names = ('a'..'i').to_a.permutation.to_a.shuffle.map(&:join)
tag_names_count = tag_names.count
max_id = ActsAsTaggableOn::Tag.maximum(:id)