Skip to content

Instantly share code, notes, and snippets.

Stig Lindqvist stojg

Block or report user

Report or block stojg

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
@stojg
stojg / Daemon.php
Last active Aug 29, 2015
A silverstripe type daemon example
View Daemon.php
<?php
/**
* This is an example of daemon that runs for a set period of time and the quits. It only allows one task at time
* by using a PID file
*
* The scripts have a few timers that might need explaining
*
* First there are the $this->anotherInstanceRunning($this->timeout) that checks if a process haven't updated the
* pidfile in $this->timeout seconds, then we declare it as dead and start the task, otherwise it quits.
View happy.php
<?php
interface Text {
public function __toString();
}
class HappyBirthday implements Text {
private $restOfLine = '';
View mysite_code_MemberAutocompleteField.php
<?php
class MemberAutocompleteField extends TextField {
private static $allowed_actions = array('suggest');
public $maxSuggestionsNum = 50;
public function Field($properties = array()) {
Requirements::javascript("mysite/javascript/MemberAutocompleteField.js");
View bad.php
<?php
class Model {
public function saveSomething(Member $member, $data) {
if($member &&
$member instanceof Member &&
$member->exists() &&
Permissions::check($member, 'CMS_MAIN')) {
// dataobject banana
@stojg
stojg / CreateSomething.php
Created Mar 23, 2014
Example Create a bunch of dataobjects in a SilverStripe task
View CreateSomething.php
<?php
/**
* CreateSomething
*
* Create a bunch of dataobjects, in this case 10 Members.
*
*/
class CreateSomething extends BuildTask {
@stojg
stojg / myconfig.yaml
Last active Aug 29, 2015
Obfuscated DI
View myconfig.yaml
## _config/myconfig.yml
name: OrderController
---
OrderController:
dependencies:
mailerService: %$MailerService
Injector:
MailerService:
factory: MailerFactory
MailerFactory:
View session_timeout.php
<?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;
View apache_mem.sh
#!/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)}'
View bgd-php.template
{
"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]*",
View gist:2ee6602111a6c05920f1
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Parameters" : {
"InstanceType" : {
"Description" : "WebServer EC2 instance type",
"Type" : "String",
"Default" : "m1.small"
}
"KeyName" : {
You can’t perform that action at this time.