Skip to content

Instantly share code, notes, and snippets.

View mortenson's full-sized avatar
💧
Did you try to clear cache?

Samuel Mortenson mortenson

💧
Did you try to clear cache?
View GitHub Profile
@mortenson
mortenson / index.html
Created September 8, 2015 20:05
Refresh current path in JS every 5 seconds (try it out by editing the content of body)
<html>
<head>
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script>
$(function() {
if (typeof init === 'undefined') {
init = true;
setInterval(function () {
$.get('', function (data) {
var doc = document.open('text/html', 'replace');
$service = New-WebServiceProxy -Uri http://143.166.84.118/services/assetservice.asmx?WSDL
if($args.count -ne 0){
$serial = $args[0]
}
else{
$system = Get-WmiObject win32_SystemEnclosure
$serial = $system.serialnumber
}
$guid = [guid]::NewGuid()
$info = $service.GetAssetInformation($guid,'check_warranty.ps1',$serial)
@mortenson
mortenson / entity-browser-image-support.patch
Created January 15, 2016 18:17
Is it really that easy?
diff --git a/src/Plugin/Field/FieldWidget/EntityReference.php b/src/Plugin/Field/FieldWidget/EntityReference.php
index 004ab98..935c05f 100644
--- a/src/Plugin/Field/FieldWidget/EntityReference.php
+++ b/src/Plugin/Field/FieldWidget/EntityReference.php
@@ -33,7 +33,8 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
* description = @Translation("Uses entity browser to select entities."),
* multiple_values = TRUE,
* field_types = {
- * "entity_reference"
+ * "entity_reference",
@mortenson
mortenson / photobooth.py
Last active April 17, 2016 18:20
Stupid simple script for taking photobooth-style pictures in Python 2.7+ using OpenCV 3+ and Pillow.
import cv2
import time
import sys
import PIL
from PIL import Image
from PIL import ImageOps
# "0" is the port of your built-in webcam, probably.
camera_port = 0
# Number of frames to ramp-up the camera.
@mortenson
mortenson / Dockerfile
Last active August 7, 2016 17:43
No-interaction Drupal 8 standard install with Docker
# Extend the official Drupal image.
FROM drupal:8.1.7-apache
# Install required binaries.
RUN apt-get update && apt-get install netcat mysql-client -y
# Safely remove the normal modules directory.
RUN rm /var/www/html/modules/README.txt && rmdir /var/www/html/modules
# Install Composer.
@mortenson
mortenson / docker-compose.yml
Created August 7, 2016 17:44
Minimal Docker Compose file for Drupal 8
version: '2'
services:
web:
build: .
ports:
- "8000:80"
volumes:
- ./modules:/var/www/html/modules
- ./files:/var/www/html/sites/default/files
links:
html,
body {
height: 100%; }
@mortenson
mortenson / fixregion.php
Created May 12, 2017 21:40
Have some 8.2 module/distro config for form or view displays? Use this to add a region to all your fields. Buyer beware!
<?php
# Run this with drush scr, silly!
use Drupal\Core\Serialization\Yaml;
foreach (file_scan_directory('.', '/core\.entity_.*display.*\.yml/') as $file) {
$filepath = realpath($file->uri);
$yml = Yaml::decode(file_get_contents($filepath));
if (isset($yml['content'])) {
@mortenson
mortenson / ssr.js
Last active October 8, 2017 15:17
Flexible server side rendering script for Stencil when used in other platforms
// Put this file in a directory where @stencil/core exists in node_modules, then run: +var stencil = require('@stencil/core/server');
// $ echo $HTML | node ssr.js [root] [build-dir] [namespace]
// Full example from my use case:
// $ echo '<sam-text text="Hello, world"></sam-text>' | node ssr.js /var/www/stencil/sams-components/ ../dist sam
// Pipes are used because HTML strings can be really long, and bash has limits on how large argument lists can get (~256k usually).
var stencil = require('@stencil/core/server');
var args = process.argv.slice(2);
if (args.length < 3) {
console.error('Not enough args');
}