Skip to content

Instantly share code, notes, and snippets.

View kshep92's full-sized avatar

Kevin kshep92

  • Trinidad and Tobago
View GitHub Profile
@kshep92
kshep92 / .bashrc
Created June 12, 2020 20:21
Some handy functions for managing NginX
alias nx='/bin/bash ~/.scripts/nx.sh' # NginX scripts
@ControllerAdvice
public class NotFoundHandler {
@Value("${spa.default-file}")
String defaultFile;
@ExceptionHandler(NoHandlerFoundException.class)
public ResponseEntity<String> renderDefaultPage() {
try {
File indexFile = ResourceUtils.getFile(defaultFile);
FileInputStream inputStream = new FileInputStream(indexFile);
@Configuration
public class MvcConfig implements WebMvcConfigurer {
@Value("${spring.resources.static-locations}")
String resourceLocations;
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/public/**").addResourceLocations(resourceLocations);
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Spring Boot</title>
</head>
<body>
<h1>Served as a static file.</h1>
</body>
</html>
@kshep92
kshep92 / routing.html
Created September 18, 2017 20:24
Routing with Page.js + Polymer
<iron-pages selected="[[selected]]">
<home-page name="home"></home-page>
<contacts-page name="contacts"></contacts-page>
<admin-page name="admin"></admin-page>
</iron-pages>
<script>
// ...Polymer boilerplate
{
properties: {
@kshep92
kshep92 / md5.groovy
Created February 24, 2017 02:52 — forked from ikarius/md5.groovy
How to generate a MD5 hash in Groovy ...
import java.security.MessageDigest
String fileContents = "<html><head></head><body>Hello world!</body></html>"
MessageDigest sha = MessageDigest.getInstance("MD5")
byte[] digest = sha.digest(fileContents.bytes)
print "${digest.encodeHex()}"
@kshep92
kshep92 / behaviours.js
Last active February 8, 2017 23:00
Some validation and form control behaviours for Polymer
// Forms
// <form is="data-form" action="/users" model="[[user]]" busy="{{sending}}" id="login">
// ...
// <input type="submit" value="Log In" disabled$="[[sending]]" />
// </form>
// this.$.login.validate()
// this.$.login.send().then().catch()
var Form = {
extends: 'form',
@kshep92
kshep92 / output.txt
Created December 15, 2016 16:16
Using MySQL GROUP_CONCAT to fetch pesky many-to-many relationships in one go.
| id | name | email | permissions |
|----|-------|----------------|--------------------|
| 1 | kevin | kevin@mail.com | basic,manage_posts |
@kshep92
kshep92 / ghostdown-lite.js
Last active December 15, 2016 04:11
How to create a Ghost-like editor with image placeholders that facilitate file upload. Sweeten to taste. From the THLabs/ghostdown repo.
'use strict';
var textarea = document.querySelector('#ghostdown-editor'),
preview = document.querySelector('#ghostdown-rendered'),
converter = new showdown.Converter(),
editor = CodeMirror.fromTextArea(textarea, {
mode: 'markdown',
tabMode: 'indent',
lineWrapping: true
});
@kshep92
kshep92 / Aureliafile.js
Last active September 29, 2016 03:23
Sample Aurelia bundler configuration
var gulp = require("gulp");
var bundler = require('aurelia-bundler');
var del = require("del");
var aureliaBundle = {
"includes": [
"aurelia-auth",
"aurelia-bootstrapper",
"aurelia-event-aggregator",
"aurelia-fetch-client",