Skip to content

Instantly share code, notes, and snippets.

View sjelfull's full-sized avatar

Fred Carlsen sjelfull

View GitHub Profile
<?php
class CraftValetDriver extends ValetDriver
{
/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
@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 / 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

@sjelfull
sjelfull / zip.php
Created January 6, 2016 13:02 — forked from jonmaim/zip.php
PHP script to remotely create zip archives of your FTP
<?php
/*
*
* This script will backup your web site by remotely archiving all files on the root FTP directory.
* It will work even if your web server is memory limited buy splitting zips in several arhive files it they are too many files.
* All zip files will be stored in a directory called temporary which must be writable.
*
* How to use it:
* - Place the script at the root of your FTP.