Skip to content

Instantly share code, notes, and snippets.

View balintsera's full-sized avatar

Bálint Séra balintsera

  • LastPass
  • Szeged, Hungary
View GitHub Profile
<?php
public function setUpServices()
{
$this->services = [
'twig.loader' =>[
'class' => '\Twig_Loader_Filesystem',
'arguments' => [__DIR__.'/views']
],
'twig.templating' => [
'class' => '\Twig_Environment',
@balintsera
balintsera / Controller.php
Created November 11, 2015 17:21
Use a service via the container
<?php
$templating = $container->get('twig.templating');
$page = $templating->render('index.twig.html', ['hell' => 'Yeah!']);
@balintsera
balintsera / composer.json
Created November 11, 2015 17:29
A starter Composer package description file example
{
"name": "evista/localpackage",
"description": "A local package for testing",
"keywords": [
"test"
],
"homepage": "https://github.com/serabalint/formista",
"license": "MIT",
"authors": [
{
@balintsera
balintsera / composer.json
Created November 11, 2015 17:33
Define any git repository in a composer.js
"repositories": [
{
"type": "vcs",
"url": "ssh://username@server:2222/home/git/localpackage.git"
}
],
@balintsera
balintsera / deploy.php
Last active June 10, 2016 05:35
A dead simple php deploy script for git
<?php
header("Content-Type: text/plain", true, 200);
echo "Deploying...\n";
$projectRoot = __DIR__;
chdir($projectRoot);
// A user must be set up who can write the docroot
package main
import mgo "gopkg.in/mgo.v2"
// Persist is a persisting dependency
type Persist interface {
Insert() (err error)
Update() (err error)
Remove() (err error)
}
@balintsera
balintsera / conditionals-loops.html
Last active November 3, 2016 12:33
Alternative and normal conditional syntax in WordPress
<?php
// inside a PHP tag
if (true) {
print "true";
}
?>
<!-- mixed with markup: alternative syntax -->
<?php if (true): ?>
<p>true</p>
@balintsera
balintsera / cart.js
Last active November 5, 2016 08:46
Self Executing Function
// Self executing function base form
const CartOps = (function(injectedDependency) {
// public (see api)
const config = {
selectors: {
addToCartForm: '.add-to-cart-form',
},
};
// private (missing from api)
@balintsera
balintsera / Dockerfile
Last active February 20, 2017 06:46
PHP (any version) for local development
# Replace image tag (after the semicolon) with whatever version you need
FROM php:5.6-cli
EXPOSE 8080
# Legacy and oldschool apps like Wordpress needs this extension
# RUN docker-php-ext-install mysqli
WORKDIR /usr/src/myapp
# 0.0.0.0 is important: this way the server will response with any request from the outside
@balintsera
balintsera / interpolation.js
Last active August 12, 2017 06:23
Functional interpolation
const cols = [{ ts: 1 }, { ts: 5 }, { ts: 6 }]
const smallest = 1
const interpolatedCols = cols.reduce((accumulated, current) => {
const prev = accumulated[accumulated.length - 1]
for (let i = prev.ts + smallest; i <= current.ts; i += smallest) {
const element = { ts: i }
accumulated.push(element)
}
return accumulated
}, [cols[0]])