Skip to content

Instantly share code, notes, and snippets.

@thijsnado
thijsnado / no_sidekiq_receive.rb
Created April 28, 2022 20:39
A rule put in place to prevent sidekiq tests from masking serialization issues
# frozen_string_literal: true
require "rubocop-rspec"
module Cops
# This cop ensures that sidekiq gets exercised even in places where we care
# about testing message expectations. The reason for this is sidekiq already
# doesn't queue up jobs in test mode and stubbing them out entirely masks
# issues with passing incorrect variables to sidekiq. Some example of incorrect
# variables are ones that don't cleanly serialize and deserialize as JSON, for example
@thijsnado
thijsnado / XCTestCase+variousExtensions.swift
Last active January 11, 2020 21:58
A collection of useful test extensions which reduce boilerplate in tests.
import XCTest
extension XCTestCase {
// swiftlint:disable unavailable_function
/// A helper function for failing and stoping tests. Marked
///
/// Usage:
/// ~~~
/// guard let value = valueOptional else {
/// failAndStopTests("didn't expect nil")
@thijsnado
thijsnado / CoreDataPreviewProvider.swift
Created January 3, 2020 14:57
An example of how to easily use previews with SwiftUI views that query core data.
#if DEBUG
import CoreData
import SwiftUI
/// A protocol for allowing easy use of CoreData
/// with preview provider.
///
/// NOTE: you must still
/// make preview comply with PreviewProvider:
/// ```
@thijsnado
thijsnado / void.rb
Created April 6, 2018 14:20
void.rb
Object.module_eval do
def self.void(method_name)
old_method_name = :"old_#{method_name}"
alias_method old_method_name, method_name
private old_method_name
define_method method_name do
send(old_method_name)
nil
end
@thijsnado
thijsnado / gist:a81a42caaeffaf5b951a
Last active September 8, 2020 16:46
Example of ActiveModel::Serializer selectively
# Gemfile
gem 'active_model_serializers', require: false
# config/initializers/active_model_serializers.rb
require "active_model"
require "active_model/serializer/version"
require "active_model/serializer"
require 'action_controller/serialization'
# in controller where you want to use active model serializer
@thijsnado
thijsnado / mutable.ex
Last active December 19, 2015 17:19
Suck it immutable state!
defrecord Mutant, pid: nil, _first_name: nil do
def init do
pid = spawn(Mutant, :run, [])
current_state(pid)
end
def current_state(pid) do
pid <- {self, :state }
receive do
{ :ok, record } -> record