Skip to content

Instantly share code, notes, and snippets.

View calebporzio's full-sized avatar

Caleb Porzio calebporzio

View GitHub Profile
<script>
export default {
props: ['icon'],
render(h) {
let svgHtml = require(`!html-loader!./../../svg/${this.icon}.svg`)
let wrapper = document.createElement('div')
wrapper.innerHTML = svgHtml
let node = wrapper.firstChild
let attrs = {}
@calebporzio
calebporzio / webpack.mix.js
Created March 2, 2019 15:17
A webpack.mix.js file for writing NPM packages the way you write JS in a Laravel app.
let mix = require('laravel-mix');
mix.js('src/index.js', 'dist/foo.js').sourceMaps();
mix.webpackConfig({
output: {
libraryTarget: 'umd',
}
})
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See https://hyper.is#cfg for all currently supported options.
module.exports = {
config: {
// Choose either "stable" for receiving highly polished,
// or "canary" for less polished but more frequent updates
updateChannel: 'stable',
@calebporzio
calebporzio / time_travel_helper.php
Last active August 18, 2019 00:00
A little Laravel helper function for hijacking Carbon's "now()" inside a callback
<?php
// Helper usage:
// timeTravel(Carbon::parse('one year ago'), function () {...});
function timeTravel($target, $callback) {
Illuminate\Support\Carbon::setTestNow($target);
return tap($callback(), function () {
Illuminate\Support\Carbon::setTestNow();
@calebporzio
calebporzio / InputHidden.vue
Created November 2, 2018 16:39
A Vue component for turning json into hidden input elements
// Usage:
// <input-hidden name="users" :value="[{name: 'Caleb'}, {name: 'Daniel'}]"/>
// (value can be a: string, integer, array, object)
//
// will render:
// <input class="hidden" type="text" name="users[0][name]" value="Caleb">
// <input class="hidden" type="text" name="users[1][name]" value="Daniel">
<script>
<?php
Blade::directive('route', function ($expression) {
return '<?php route(' . $expression . '); ?>';
});
@calebporzio
calebporzio / timer_helpers.php
Last active August 18, 2019 00:07
A simple helper function and macro for timing php scripts and eloquent queries
<?php
// Helper function.
if (! function_exists('timer')) {
function timer($expression)
{
$start = microtime(true);
if ($expression instanceof Closure) {
$expression();
@calebporzio
calebporzio / amount_in_dollars.php
Created June 1, 2017 19:07
A handy accessor and mutator for storing amounts in cents and accessing and setting them in dollars
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class [Insert Name Here] extends Model
{
protected $guarded = [];
@calebporzio
calebporzio / ddValidation.php
Created June 20, 2018 16:30
little Laravel TestCase helper to get better validation output
<?php
// Place this method somewhere in TestCase.php
protected function ddValidation(array $except = [])
{
if ($this->originalExceptionHandler == null) {
$this->originalExceptionHandler = app(ExceptionHandler::class);
}
@calebporzio
calebporzio / karabiner_vim_mode.json
Created March 27, 2020 18:13
A backup of the ideal vim mode karabiner plugin
{
"title": "Caleb's Vim Mode",
"author": "Caleb Porzio(calebporzio.com)",
"rules": [
{
"description": "Vim Mode [D as Trigger Key]",
"manipulators": [
{
"from": {
"key_code": "d",