Skip to content

Instantly share code, notes, and snippets.

@forsvunnet
forsvunnet / dot-path-resolver.php
Created July 19, 2018 12:59
Dot path resolver
<?php
function convert(&$arr, $path, $value) {
$keys = explode('.', $path);
foreach ($keys as $key) {
if ( ! isset( $arr[$key] ) ) {
$arr[$key] = [];
}
$arr = &$arr[$key];
@forsvunnet
forsvunnet / generate_combinations.js
Created June 12, 2018 14:30
Get all cell combinations from a 2d array
/**
* Recursive mapping
* @param array collection Any 2d array
* @param integer index The starting index (used for recursion)
* @return array Array with all possible combination of items
*/
var generate_combinations = function( collection, index ) {
// Sanity check
if ( ! collection[ index ] ) {
@forsvunnet
forsvunnet / waybill.php
Created May 11, 2018 12:05
WP: Remove "add new" for post type
<?php
class Post_Type_Waybill {
static function setup() {
// add_filter( 'user_has_cap', __CLASS__ .'::disallow_new_post_button', 10, 2 );
// add_filter( 'user_has_cap', __CLASS__ .'::disallow_new_post_page', 10, 2 );
add_action( 'init', __CLASS__ .'::waybill_capabilities', 0 );
add_action( 'init', __CLASS__ .'::waybill_post_type', 1 );
@forsvunnet
forsvunnet / zero-dimensions.php
Created November 4, 2017 21:06
Zero dimensions
<?php
$wp_did_header = true;
require_once 'public/wp-load.php';
$args = [
'post_type' => 'product',
'posts_per_page' => -1,
'fields' => 'ids',
@forsvunnet
forsvunnet / linode-install-procedure.sh
Last active May 15, 2017 08:36
Linode install procedure
echo "Installing web software" && \
apt-get update \
apt-get install \
zip \
git \
zsh \
mariadb-server apache2 php php-mbstring php-dom php-mcrypt libapache2-mod-php php-mysql \
letsencrypt python-letsencrypt-apache \
-y && \
@forsvunnet
forsvunnet / log-checker.php
Created November 28, 2016 11:03
Log checker
<?php
$base_path = '/Users/eivin.landa/Workspace';
$who = 'Eivin';
$repos = [
'AVREmea/emea.dev',
'Exist/exist.dev',
'Soma/soma.dev',
@forsvunnet
forsvunnet / wp-ajax-plugin-example.php
Created November 18, 2016 11:07
WordPress ajax plugin example
Replace name_of_action with the name of the ajax action;
Replace name-of-plugin and name_of_plugin with the name of the plugin
File: name-of-plugin.php
<?php
class name_of_plugin {
/**
* Setup
*/
@forsvunnet
forsvunnet / phpsendmail.php
Created September 29, 2016 14:35
phpsendmail
#!/usr/bin/php
<?php
date_default_timezone_set('CET');
/**
* This script is a sendmail wrapper for php to log calls of the php mail() function.
*/
//* Get the email content
$logline = '';
$pointer = fopen('php://stdin', 'r');
@forsvunnet
forsvunnet / Front.php
Created March 2, 2016 09:52
app / code / local / Mage / Core / Controller / Varien / Front.php
<?php
$file_content = file_get_contents( MAGENTO_ROOT. '/app/code/core/Mage/Core/Controller/Varien/Front.php' );
$look_for = '->setRedirect($baseUrl, $redirectCode)';
$use = '->setRedirect( $baseUrl . substr( $requestUri, 1 ), $redirectCode )';
$file_content = str_replace( '<?php', '', $file_content );
$file_content = str_replace( $look_for, $use, $file_content );
eval( $file_content );
<?php /* This changes the CSV into another CSV. But merges duplicated fields. */
$fh = fopen("clubexp.csv", "r");
$row = 0;
$clubs = array();
while (($data = fgetcsv($fh, 1000, ",")) !== FALSE) {
// ID
$club_id = $data[0];
// Day