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
@balintsera
balintsera / docker-compose.yml
Created October 1, 2017 08:28
Use environment variable in an Nginx container using templating
version: "3"
services:
vhostfront:
image: repository/vhostmon/vhostfront:latest
environment:
- APP_CONF=config={"baseUrl":"http://localhost:8081"}
ports:
- "8085:80"
command: ["sh", "-c", "envsubst < /etc/nginx/conf.d/deafault.conf.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"]
@balintsera
balintsera / nginx.conf
Created October 1, 2017 08:23
Send config as cookie with nginx to single page javascript apps
location / {
root /usr/share/nginx/html;
index index.html index.htm;
add_header "Set-Cookie" 'config={"baseUrl":"http://localhost:8081"}';
}
@balintsera
balintsera / higher order function.js
Created September 11, 2017 17:54
higher order function created by balintsera - https://repl.it/Kwbw/1
var snakify = function(text) {
return text.replace(/millenials/ig, "Snake People");
};
console.log(snakify("The Millenials are always up to something."));
var hippify = function(text) {
return text.replace(/baby boomers/ig, "Aging Hippies");
};
console.log(hippify("The Baby Boomers just look the other way."));
@balintsera
balintsera / interpolation_functional.js
Created August 12, 2017 10:55
A more functional interpolation example
// Original elements with gaps
const cols = [
{ ts: 2, name: 'two' },
{ ts: 4, name: 'four' },
{ ts: 11, name: 'thirtyone' },
]
const step = 1
// The first and last element for being much more readable
@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]])
@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 / 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 / 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>
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 / 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