Skip to content

Instantly share code, notes, and snippets.

@fyrebase
fyrebase / .svgo.yml
Created Oct 1, 2016
Convert dimensions to viewBox - SVGO Plugin
View .svgo.yml
plugins:
...
- convertDimensions
...
@fyrebase
fyrebase / gist.php
Last active May 11, 2016
Craft CMS generate asset title before save
View gist.php
<?php
craft()->on('assets.beforeSaveAsset', function(Event $event) {
if ($event->params['isNewAsset']) {
$asset = $event->params['asset'];
$source = $asset->getSource();
if (in_array($source->handle, ['myAssetSource'])) {
$asset->getContent()->title = 'myAssetTitle';
}
@fyrebase
fyrebase / gist.php
Created May 11, 2016
Craft CMS rename asset and title on asset save
View gist.php
<?php
protected function initSaveAssetEventListeners()
{
craft()->on('assets.saveAsset', function(Event $event) {
if ($event->params['isNewAsset']) {
$asset = $event->params['asset'];
$source = $asset->getSource();
if (in_array($source->handle, ['myAssetSource'])) {
View guide.md

Php-FPM

Php fpm is the new way to setup php to run with your webserver. Php-fpm is a fastcgi process manager for php that is totally separate from the webserver. The webserver communicates with fpm through a socket and passes the name of the script to execute. So fpm can run with any web server that is fastcgi compatible.

I recently moved from my old shared hosting to linode. Linode provides linux vps hosting at economic prices. However the servers are totally unmanaged are just raw linux machines that have shell access. So through the shell you have to setup everything including the web server, php and the web files.

So this time I decided to go with the combination of nginx and php-fpm. I had multiple sites to setup on this new webserver. Nginx deals with these through separate server blocks (aka vhost in apache). However there was another thing needed. Php on each site should run with its own user and not the nginx common user named www-data.

Running each site with its own uid/gid is more secure and

@fyrebase
fyrebase / image.styl
Last active Nov 24, 2015
Distortion free full screen image using Stylus
View image.styl
.img-wrapper
position relative
img
position absolute
left 50%
top 50%
transform translate(-50%,-50%)
display inline-block
max-width 100%
@fyrebase
fyrebase / navigation.twig
Last active Apr 18, 2018
Neat way of adding active class to cached navigation in Craft - From http://goo.gl/9LaOuM
View navigation.twig
{% set navigation %}
{% cache globally for 3 years %}
{% set entries = craft.entries.section('navigation') %}
<ul>
{% nav entry in entries %}
<li>
{# Check for entry type / get related entry #}
{% if entry.type == 'linkedChannelEntry' %}
@fyrebase
fyrebase / index.js
Created Nov 5, 2015
Gulp Useref - Log Invalid paths
View index.js
// Add after pattern is defined. Line #113
var fs = require('fs');
fs.stat(pattern, function(err, stat) {
if(err) console.log('[INVALID PATH] ' + err.path);
});