Skip to content

Instantly share code, notes, and snippets.

View lennartvdd's full-sized avatar

Lennart van den Dool lennartvdd

  • Circular IT Group, DigitalDeploy
  • Utrecht
View GitHub Profile
@lennartvdd
lennartvdd / roundValue.php
Created October 9, 2013 12:05
Round values to nearest multiple's of {n} and/or to an arbitrary precision (number of decimals)
<?php
/**
* Created by: Lennart van den Dool <lennartvdd at gmail.com>
*/
Class SomeModel
{
/**
* @var integer The number of decimals to round to
*
@lennartvdd
lennartvdd / configure.php
Last active August 29, 2015 13:55
Yii bootstrapper for server specific configurations (Yii 1.1.x)
<?php
//determine application environment
if(!defined('YII_ENV')) {
if(($env = getenv('YII_ENV'))===false) {
$env='production';//by default
}
define('YII_ENV', $env);
unset($env);
}
@lennartvdd
lennartvdd / listener.php
Last active August 29, 2015 13:58
Catch and write Raw POST data to file
<?php
$data = file_get_contents("php://input");
if(!$data)
die("Missing data");
file_put_contents("postdata_".date("Ymd_His")."_".uniqid().".txt", $data);
@lennartvdd
lennartvdd / webrequest.ps1
Created April 15, 2014 09:18
Powershell Web Request
#param(
# [string]$ProductId,
#)
# ---- Basic Settings
$url = ""
$username = ""
$password = ""
$timeout = 60 * 1000 # 60 seconds
# ---- ./ Basic Settings
@lennartvdd
lennartvdd / post-receive-yii2.sh
Last active February 27, 2021 19:35
GIT Hook: post-receive - Automatically deploy a Yii2 project using GIT
#!/bin/bash
# == Settings ==
GIT_DIR=/var/repo/project.git
WORK_TREE=/var/www/domain.com
BRANCH=master
YII_ENVIRONMENT=Production
# == Script ==
@lennartvdd
lennartvdd / SingleResponsibility.php
Created October 15, 2014 09:01
An example of implementation of single responsibility within PHP
<?php
Class Foo
{
/**
* not a method with a single responsibility
*/
public function __construct()
{
@lennartvdd
lennartvdd / mc-subscribe.php
Created October 21, 2014 10:15
Mailchimp Subscribe
<?php
/**
* Copyright 2014 by LDiT
* Created by: Lennart van den Dool
* Date: 2014-10-21
*
* Free software, licensed under the BSD License
*
* IMPORTANT:
* this script is not XSS safe. If you need this you will have to implement a CSRF token.
@lennartvdd
lennartvdd / schema.org.html
Created November 17, 2014 14:49
implement schema.org aggregate rating
<span itemprop="review" itemscope itemtype="http://data-vocabulary.org/Review-aggregate">
<span itemprop="rating" style="display:none;">4</span>
<span itemprop="count" style="display:none;">1</span>
</span>
<!-- SHOULD BECOME -->
<span itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
<span itemprop="ratingValue" style="display:none;">4</span>
<span itemprop="reviewCount" style="display:none;">1</span>
@lennartvdd
lennartvdd / rsync-backup.sh
Last active August 29, 2015 14:13
rsync backup over ssh
#!/bin/sh
# This script does backups to a remote server over ssh. the account running this script
# must have ssh access to the remote server using passwordless key authentication.
# perform:
# > ssh-keygen -q
# > ssh-copy-id [username]@[hostname]
# test with: `ssh [username]@[hostname]` & add script to cron
# > crontab -e
# #backup: every day @ 03:30 & log output.
@lennartvdd
lennartvdd / codeship-test-yii1.sh
Last active August 29, 2015 14:17
CodeShip - Yii 1.x test setup script
# Set php version through phpenv. 5.3, 5.4 and 5.5 available
phpenv local 5.4
# == configure composer
composer config -g github-oauth.github.com $GITHUB_ACCESS_TOKEN # configure env var in project settings!
# == install composer global dependencies
composer global require "phpunit/phpunit=4.3.*"
composer global require "phpunit/phpunit-selenium"
composer global require "phpunit/php-invoker"