Skip to content

Instantly share code, notes, and snippets.

View mblarsen's full-sized avatar
💭
Actively recommending people not to use WordPress!

Michael Bøcker-Larsen mblarsen

💭
Actively recommending people not to use WordPress!
View GitHub Profile
@mblarsen
mblarsen / create-facebook-app.js
Last active April 8, 2017 04:24
Creating a Facebook App programmatically using CasperJS
//
// run: casperjs --engine=slimerjs create-facebook-app.js
//
const casper = require('casper').create({
verbose: true,
loglevel: 'debug',
})
/* captures every step */
@mblarsen
mblarsen / CodeSlot.vue
Last active May 19, 2018 15:17
WordPress style shortcodes in Vue
/* Based on ideas described here: https://medium.com/@mblarsen/wordpress-style-shortcodes-using-vue-js-d2acd20f403f */
<script>
import 'babel-polyfill'
import { default as Tokenizer } from 'shortcode-tokenizer'
import Vue from 'vue'
import Row from 'components/ui/Row'
import Column from 'components/ui/Column'
import ProductList from 'components/content/ProductList'
import ProductCard from 'components/content/ProductCard'
@mblarsen
mblarsen / app__Console__Commands__WebpackCommand.php
Last active June 11, 2018 00:43
Laravel and Webpack (with webpack-dev-server)
<?php
namespace Supawdog\Console\Commands;
use Illuminate\Console\Command;
use Symfony\Component\Process\ProcessUtils;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Process\PhpExecutableFinder;
class WebpackCommand extends Command
@mblarsen
mblarsen / Caddyfile
Created October 14, 2016 02:31
Simple PHP setup for Caddy local dev
codeboutique.dev:80 {
root /var/www/codeboutique
gzip
tls off
log stdout
errors stderr
fastcgi / /run/php/php7.0-fpm.sock php {
ext .php
index index.php index.html
}
@mblarsen
mblarsen / Numeric.php
Created August 15, 2016 17:56
Module rewrite that enables same increment prefix for each Magento store under a website.
<?php
// app/code/local/Namespace/Modulename/Eav/Model/Entity/Increment/Numeric.php
/**
* Changes the next id behaviour so that all stores share the same increment
* for orders, invoces, creditmemos and shipments if they share the same
* increment prefix.
*
* 1. In eav_entity_type leave increment_model to be the default eav/entity_increment_numeric
*
@mblarsen
mblarsen / gzip.sh
Last active July 27, 2016 12:49
Re-zips github repo zipfile so that the first fold is not the repo name but the actual src
#!/bin/bash
# Moves Github zipped-repo files into root of zip files
#
# knockout-master.zip:
#
# knockout-master/<all files>
#
# to:
#
@mblarsen
mblarsen / example.js
Last active August 8, 2016 14:41
Object predicates for ko.utils.arrayFirst and similar
// Override arrayFirst (but remain backward compatible)
ko.utils._arrayFirst = ko.utils.arrayFirst
ko.utils.arrayFirst = function (array, ...predicateParams) {
// In case used as regular arrayFirst
if (typeof predicateParams[0] === 'function') {
return ko.utils._arrayFirst(array, predicateParams[0])
}
// Otherwise wrap
return ko.utils._arrayFirst(array, ko.utils.objectPredicate(...predicateParams))
}
@mblarsen
mblarsen / lists-problem-3.elm
Last active July 27, 2016 03:15
99 Elm problems — My solutions (solution only listed if different from others)
elementAt : List a -> Int -> Maybe a
elementAt xs n =
case List.drop (n - 1) xs of
[ ]
-> Nothing
y::ys
-> Just y
@mblarsen
mblarsen / bind-with-php.php
Last active July 24, 2016 03:23
Closure::bind (native JS-like bind in PHP)
<?php
class A {
public $param = 7;
}
class B {
private $param = 28;
}
/**
* Knockout.js extension that gives both new and old value to
* subscription functions.
*
* Credit: http://stackoverflow.com/a/18184016/204610
*
* Changed JBeagle's code to return a disposable subscription
* object so it conforms to subscribe()
*/
ko.subscribable.fn.subscribeChanged = function (callback) {