Skip to content

Instantly share code, notes, and snippets.

View shawnsandy's full-sized avatar

Shawn Sandy shawnsandy

View GitHub Profile
@shawnsandy
shawnsandy / form-data-field.php
Created February 7, 2017 03:06
Laravel form data field
<p>
<input type="text" name="notes_title" class="col-fluid {{ $errors->first('notes_title', 'error') }}"
placeholder="* Whats the title of this note?"
value="{{ old('notes_title', (isset($note->notes_title) ? $note->notes_title : '')) }}">
</p>
@shawnsandy
shawnsandy / set-flash.php
Created February 5, 2017 01:28
Set flash data
<?php
if($saved = $this->save($request, $gistId))
$request->session()->flash('success', 'Your gist has been saved');
@shawnsandy
shawnsandy / data-attribute.js
Last active February 8, 2017 23:47
Get a data-attribute value in vanilla javascript
// get the element
var config = document.getElementById('git-edit');
// get the data-theme='somevalue'
var theme = config.dataset.theme;
@shawnsandy
shawnsandy / save-cache.php
Created February 4, 2017 14:07
Updates controller to display collections
<?php
try {
if (is_null($gistId)):
$saved = $this->gist->create($request->all());
else :
$saved = $this->gist->update($gistId, $request->all());
$this->gist->cacheItem($saved, $gistId);
endif;
$this->gist->forgetCollection();
@shawnsandy
shawnsandy / errors.blade.php
Created February 4, 2017 13:39
Blade - displays false messages (error. success, warning, info)
@if(Session::has('error'))
<p class="alert alert-error">{{ Session::get('error') }}</p>
@endif
@if(Session::has('success'))
<p class="alert alert-success">{{ Session::get('success') }}</p>
@endif
@if(Session::has('warning'))
<p class="alert alert-warning">{{ Session::get('warning') }}</p>
@shawnsandy
shawnsandy / detect-filename.php
Last active February 11, 2017 01:38
Testing filename detection
<?php
/**
* @param Request $request
* @param null $gistId
* @return bool
*/
function save(Request $request, $gistId = NULL)
{
$this->validate($request, [
@shawnsandy
shawnsandy / ace-test.js
Last active February 9, 2017 00:57
test ace
if(editor.getValue()){
content.value = editor.getValue();
// alert(editor.getValue());
console.log(content.value);
document.getElementById('gist-content').submit();
}
@shawnsandy
shawnsandy / codemirror.blade.php
Created February 3, 2017 14:39
Code Mirror example
@push('styles')
<link rel="stylesheet" href="https://unpkg.com/codemirror@5.23.0/lib/codemirror.css">
@endpush
@push('scripts')
<script src="https://unpkg.com/codemirror@5.23.0/lib/codemirror.js"></script>
@endpush
@push('inline_scripts')
<script>
var editor = document.getElementById('content');
var edit = CodeMirror.fromTextArea(editor, {
@shawnsandy
shawnsandy / cache-data.php
Last active February 3, 2017 20:02
Cache Results
<?php
$key = $this->cacheId . '-' . $gistId;
if (Cache::has($key)):
$results = Cache::get($key);
else :
$results = $this->gist->get($gistId);
Cache::add($key, $results, 600);
endif;
@shawnsandy
shawnsandy / extract-id-from-gist.php
Created February 3, 2017 04:03
Grab a gist id from a url
<? php
/**
* @param string $url
* @return string
*/
private function extractIdFromUrl($url)
{
$url = rtrim($url, '/');
return last(explode('/', $url));
}