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

<div class="section">
<div class="header">Header</div>
<div class="content">
<div class="sidebar">Sidebar</div>
<div class="article">Article</div>
</div>
<div class="footer">Footer</div>
</div>

SPACEMACS

#notes

@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
Fetching libv8 6.7.288.46.1
Installing libv8 6.7.288.46.1 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /Users/amree/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/libv8-6.7.288.46.1/ext/libv8
/Users/amree/.rbenv/versions/2.5.0/bin/ruby -r ./siteconf20191021-37951-cidhuv.rb extconf.rb
creating Makefile
________ running 'git -c core.deltaBaseCacheLimit=2g clone --no-checkout --progress https://chromium.googlesource.com/v8/v8.git
/Users/amree/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/libv8-6.7.288.46.1/vendor/_gclient_v8_OSkH9q' in '/Users/amree/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/libv8-6.7.288.46.1/vendor'
#!/usr/bin/env ruby
# frozen_string_literal: true
# README
# - gem install git
# - Update the ticket prefix
# - Update the branch name
# - Put this in /usr/local/bin and chmod +x it
require 'git'
@amree
amree / file.js
Last active December 14, 2020 08:03
/** @preserve jQuery.floatThead 2.2.1 - https://mkoryak.github.io/floatThead/ - Copyright (c) 2012 - 2020 Misha Koryak **/ ! function(bt) {
bt.floatThead = bt.floatThead || {}, bt.floatThead.defaults = {
headerCellSelector: "tr:visible:first>*:visible",
zIndex: 1001,
position: "auto",
top: 0,
bottom: 0,
scrollContainer: function(t) {
return bt([])
},
@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
id country state city postcode created_at updated_at
1 Malaysia Johor Ayer Baloi 82100 2020-05-12 06:48:36 UTC 2020-05-12 06:48:36 UTC
2 Malaysia Johor Ayer Hitam 86100 2020-05-12 06:48:37 UTC 2020-05-12 06:48:37 UTC
3 Malaysia Johor Ayer Tawar 2 81920 2020-05-12 06:48:39 UTC 2020-05-12 06:48:39 UTC
4 Malaysia Johor Bandar Penawar 81930 2020-05-12 06:48:41 UTC 2020-05-12 06:48:41 UTC
5 Malaysia Johor Bandar Penawar 81960 2020-05-12 06:48:41 UTC 2020-05-12 06:48:41 UTC
6 Malaysia Johor Bandar Tenggara 81440 2020-05-12 06:48:43 UTC 2020-05-12 06:48:43 UTC
7 Malaysia Johor Batu Anam 85100 2020-05-12 06:48:44 UTC 2020-05-12 06:48:44 UTC
8 Malaysia Johor Batu Pahat 83000 2020-05-12 06:48:46 UTC 2020-05-12 06:48:46 UTC
9 Malaysia Johor Batu Pahat 83010 2020-05-12 06:48:46 UTC 2020-05-12 06:48:46 UTC