Skip to content

Instantly share code, notes, and snippets.

View eriktorsner's full-sized avatar

Erik Torsner eriktorsner

  • Stockholm, Sweden
View GitHub Profile
@eriktorsner
eriktorsner / WordPressMultisiteValetDriver.php
Created August 18, 2023 11:04
Updated WordPress multisite driver for valet 4
<?php
namespace Valet\Drivers\Custom;
use Valet\Drivers\BasicValetDriver;
/*
Valet driver for Wordpress Multisite
Usage: Drop this file into your ~/.valet/Drivers/ directory
@eriktorsner
eriktorsner / test_dependencies.php
Last active August 6, 2021 13:03
test dependencies example
<?php
class Item_handler {
public static function upload_one() {
// Do something expensive with lots of deps
return true;
}
public function upload_two() {
// Do something expensive with lots of deps
<?php
$secret = 'top_secret';
$url = 'https://example.com/wa-hook/abc123abc123
$parameters = ['foo' => 'bar'];
$args = ['headers' => []];
$args['body'] = json_encode($parameters);
$hash = hash_hmac('sha1', $args['body'], $secret);
$args['headers']['Content-Type'] = 'application/json; charset=utf-8';
@eriktorsner
eriktorsner / cardMap.js
Last active February 1, 2018 09:09
Small script to display AMD GPU ordering in xmr-stak vs OverdriveNTool.
/********************************************************
*
* Small script to display AMD GPU ordering in xmr-stak vs OverdriveNTool.
*
* To run this script, you first need to create a correctly named
* textfile with clinfo output. Use this command to create the file:
*
* C:\some\folder> clinfo | findstr "Device Topology" > clinfo_topology.txt
*
* TIP: Add the above command to your windows startup script, that way you
@eriktorsner
eriktorsner / RuntimeProvider.php
Last active December 27, 2017 10:06
Snippet from RuntimeProvider.php
<?php
/**
* Class RuntimeProvider
*
* Use Pimple as dependency injection container
*
*/
class RuntimeProvider implements ServiceProviderInterface
{
/**
<?php
// Solution 1. Let ElectricCar handle unplugging itself
class ElectricCar extends Car
{
...
public function start()
{
$this->unplug();
parent::start();
<?php
class Driver
{
private $car;
public function __construct($car)
{
$this->car = $car;
}
<?php
class Car
{
public function start()
{
/// wrooom
}
}
@eriktorsner
eriktorsner / hello-bootstrap.php
Last active April 25, 2017 23:59
Snippet from hello-bootstrap.php
<?php
/**
* The main plugin function. Checks php version
* and initialize our classes
*/
function helloTestableBootstrap()
{
$pluginVersion = '0.1.0';
if (defined('DOING_AJAX') && DOING_AJAX) {
return;
@eriktorsner
eriktorsner / LyricsTest.php
Last active April 25, 2017 10:14
Snippet from LyricsTest.php
<?php
public function testGetLyric()
{
$file = dirname(__DIR__) . '/fixtures/lyrics.txt';
$lyrics = new Lyrics($file);
\WP_Mock::userFunction('wptexturize', array(
'return' => function($s) {
return $s . ' wptexturize';