Skip to content

Instantly share code, notes, and snippets.

Jani Tarvainen janit

View GitHub Profile
View swiftmailer.yaml
// YAML config for sending emails on eZ Platform Cloud / Platform.sh on eZ Platform v3.0 and higher
swiftmailer:
url: 'smtp://%env(PLATFORM_SMTP_HOST)%'
spool: { type: 'memory' }
View clean-up-ezp-31546-issue.txt
eZ Platform v3.0.0 used ezplatform-kernel 1.0.0 package which had an issue with
storing images in the wrong directory: https://jira.ez.no/browse/EZP-31546
The issue was fixed in ezplatform-kernel 1.0.1 (shipped in eZ Platform v3.0.1),
but misplaced files and corrupt database entries for image binaries remain in
the wrong location. This will make your installation not work consistently.
This is a set of commands that can be used to remedy the issue and bring your
file structure and database up-to-date if you have been running version 3.0.0
@janit
janit / preparerichtext.php
Last active Jun 20, 2019
Convert HTML to eZ Platform Rich Text DocBook XML format
View preparerichtext.php
<?php
// This is the namespace you want to use
use EzSystems\EzPlatformRichText\eZ\FieldType\RichText\Type as RichTextFieldType;
// this would be a method in your class (you'll need to inject RichTextFieldType)
// It has some extra wrangling of input not required, but makes it moarrr robust
private function prepareRichText($inputText){
if($inputText === ''){
@janit
janit / init.txt
Last active Jun 15, 2018
Using Zyxel SBG3300 with CDC ethernet on Huawei E5377 (eth3G)
View init.txt
# You can run the Huawei E5377 LTE modem as an ethernet device on the Zyxel SBG3300 router
# More here: https://kb.zyxel.com/KB/searchArticle!gwsViewDetail.action?articleOid=013274&lang=EN
Short info:
$ telnet 192.168.1.1
$ sh
$ usb_modeswitch -v 12d1 -p 1f02 -V 4817 -P 5340 -M 55534243123456780000000000000a11062000000000000100000000000000
$ lsusb
@janit
janit / sw.js
Last active Oct 31, 2019
Service Worker example for controlling what is cached - See https://malloc.fi/fix-duplicate-redirects-service-worker-caching
View sw.js
self.addEventListener('install', function (event) {
event.waitUntil(preLoad());
});
var preLoad = function () {
// console.log('[PWA Builder] Install Event processing');
return caches.open('pwabuilder-offline').then(function (cache) {
// console.log('[PWA Builder] Cached index and offline page during Install');
return cache.addAll(['/offline.html', '/']);
});
@janit
janit / db_backup.sh
Created Jun 26, 2017
Rotating PostgreSQL Backup Script
View db_backup.sh
#!/bin/bash
# for use with cron, eg:
# 0 3 * * * postgres /var/db/db_backup.sh foo_db
if [[ -z "$1" ]]; then
echo "Usage: $0 <db_name> [pg_dump args]"
exit 1
fi
View DefaultController.php
public function apiApartmentsAction(Request $request)
{
$appState = new AppState();
$em = $this->get('doctrine.orm.default_entity_manager');
$apartments = $em->getRepository('AppBundle:Apartment')->getRandom(10);
$appState->setApartments($apartments);
$response = new JsonResponse();
View app.js
var ApartmentListing = Vue.extend({
template: `
<div>
<h2>Hello from Vue</h2>
<table>
<tr v-for="apartment in apartments">
<td>
{{ apartment.streetaddress }}<br />
{{ apartment.city }}<br />
{{ apartment.zipcode }}
View base.html.twig
<script type="text/javascript">
var initialAppState = {{ appstate_serialized|raw }};
</script>
<script src="{{ asset('bundles/app/js/vue/vue.js') }}"></script>
<script src="{{ asset('bundles/app/js/vue/app.js') }}"></script>
View index.html.twig
<h2>Hello from Twig</h2>
<table>
{% for apartment in appstate.apartments %}
<tr>
<td>
{{ apartment.streetaddress }}<br />
{{ apartment.city }}<br />
{{ apartment.zipcode }}
</td>
<td>{{ apartment.country }}</td>
You can’t perform that action at this time.