Skip to content

Instantly share code, notes, and snippets.

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 Apr 8, 2017
Creating a Facebook App programmatically using CasperJS
View create-facebook-app.js
//
// 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
WordPress style shortcodes in Vue
View CodeSlot.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 Jun 11, 2018
Laravel and Webpack (with webpack-dev-server)
View app__Console__Commands__WebpackCommand.php
<?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 Oct 14, 2016
Simple PHP setup for Caddy local dev
View Caddyfile
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 Aug 15, 2016
Module rewrite that enables same increment prefix for each Magento store under a website.
View Numeric.php
<?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 Jul 27, 2016
Re-zips github repo zipfile so that the first fold is not the repo name but the actual src
View gzip.sh
#!/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 Aug 8, 2016
Object predicates for ko.utils.arrayFirst and similar
View example.js
// 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 Jul 27, 2016
99 Elm problems — My solutions (solution only listed if different from others)
View lists-problem-3.elm
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 Jul 24, 2016
Closure::bind (native JS-like bind in PHP)
View bind-with-php.php
<?php
class A {
public $param = 7;
}
class B {
private $param = 28;
}
View knockout.subscribeChanged.js
/**
* 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) {