Skip to content

Instantly share code, notes, and snippets.

View hafriedlander's full-sized avatar

Hamish Friedlander hafriedlander

  • RUSH
  • Auckland, New Zealand
View GitHub Profile
@hafriedlander
hafriedlander / extract.sh
Created August 4, 2016 23:14
Reminder on creating a bunch of HQ gifs from a video
#!/bin/bash
palette='/tmp/palette.png'
filters='fps=15,scale=240:320:flags=lanczos'
dur=`echo "$2-$1" | bc`
ffmpeg -ss $1 -t $dur -i Cropped.mp4 -vf "$filters,palettegen" -y $palette
ffmpeg -ss $1 -t $dur -i Cropped.mp4 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse=dither=none" -y '/tmp/gif.gif'
gifsicle '/tmp/gif.gif' --optimize=100 > $3
@hafriedlander
hafriedlander / Foo\Page.php
Last active July 27, 2016 22:30
Example showing proposed dynamic referencing of "Page" class namespace in SilverStripe 4
<?php
namespace Foo;
class Page {
function whoami() {
echo __CLASS__;
}
}
@hafriedlander
hafriedlander / test.php
Created October 8, 2015 03:55
PHP private abstract function in traits test
<?php
trait Foo {
abstract private function qux();
}
class Bar {
use Foo { qux as protected; }
}
<?php
class HackedDataQuery extends DataQuery {
public function __construct($dataQuery) {
$this->dataClass = $dataQuery->dataClass;
$this->query = $dataQuery->query;
}
public function selectField($fieldExpression, $alias = null) {
parent::selectField($fieldExpression, $alias);
@hafriedlander
hafriedlander / gist:49a38ba86a334bef8f30
Created October 22, 2014 20:37
Storing files in dataobject fields example
<?php
class MyObject extends DataObject {
private static $db = array(
'Thumbnail' => 'File'
);
function thumbnailLink() {
return $this->obj('Thumbnail')->Link;
@hafriedlander
hafriedlander / mysite_code_MemberAutocompleteField.php
Created March 7, 2014 03:04
MemberAutocompleteField (example of SilverStripe 3.1 ajax-based autocomplete)
<?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");
@hafriedlander
hafriedlander / config_a.yml
Created August 28, 2012 01:33
Bad and good SilverStripe config fragment before/after rules
---
After:
- cms
- framework
---
SomeClass:
SomeProperty: 1
---
@hafriedlander
hafriedlander / en.yml
Created August 23, 2012 22:06
Overriding the field labels in a SS3 comment form
en:
CommentingController:
EMAILADDRESS: 'Email'
@hafriedlander
hafriedlander / CommentingControllerExtension.php
Created August 23, 2012 22:04
How to remove a field from the comment form
<?php
class CommentingControllerExtension extends Extension {
function alterCommentForm(Form $form) {
$fields = $form->Fields();
$fields->removeByName('URL');
}
}
diff --git a/javascript/CMSMain.EditForm.js b/javascript/CMSMain.EditForm.js
index 35d8e44..58b49eb 100644
--- a/javascript/CMSMain.EditForm.js
+++ b/javascript/CMSMain.EditForm.js
@@ -24,6 +24,8 @@
+
+ Title: null,
+
// Constructor: onmatch
onmatch : function() {