Skip to content

Instantly share code, notes, and snippets.

Jani Tarvainen janit

Block or report user

Report or block janit

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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 Jul 10, 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>
View DefaultController.php
<?php
public function indexAction(Request $request )
{
$appState = new AppState();
$em = $this->get('doctrine.orm.default_entity_manager');
$apartments = $em->getRepository('AppBundle:Apartment')->findByLimit(3);
$appState->setApartments($apartments);
$appState->setFetchMore(true);
View AppState.php
<?php
namespace AppBundle\State;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
class AppState implements \JsonSerializable {
public $fetchMore = false;
You can’t perform that action at this time.