Skip to content

Instantly share code, notes, and snippets.

View mcordingley's full-sized avatar

Michael Cordingley mcordingley

  • Upstart
  • Columbus, Ohio
View GitHub Profile
@mcordingley
mcordingley / BackInThePack.ino
Created October 26, 2019 03:46
Code for my Flora-enabled backpack that has a NeoPixel ring, an SI1145 sensor, and a LSM303 sensor.
#include <Adafruit_NeoPixel.h>
#include <Adafruit_SI1145.h>
Adafruit_NeoPixel pixelCircle = Adafruit_NeoPixel(12, 9, NEO_GRBW + NEO_KHZ800);
Adafruit_SI1145 lightSensor = Adafruit_SI1145();
void setup() {
pixelCircle.begin();
pixelCircle.setBrightness(50);
pixelCircle.show();
<?php
namespace App\Models\Traits;
use Carbon\Carbon;
use Cron\CronExpression;
use InvalidArgumentException;
/**
* @property CronExpression|null $cron_expression
@mcordingley
mcordingley / index.html
Last active December 24, 2017 17:50
Message Commitment
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="./styles.css" />
</head>
<body>
<div class="mx-auto max-width-4">
<h1>Message Commitment</h1>
<?php
/**
* Takes the results of a relation sync and replaces the ids with model instances.
*
* @param array $synced The results of a call to `sync()` on a `BelongsToMany` relation.
* @param string $foreign Namespaced model name. e.g. from Foo::class
* @return array $sync, but with ids replaced with model instances
*/
function fetchSynced(array $synced, string $foreign): array
<?php
/**
* @param string $message
* @param int $length
* @param string $cap What to place at the end of the truncated message to indicate truncation.
* @param string $delimiter
* @param bool $removeLastDelimiter
* @param bool $lengthInBytes
* @param string|null $encoding
* @return string
@mcordingley
mcordingley / median.php
Last active December 26, 2016 16:10
median
<?php
/**
* @param array $items
* @param callable|int|string|null $callback
* @return mixed
*/
public static function median($items, $callback = null)
{
return static::nthOrder($items, (int) ((count($items) - 1) / 2), $callback);
}
@mcordingley
mcordingley / d3-gauge.js
Last active March 27, 2016 21:36
A speedometer-style chart for d3.
function gauge() {
'use strict';
var settings = {
'arc-size': 10,
angle: 90.0, // Degrees
arcGenerator: d3.svg.arc(),
angleScale: d3.scale.linear().range([-45, 45]), // Value to degrees
domain: null, // Raw values to that correspond to each color in range.
margin: {
@mcordingley
mcordingley / Solver.js
Last active August 29, 2015 14:20
Algorithmic Sudoku Solver
(function(root, Sudoku) {
'use strict';
/*
* Depth-first search tree of the Sudoku board. Should be as good as A*,
* since there's no real heuristic to direct the search and give A* an
* advantage.
*/
root.solveBoard = function(board) {
var open = [],
@mcordingley
mcordingley / eased-interval.js
Created April 11, 2014 19:45
setInterval, but with easing from one timer value to another
(function(root) {
'use strict';
// Mapping of returned interval handles to their current timeout handles
var intervals = {},
easedIntervalCounter = 0;
var isNumeric = function(candidate) {
return (!isNaN(parseFloat(candidate)) && isFinite(candidate));
},
@mcordingley
mcordingley / .htaccess
Created January 30, 2014 18:20
Common .htaccess Options
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType image/jpeg A604800
ExpiresByType image/gif A604800
ExpiresByType image/png A604800
ExpiresByType text/css A604800
ExpiresByType application/x-javascript A604800
ExpiresByType application/javascript A604800
ExpiresByType text/javascript A604800
</IfModule>