Skip to content

Instantly share code, notes, and snippets.

View janit's full-sized avatar

Jani Tarvainen janit

View GitHub Profile
@janit
janit / gist:32a36c5a1dcbbf6bca5d
Created June 22, 2015 20:26
Example H2O HTTP server configuration for PHP rewrite apps (such as Bolt, WordPress)
# to find out the configuration commands, run: h2o --help
user: www-data
hosts:
"example.com":
listen:
host: xx.xx.xx.xx
port: 443
@janit
janit / init.txt
Last active June 15, 2018 15:42
Using Zyxel SBG3300 with CDC ethernet on Huawei E5377 (eth3G)
# 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
Here used to be a rough prototype of an
implementation, which is now deprecated.
in favour of this:
https://www.symfony.fi/entry/sharing-state-in-a-symfony-hybrid-app-with-twig-react-etc
-----
Using this approach you can bootstrap a
React application on the server side using
PHP/Symfony so that your client application
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();
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 }}
<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>
<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>
<?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);
<?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;
@janit
janit / test.html.twig
Created January 25, 2017 10:20
Sample Twig calls for PhpStorm indenting example
{{ render_esi(
controller(
"Foo:Default:bar",
{
'bar': foo,
}
)
) }}