Skip to content

Instantly share code, notes, and snippets.

View reinink's full-sized avatar

Jonathan Reinink reinink

View GitHub Profile
@reinink
reinink / query.sql
Last active November 14, 2023 11:08
Text search across multiple tables using MySQL
select
first_name,
last_name
from
users
left join
companies on companies.id = users.company_id
where (
companies.name like 'TERM%' or
first_name like 'TERM%' or
SELECT name
FROM devices
WHERE name IN (
'Apple iPhone 11',
'Apple iPhone 3G',
'Apple iPhone XR'
)
ORDER By name+0<>0 DESC, name+0, name;
<?php
function trim_leading_whitespace($code)
{
$lines = collect(explode("\n", $code));
$min = collect(explode("\n", $code))->filter(function ($line) {
return trim($line);
})->min(function ($line) {
return strlen($line) - strlen(ltrim($line));
<!DOCTYPE html>
<html>
<head>
<title>Nulls Last</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="antialiased leading-none">
<div class="flex w-full p-24 bg-gray-300">
@reinink
reinink / DateInput.vue
Created August 27, 2019 11:51
Pikaday Vue Component
<template>
<div>
<label v-if="label" class="form-label" :for="`date-input-${_uid}`">{{ label }}:</label>
<input v-bind="$attrs" class="form-input" :id="`date-input-${_uid}`" :class="{ error: error }" type="text" ref="input" :value="value" @change="change" @keyup="change">
<div v-if="error" class="form-error">{{ error }}</div>
</div>
</template>
<script>
import pikaday from 'pikaday'
<?php
use Illuminate\Database\Query\Builder;
Builder::macro('orderByNulls', function ($column, $direction = 'asc', $nulls = 'last', $bindings = []) {
$column = $this->getGrammar()->wrap($column);
$direction = strtolower($direction) === 'asc' ? 'asc' : 'desc';
$nulls = strtolower($nulls) === 'first' ? 'NULLS FIRST' : 'NULLS LAST';
return $this->orderByRaw("$column $direction $nulls", $bindings);
});

Laravel Developer - Interview Exercise

  • Setup a fresh Laravel 5.8 application.
  • Use Tailwind CSS as the CSS framework.
    • CDN version is fine.
    • Bonus points if installed via NPM.
  • Create a new contact page at /contact.
  • Create a contact form on the page.
  • The form should be built as a Vue component.
  • The form should submit via ajax.
@reinink
reinink / query.php
Created May 20, 2019 12:28
Getting table totals using Laravel Eloquent
<?php
$totals = DB::table('subscribers')
->addSelect(DB::raw('count(*) as all'))
->addSelect(DB::raw("sum(case when status = 'confirmed' then 1 else 0 end) as confirmed"))
->addSelect(DB::raw("sum(case when status = 'unconfirmed' then 1 else 0 end) as unconfirmed"))
->addSelect(DB::raw("sum(case when status = 'cancelled' then 1 else 0 end) as cancelled"))
->addSelect(DB::raw("sum(case when status = 'bounced' then 1 else 0 end) as bounced"))
->addSelect(DB::raw("sum(case when status = 'inactive' then 1 else 0 end) as inactive"))
->get();
<?php
use PHPUnit\Framework\Assert;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Foundation\Testing\TestResponse;
TestResponse::macro('data', function ($key) {
return $this->original->getData()[$key];
});