Skip to content

Instantly share code, notes, and snippets.

View aaroncadrian's full-sized avatar

Aaron Adrian aaroncadrian

  • Orange County, CA
View GitHub Profile

Cool Code Names

Cool Names List

  • 007
  • Advantage
  • Alert
  • Backhander
  • Badass
  • Blade
  • Blaze
@aaroncadrian
aaroncadrian / top-sort.ts
Last active May 18, 2020 16:58
Topological Sort implemented in TypeScript
import _ from 'lodash';
export function topSort(definitions: _.Dictionary<string[]>) {
const visited: _.Dictionary<boolean> = {};
const sorted: string[] = [];
const sortVertex = (vertex: string) => {
visited[vertex] = true;
for (const childVertex of _.get(definitions, vertex, <string[]>[])) {
@aaroncadrian
aaroncadrian / tailwind_md_all_colours.js
Created April 4, 2018 21:12 — forked from davidpiesse/tailwind_md_all_colours.js
A colour set for Tailwind CSS that include all Material Design Colours, shades, accents and contrast colours
// https://davidpiesse.github.io/tailwind-md-colours/
//
//Notes
//
//All colours are generated from Material Design Docs
//Colours have a base, a set of shades (50-900) accent colours
//In addition a companion set of contrast colours are included for colouring text / icons
// Example usage
// class="w-full bg-red-600 text-red-600-constrast"
const ee = new EventEmitter();
ee.on('change', (note) => {
console.log('Change has been triggered.');
if(note) {
console.log(note);
}
});
ee.on('change', () => {
@aaroncadrian
aaroncadrian / EventEmitter.js
Created March 21, 2018 20:23
Simple JavaScript event emitter class
class EventEmitter {
constructor() {
this.events = {};
}
on(eventName, callback) {
if(!this.events[eventName]) {
this.events[eventName] = [];
}
this.events[eventName].push(callback);
@aaroncadrian
aaroncadrian / macro.md
Created March 11, 2018 09:21 — forked from brunogaspar/macro.md
Recursive Laravel Collection Macros

What?

If a nested array is passed into a Laravel Collection, by default these will be threaded as normal arrays.

However, that's not always the ideal case and it would be nice if we could have nested collections in a cleaner way.

This is where this macro comes in handy.

Setup

@aaroncadrian
aaroncadrian / phpunit-php-env.xml
Created March 8, 2018 20:37
phpunit env settings
<phpunit>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
</php>
</phpunit>
@aaroncadrian
aaroncadrian / TestCaseDisableExceptionHandling.php
Last active March 7, 2018 21:41
Method to disableExceptionHandling in tests so that you can fully inspect the error with phpunit.
protected function disableExceptionHandling()
{
$this->app->instance(\Illuminate\Contracts\Debug\ExceptionHandler::class, new class extends \App\Exceptions\Handler {
public function __construct() {}
public function report(\Exception $e) {}
public function render($request, \Exception $e)
{
throw $e;
}
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
</head>
<body>