Skip to content

Instantly share code, notes, and snippets.

View adamwathan's full-sized avatar

Adam Wathan adamwathan

  • Ontario, Canada
View GitHub Profile
@adamwathan
adamwathan / maxBy.php
Created June 23, 2016 18:44
maxBy/minBy macros
<?php
Collection::macro('maxBy', function ($callback) {
$callback = $this->valueRetriever($callback);
return $this->reduce(function ($result, $item) use ($callback) {
if ($result === null) {
return $item;
}
return $callback($item) > $callback($result) ? $item : $result;
@adamwathan
adamwathan / Marge.php
Last active September 19, 2023 13:11 — forked from davidhemphill/Marge.php
<?php
namespace App\Merge;
class Marge
{
protected $data = [];
public function setData($data)
{
@adamwathan
adamwathan / belongs-to-many.sublime-snippet
Last active October 19, 2020 16:59
Eloquent Relationship snippets for Sublime Text
<snippet>
<content><![CDATA[
public function ${1:relationship}()
{
return \$this->belongsToMany(${1/^(.+)$/(?1\u$1:)/g}::class, {$2:table});
}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>belt</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
@adamwathan
adamwathan / 1.md
Created August 20, 2015 16:28
Move vertically quickly in Sublime Test

Option + left/right is awesome for jumping around quickly horizontally, but if you're like me, you've probably tried to use that same muscle memory to jump vertically by using option + up/down.

Here's a few macros you can use to accomplish that, as well as creating selections while jumping vertically as well.

Add these shortcuts and you'll be in bizniz:

    //...
    { "keys": ["alt+up"], "command": "run_macro_file", "args": {"file": "Packages/User/move_3_lines_up.sublime-macro"} },
 { "keys": ["alt+down"], "command": "run_macro_file", "args": {"file": "Packages/User/move_3_lines_down.sublime-macro"} },
@adamwathan
adamwathan / import-reference.md
Last active December 5, 2016 06:58
Importing class mixins by reference

This is the workflow I really love with Less that's missing in Sass. Killer way to use a library like Bootstrap without coupling any of your markup to Bootstrap itself.

Import a bunch of vendor styles by reference only, mix in the classes you want to keep into your own aliases, no vendor class names end up in your compiled CSS.

Sass doesn't support reference import or the ability to mixin a class, only a mixin.

// Vendor less
.btn {
 // a bunch
@adamwathan
adamwathan / v-cloak.md
Last active February 26, 2023 14:26
Useful CSS utilities for Vue.js cloaking

Handy helpers for controlling visibility of elements until Vue has compiled.

Use like:

<div v-cloak>
  <h1>
    <span class="v-cloak--inline">Loading...</span> <!-- Only displayed before compiling -->
    <span class="v-cloak--hidden">{{ post.title }}</span> <!-- Hidden until compiling is finished -->
 
@adamwathan
adamwathan / gistlog.yml
Last active September 27, 2015 02:36
A Sample Gistlog
published: true
@adamwathan
adamwathan / magic-decorator.markdown
Created January 15, 2015 13:23
Magic Decorator Woes

Some arbitrary interface:

interface Foo {
    public function look();
    public function at();
    public function all();
    public function these();
    public function methods();
}
@adamwathan
adamwathan / struct.php
Last active September 9, 2022 11:12
Structs in PHP
<?php
// Wow this whole thing is horrible
class Struct
{
public function __construct($properties)
{
foreach ($properties as $key => $value) {
if (property_exists($this, $key)) {
$this->{$key} = $value;
@adamwathan
adamwathan / scublish.sh
Created November 4, 2014 14:57
Sculpin GitHub publish script
function scublish() {
sculpin generate --env=prod
cd output_prod
git add --all
git commit -am "$1"
git push origin master
cd ..
}