Skip to content

Instantly share code, notes, and snippets.

View rossriley's full-sized avatar

Ross Riley rossriley

View GitHub Profile
library(lme4)
bats <- structure(list(Indvar1 = c(0, 5, 10, 19, 30, 33, 39, 44, 54,
63, 68, 72, 81, 87, 93, 100, 105, 110, 119, 127, 134, 141, 149,
155, 115, 120, 125, 0, 5, 9, 17, 22, 29, 35, 39, 44, 45, 50,
55, 63), IndvarType = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
3L), .Label = c("CONTROL", "LED", "Metal Halide", "SOX"), class = "factor"),
IndvarCat = c(26.9, 25.16, 39, 29.81, 21.83, 20.22, 2.9,
@rossriley
rossriley / CSVImportCommand.php
Created July 25, 2016 10:38
Import Content to Bolt from CSV File
<?php
namespace Mysite\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Bolt\Application;
<?php
// Assuming you have a repeater field named `performances` and within each set there's a field named performancetime which is a datetime.
// The example is in PHP code, if you want to use it in Twig then you'll need to put this code in a method and use a Twig Filter to point
// to the method
$iterator = $record['performances']->getIterator();
$iterator->uasort(function ($first, $second) {
if ($first === $second) {
<?php
// This line needs to be called after initialize but before run
$app['upload'] = $app->extend(
'upload',
function ($handler, $app) {
$handler->setSanitizerCallback(function ($filename) {
return $filename;
});
return $handler;
<?php
namespace Myapp\Response;
use Symfony\Component\HttpFoundation\Response;
class CsvResponse extends Response
{
protected $data;
<?php
// This line needs to be called after initialize but before run
$app['upload'] = $app->extend(
'upload',
function ($handler, $app) {
if ($app['request']->get('contenttypeslug') && $app['request']->get('id')) {
$handler->setPrefix("/".$app['request']->get('contenttypeslug')."/".$app['request']->get('id'));
}
<?php
// A method looks like this assuming that you are passed a $request instance that contains all the needed info
$builder = new ContainerBuilder();
$builder->addDefinitions(__DIR__."/config/services.php");
$container = $builder->build();
$routeInfo = $this->dispatcher->dispatch($request->getMethod(), $request->getPathInfo());
<?php
$dispatcher = FastRoute\simpleDispatcher(function(FastRoute\RouteCollector $r) {
$r->addRoute('GET', '/', 'MyApp\Action\Index');
$r->addRoute('GET', '/example/{parameter}', 'MyApp\Action\Example');
});
<?php
use Bolt\Thumbs\ThumbnailResponder;
class S3ThumbnailResponder extends ThumbnailResponder
{
/**
* Gets raw image data for the thumbnail.
*
$app['cache'] = $app->share(
function (Application $app) {
$memcache = new Memcache();
$memcache->connect('127.0.0.1', 11211);
$cacheDriver = new \Doctrine\Common\Cache\MemcacheCache();
$cacheDriver->setMemcache($memcache);
return $cacheDriver;
}
);