Skip to content

Instantly share code, notes, and snippets.

@sjelfull
sjelfull / gist:4f80e0ac461573ab493e229a25be2934
Created June 5, 2017 13:37
Parallel processing in Craft with parallel
#!/bin/bash
LOCAL_PARALLEL_JOBS=$1
PARALLEL_JOBS=${LOCAL_PARALLEL_JOBS:-4}
# parallel creates a subshell, which will use the default $SHELL
# This makes sure php runs paralell with the correct shell
export SHELL=/bin/bash
index() {
echo Indexing $1
<?php
public function createProduct ($locale = null)
{
if ( !$this->productTypes ) {
$this->productTypes = craft()->commerce_productTypes->getAllProductTypes();
}
if ( !$locale ) {
$locale = craft()->i18n->getPrimarySiteLocaleId();
@sjelfull
sjelfull / _lazyFocusImager.twig
Created April 6, 2017 12:51 — forked from hendrikeng/_lazyFocusImager.twig
Twig/Craft macro for lazy responsive images/bgimages with Imager and Focuspoint
{#
// lazyLoaded Image/bgImages, optimized with Imager and Focuspoint
---------------------------------------------------------------------------
https://nystudio107.com/blog/creating-optimized-images-in-craft-cms
https://github.com/aelvan/Imager-Craft
https://github.com/smcyr/Craft-FocusPoint
for the bgImage intrinsic ratio classname creation check:
https://github.com/inuitcss/inuitcss/blob/develop/objects/_objects.ratio.scss
@sjelfull
sjelfull / Pushover+UptimeRobot.php
Created November 29, 2016 14:54
Use Pushover and a webhook from Uptime Robot to send notifications to your phone
<?php
require __DIR__ . '/vendor/autoload.php';
use Sly\PushOver\Model\Push;
use Sly\PushOver\PushManager;
if (!isset($_GET['key']) || $_GET['key'] !== 'KEY') {
die('No key');
}
$monitorFriendlyName = $_GET['monitorFriendlyName'];
@sjelfull
sjelfull / create-test-order-in-craft-commerce.php
Created October 24, 2016 09:25
Creating test order in Craft Commerce
<?php
public function actionCreateTestOrder ()
{
// Configuration
$customerId = 1;
$productId = 8;
$productQuantity = 5;
$orderStatusId = 1;
$paymentMethodId = 1;
$shippingMethodHandle = 'bring';

Keybase proof

I hereby claim:

  • I am sjelfull on github.
  • I am fredcarlsen (https://keybase.io/fredcarlsen) on keybase.
  • I have a public key ASCXgDizO7fSlSLYrno4ro3h_lPxQJmDv390-gE6TE7qmwo

To claim this, I am signing this object:

@sjelfull
sjelfull / craft-commerce-create-test-order.php
Last active August 1, 2016 11:00
Create a test order in Craft Commerce
<?php
public function actionCreateTestOrder ()
{
// Configuration
// Id of customer for this order
$customerId = 1;
$productId = 8;
$orderStatusId = 1;
$paymentMethodId = 1;
@sjelfull
sjelfull / sm-annotated.html
Created April 25, 2016 15:07 — forked from hdragomir/sm-annotated.html
The deferred font loading logic for Smashing Magazine. http://www.smashingmagazine.com/
<script type="text/javascript">
(function () {
"use strict";
// once cached, the css file is stored on the client forever unless
// the URL below is changed. Any change will invalidate the cache
var css_href = './index_files/web-fonts.css';
// a simple event handler wrapper
function on(el, ev, callback) {
if (el.addEventListener) {
el.addEventListener(ev, callback, false);
@sjelfull
sjelfull / set-project-perms.sh
Created April 20, 2016 20:40 — forked from khalwat/set-project-perms.sh
Properly set permissions for a Craft CMS install, including ensuring that files are all g-x. Set CHOWN_USER, CHOWN_GROUP, and BASE_DIR to whatever is appropriate, add directories that need to be writeable by the web server to DIRS[], then execute: ./set-project-perms.sh PROJECT_NAME
#!/bin/bash
# Execute via: ./set-project-perms.sh PROJECT_NAME
# The paradigm is the entire project dir is owned by $CHOWN_USER with the group set to $CHOWN_GROUP
# $CHOWN_USER is an admin or user account that is used to edit files/templates, etc.
# $CHOWN_GROUP is the group of the webserver (e.g.: 'apache', 'nginx', 'httpd', etc.)
# The project dir permissions are set to 755 (-rwxr-xr-x) for directories and to 644 (-rw-r--r--) for files
# The permissions to $DIRS[] that need to be writeable are set to 775 (-rwxrwxr-x) for directories and
# 664 (-rw-rw-r--) for files. Add any assets directories, etc. as necessary.
# Change $BASE_DIR to the absolute path where your websites are stored (leaving it appended with '/$1')
@sjelfull
sjelfull / latency.markdown
Created February 9, 2016 11:46 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs