Skip to content

Instantly share code, notes, and snippets.

View tormjens's full-sized avatar

Tor Morten Jensen tormjens

View GitHub Profile
@tormjens
tormjens / tagcommit
Created August 22, 2019 08:46
Git: Commit, tag and push
#!/bin/bash
#get highest tag number
VERSION=`git describe --abbrev=0 --tags`
#replace . with space so can split into an array
VERSION_BITS=(${VERSION//./ })
#get number parts and increase last one by 1
VNUM1=${VERSION_BITS[0]}
@tormjens
tormjens / README.md
Created February 22, 2019 09:25
Laravel Envoyer – conditional webpack/npm run

Laravel Envoyer - Diffed conditional webpack run/npm install

At work we use Envoyer to build our assets as part of our deployment. This has removed a lot of the headaches related to merge conflicts.

However, due to this, deployment takes a long time. Even when you just deploy a update to a controller or some other things.

We use these deployment hooks to run npm install and npm run production only if there's been changes to the source files.

The hooks should work as long as your assets are in resources/assets (which was the default up to Laravel 5.7).

@tormjens
tormjens / aircrafts.html
Last active April 6, 2017 08:43
Aircraft Types in JSON
<html>
<head>
<title>Aircrafts</title>
</head>
<body>
<table id="myTable" class="tablesorter">
<thead>
<tr>
@tormjens
tormjens / markdown.php
Created March 9, 2017 12:55
Function for rendering markdown templates i Laravel 5.4
<?php
if(!function_exists('markdown')) {
/**
* Renders a markdown template (with Blade)
*
* @param string $view
* @param array $data
* @return string
*/
function markdown($view, $data = [])
@tormjens
tormjens / load-map.js
Last active December 9, 2016 09:43
Simple Google Maps Async Loader Using Deferred Object (ES6/jQuery)
export default function(ApiKey, libraries) {
var promise = jQuery.Deferred();
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'http://maps.google.com/maps/api/js?key='+ApiKey;
if(libraries)
script.src += '&libraries='+ libraries
document.body.appendChild(script);
jQuery('body').addClass('google-maps-ready');
@tormjens
tormjens / acf.php
Created November 14, 2016 10:08
Add Post Type Templates (WordPress 4.7) To ACF Add Field Group
<?php
add_filter('acf/location/rule_values/page_template', function($val) {
$post_types = get_post_types(array('public' => true), 'objects');
$new_values = array();
foreach($post_types as $post_type) {
$values = array();
$items = get_page_templates( null, $post_type->name );
foreach($items as $name => $item) {
$values[$item] = $name;
@tormjens
tormjens / README.md
Last active August 15, 2016 14:13
Mixin for multiple Foundation mixins & modifiers

Breakpoint Mixin

Mixin using Foundation 6's great breakpoint mixin, which uses the breakpoint maps.

Usage

Multiple breakpoints

The following will compile down to medium, and also the global portrait.

@tormjens
tormjens / README.md
Last active July 29, 2016 22:59
Vagrant - lighttpd + PHP5.5 + MySQL

Vagrant - lighttpd + PHP5.5 + MySQL

Host: 33.33.33.10

WWW-root in the www/ folder created by Vagrant

MySQL

Host: localhost / 33.33.33.10 User: root

@tormjens
tormjens / README.md
Last active June 24, 2016 10:54
WP Plugin Autoload

Autoloading for plugins

Say your plugin classes are following this naming convention My_Plugin_Thing and you name your files by the last "thing" e.g. thing.php inside the lib folder.

This snippet autoloads all classes within a the namespace. Handy!

Also, documentation poor. I'm tired!

@tormjens
tormjens / square-image.php
Created June 14, 2016 12:32
Force images to be square.
<?php
/**
* Parameters
* image = URL to original image
* size = The size of the square (e.g. 300)
**/
header("Content-Type: image/png");