Skip to content

Instantly share code, notes, and snippets.

View stojg's full-sized avatar

Stig Lindqvist stojg

View GitHub Profile
@stojg
stojg / graylog2-web-interface
Last active August 29, 2015 14:05
graylog2-web-interface init
#!/bin/bash
### BEGIN INIT INFO
# Provides: graylog2-web
# Required-Start: $graylog2
# Required-Stop: $graylog2
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts graylog2-web
# Description: Starts graylog2-web using start-stop-daemon
### END INIT INFO
@stojg
stojg / graylog2
Last active August 29, 2015 14:05
graylog2 init file
#!/bin/bash
### BEGIN INIT INFO
# Provides: graylog2
# Required-Start: elasticsearch
# Required-Stop: elasticsearch
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts GrayLog2
# Description: Starts GrayLog2 using start-stop-daemon
### END INIT INFO
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Parameters" : {
"InstanceType" : {
"Description" : "WebServer EC2 instance type",
"Type" : "String",
"Default" : "m1.small"
}
"KeyName" : {
@stojg
stojg / Cache_Stamped_example.php
Created July 20, 2014 11:21
Cache Stampede example
<?php
/**
* Cache stampede protection examples
*/
class cache
{
/**
* @var array
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "PHP Blue-Green Deployment environment template",
"Parameters" : {
"KeyName" : {
"Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances",
"Type" : "String",
"MinLength" : "1",
"MaxLength" : "64",
"AllowedPattern" : "[-_ a-zA-Z0-9]*",
#!/bin/bash
ps -ylC apache2 | awk '{x += $8;y += 1} END {print "Apache Memory Usage (MB): "x/1024; print "Average Proccess Size (MB): "x/((y-1)*1024)}'
@stojg
stojg / session_timeout.php
Created May 27, 2014 22:05
session timeout
<?php
function start_session($timeout = 1800)
{
session_cache_limiter(false);
session_start();
ini_set("session.gc_maxlifetime", $timeout);
if (isset($_SESSION['lastSeen'])) {
$heartbeatAgo = time() - $_SESSION['lastSeen'];
$timeLeft = $timeout - $heartbeatAgo;
@stojg
stojg / myconfig.yaml
Last active August 29, 2015 14:01
Obfuscated DI
## _config/myconfig.yml
name: OrderController
---
OrderController:
dependencies:
mailerService: %$MailerService
Injector:
MailerService:
factory: MailerFactory
MailerFactory:
@stojg
stojg / CreateSomething.php
Created March 23, 2014 20:11
Example Create a bunch of dataobjects in a SilverStripe task
<?php
/**
* CreateSomething
*
* Create a bunch of dataobjects, in this case 10 Members.
*
*/
class CreateSomething extends BuildTask {
@stojg
stojg / bad.php
Created March 21, 2014 10:25
petpeve
<?php
class Model {
public function saveSomething(Member $member, $data) {
if($member &&
$member instanceof Member &&
$member->exists() &&
Permissions::check($member, 'CMS_MAIN')) {
// dataobject banana