Skip to content

Instantly share code, notes, and snippets.

View jackdpeterson's full-sized avatar

Jack Peterson jackdpeterson

View GitHub Profile
@jackdpeterson
jackdpeterson / TypedCollection.php
Created July 30, 2018 23:43
Sample immutable Typed collection
<?php
final class ImageCollection implements \Iterator, \JsonSerializable, \Countable
{
private $data;
public function __construct(array $values)
{
$this->data = (function (Image ...$values) {
return $values;
@jackdpeterson
jackdpeterson / dock.sh
Created April 4, 2018 18:05
Ubuntu 18.04 - Mixed DPI with 4k Laptop monitor (HiDPI), and two LoDPI monitors (27", 21")
#!/bin/bash
echo "setting frame buffer" &&
xrandr --fb 12800x2880 &&
echo "setting laptop monitor" &&
xrandr --output eDP-1-1 --mode 3840x2160 --rate 60 --primary&&
echo "setting 27 inch monitor" &&
xrandr --output DP-0.2 --mode 2560x1440 --scale-from 5120x2880 --panning 5120x2880+3840+0 --right-of eDP-1-1 &&
echo "setting the samsung monitor" &&
xrandr --output DP-0.1 --mode 1920x1080 --scale-from 3840x2160 --panning 3840x2160+8960+0 --right-of DP-0.2&&
echo "setting global scaling to 2x" &&
@jackdpeterson
jackdpeterson / FacebookAction.php
Created March 6, 2018 21:35
League OAuth2 OpenID (kind-of) with FaceBook Authorization Code flow to internal Authorization Code grant
<?php
namespace Sso\Action;
use League\OAuth2\Client\Provider\Facebook;
use League\OAuth2\Client\Provider\FacebookUser;
use League\OAuth2\Server\Entities\ClientEntityInterface;
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
@jackdpeterson
jackdpeterson / Expr.php
Created March 2, 2018 20:46
When you are using the where In SQL-like search and provide an empty array for the in side of things ... DQL will barf and die with a syntax error. The fix is to check the count of items in the parameter being passed in and create a single entry with a non-possible value to filter down. /** * Creates an IN() expression with the given arguments. …
/**
* Creates an IN() expression with the given arguments.
*
* @param string $x Field in string format to be restricted by IN() function.
* @param mixed $y Argument to be used in IN() function.
*
* @return Expr\Func
*/
public function in($x, $y)
{
@jackdpeterson
jackdpeterson / CellularAdapterDisableEnableScript.cmd
Last active January 18, 2018 21:53
Restart Cellular Adapter
### GET WDK for Windows 10: https://developer.microsoft.com/en-us/windows/hardware/windows-driver-kit
## Docs for devcon can be found at https://docs.microsoft.com/en-us/windows-hardware/drivers/devtest/devcon
@jackdpeterson
jackdpeterson / convert_raw_to_jpeg.sh
Last active January 8, 2019 04:35
bash script to recursively convert RAW to JPEG retaining directory structure.
#!/bin/bash
src_dir=$1
src_dir_length=${#src_dir}
dest_dir=$2
file_type="ARW"
### let's use ufraw-batch. This assumes that you've compiled to the latest ... 0.22 as of this one doesn't cause crappy weirdness with red-spots appearing with under-exposure.
# Usage: ./convert_raw_to_jpeg.sh /source/folder /destination/folder
#
###
@jackdpeterson
jackdpeterson / 042-vagrant.binary
Created June 8, 2016 16:30
042-vagrant.binary - switch username to vagrant
#!/bin/bash -eux
# vi: ts=4 noexpandtab
#
# Generate a generic Vagrant Box.
#
# Vagrant images are essentially nothing more than OVA's with extra-metadata.
#
# We can't use the OVA's for Vagrant since Vagrant uses SSH to modify the instance.
# This build step creates a cloud-config ISO so that Cloud-Init will configure
# the initial user, creates meta-data that tells Vagrant how to interact with
@jackdpeterson
jackdpeterson / test-oauth.html
Created April 22, 2016 17:33
Apigility login using jQuery
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Oauth test</title>
<script src="../js/jquery.js"></script>
<!-- Latest compiled and minified CSS -->
@jackdpeterson
jackdpeterson / phpunit.xml
Created April 15, 2016 17:20
phpunit.xml sample - with code coverage
<phpunit bootstrap="./bootstrap.php" colors="true">
<testsuites>
<testsuite name="MyCompany Test Suite">
<directory>./MyCompany/Service</directory>
</testsuite>
</testsuites>
<logging>
<log type="coverage-html" target="./log/codeCoverage" charset="UTF-8"
yui="true" highlight="true" lowUpperBound="50" highLowerBound="80"
showUncoveredFiles="false" />
@jackdpeterson
jackdpeterson / bootstrap.php
Last active April 15, 2016 17:48
ZF2 PHPUnit bootstrap sample
<?php
namespace MyCompany;
use Zend\Loader\AutoloaderFactory;
use Zend\Mvc\Service\ServiceManagerConfig;
use Zend\ServiceManager\ServiceManager;
error_reporting(E_ALL | E_STRICT);
chdir(__DIR__);
if (! defined('APPLICATION_ENV')) {