Skip to content

Instantly share code, notes, and snippets.

View kemenaran's full-sized avatar

Pierre de La Morinerie kemenaran

View GitHub Profile
@kemenaran
kemenaran / holding_controller.rb
Created November 9, 2022 12:01
A test controller that holds a request for the given time, then returns.
# A test controller that holds a request for the given time, then returns.
# Useful for testing requests that time out in Capybara.
#
# Usage:
# mock_posts_controller = HoldingController.new
# PostsController.stubs(:new).returns(mock_posts_controller)
# mock_posts_controller.holding_actions do
# # do something that should time out
# assert_text "The request timed out"
# end
@kemenaran
kemenaran / vcr_body_as_json_excluding_matcher.rb
Created October 18, 2022 07:14
A VCR matcher that matches a request where the JSON body is identical to another, except for some keys
# Match the JSON body of the request, ignoring some specified keys.
#
# Usage:
# VCR.use_cassette(
# 'my_request',
# match_requests_on: [:host, :path, body_as_json_excluding(:timestamp)]
# )
#
# See also: body_as_json
def body_as_json_excluding(*keys)
@kemenaran
kemenaran / test_helper.rb
Created September 16, 2022 12:18
Silencing ActiveRecord SQL logs when loading Rails fixtures
# By default, ActiveRecord logs SQL statements during tests – including when
# creating fixtures.
#
# When a Rails app has many fixtures, those logs can clobber test logs with
# a lot of logged SQL statements.
#
# We could disable ActiveRecord SQL logs entirely during tests, but having
# SQL queries displayed during tests is useful. Instead this snippet disables
# the ActiveRecord SQL logs just when loading fixtures.
#
@kemenaran
kemenaran / fix-data-sym.rb
Created November 24, 2020 17:28
Adding Sorbet type annotations to a standalone Ruby script
#!/usr/bin/env ruby
#
# Given a source file, scan the unresolved data raw addresses,
# and emit an SYM file with additional data labels for those addresses.
#
# This SYM-file can then be fed into mgbdis to generate a new disassembly
# that includes the proper data blocks.
#
# For best results:
# - Document symbols in the original source file the best you can.
@kemenaran
kemenaran / colibriwp-serialization-fix.php
Last active February 16, 2022 11:01
Script to fix ColibriWP serialization errors
<?php
/**
* Plugin Name: ColibriWP Fix Options
*
* How to use:
*
* 1. Put this file inside the wp-content/plugins/ directory;
* 2. In the Wordpress Dashboard, navigate to the Extensions page;
* 3. Enable the "ColibriWP Fix Options" extension;
@kemenaran
kemenaran / dossier.rb
Created March 26, 2020 15:36
Format error messages for champs
validates_associated :champs, :champs_private
# -> Rails displays: "Champs is invalid"
validates_associated :champs, :champs_private, message: -> (object, _data) {
(object.champs + object.champs_private)
.reject(&:valid?)
.flat_map do |champ|
champ.errors.full_messages.map do |message|
"#{champ.libelle} : #{message}"
end
@kemenaran
kemenaran / gist:0ce04f976e8b338f4a54
Created May 13, 2014 09:03
Flashvars for a single Youtube video
flashvars="dashmpd=http%3A%2F%2Fmanifest.googlevideo.com%2Fapi%2Fmanifest%2Fdash%2Fplayback_host%2Fr6---sn-25ge7nez.googlevideo.com%2Ffexp%2F938647%252C945808%252C916612%252C932990%252C936103%252C913434%252C939940%252C936923%252C945044%2Fmws%2Fyes%2Fipbits%2F0%2Fkey%2Fyt5%2Fsignature%2FD449517F9688BB4C453C7B18D50DEAACDC324923.5669E0CE0EA5325147384F04EBD81985EFA35237%2Fid%2Fo-AL6KbE-hh8iY798b-T_Ftn5Ae5kgJU7AYI-xUMdzStzy%2Fas%2Ffmp4_audio_clear%252Cwebm_audio_clear%252Cfmp4_sd_hd_clear%252Cwebm_sd_hd_clear%2Fmv%2Fm%2Fms%2Fau%2Fsource%2Fyoutube%2Fmt%2F1399971692%2Fitag%2F0%2Fsparams%2Fas%252Ccmbypass%252Cid%252Cip%252Cipbits%252Citag%252Cplayback_host%252Csource%252Cexpire%2Fexpire%2F1399995998%2Fupn%2FsloiJFh6ezQ%2Fip%2F80.12.87.84%2Fsver%2F3%2Fcmbypass%2Fyes&amp;logwatch=1&amp;watch_ajax_token=QUFFLUhqbG9oSmF1dkVTLTV6YVg5Y2RhaUowMDQ3Wndxd3xBQ3Jtc0trVXlvYjZUVFI5TWlnbWE5SlZ4RU1FdmNWY1dZTWx1TVpfSnBhRk13QWdCcmc2SUFHY1JuQTZfTC1IQTUtanhxek1ReXlmQzZTQzFGdUpuLWxfWk9MY1VBaVYtRWtHTXZ1Z1lKQlZlMU8tUGN2Zl85aw%3D%3D&amp;tk=
#ifndef NS_DESIGNATED_INITIALIZER
#if __has_attribute(objc_designated_initializer)
#define NS_DESIGNATED_INITIALIZER __attribute((objc_designated_initializer))
#else
#define NS_DESIGNATED_INITIALIZER
#endif
#endif
---
:verbose: true
:update_sources: true
gem: --no-rdoc --no-ri
:backtrace: false
:bulk_threshold: 1000
:benchmark: false