Skip to content

Instantly share code, notes, and snippets.

@amree
amree / Laravel-Container.md
Created October 16, 2017 15:22
Laravel's Dependency Injection Container in Depth

Laravel's Dependency Injection Container in Depth

Laravel has a powerful Inversion of Control (IoC) / Dependency Injection (DI) Container. Unfortunately the official documentation doesn't cover all of the available functionality, so I decided to experiment with it and document it for myself. The following is based on Laravel 5.4.26 - other versions may vary.

Introduction to Dependency Injection

I won't attempt to explain the principles behind DI / IoC here - if you're not familiar with them you might want to read What is Dependency Injection? by Fabien Potencier (creator of the Symfony framework).

Accessing the Container

@amree
amree / index.js Capture DOM element screenshot using Chrome headless
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// Adjustments particular to this page to ensure we hit desktop breakpoint.
page.setViewport({width: 1000, height: 600, deviceScaleFactor: 1});
await page.goto('https://www.chromestatus.com/samples', {waitUntil: 'networkidle'});
#! /usr/bin/env ruby
# usage:
# $ das_download.rb
require "mechanize"
require "fileutils"
class DasDownloader
attr_reader :agent, :email, :password
@amree
amree / retry_until_timeout_spec.rb
Created January 8, 2022 00:46 — forked from jvillarejo/retry_until_timeout_spec.rb
A timeout for failing specs when using turbo frames and hotwire
# This is how we use it
retry_until_timeout do
expect(page).to have_button('Add comment')
expect(page).to have_text('Cancell')
end
def retry_until_timeout(seconds = 10, message: 'Failed with timeout')
Timeout.timeout(seconds) do
loop do
yield