Skip to content

Instantly share code, notes, and snippets.

View johnie's full-sized avatar
httpster

Johnie Hjelm johnie

httpster
View GitHub Profile
@johnie
johnie / ComponentIndex.js
Created April 1, 2018 20:28 — forked from davidgljay/ComponentIndex.js
Pattern for dynamically loading React components based on a config json object.
import config from '../config'
let components = {}
//For each component in the config fiel into an object
for (var i = config.length - 1; i >= 0; i--) {
components[config[i].name] = require(config[i].path).default
}
export default components
@johnie
johnie / array.from.js
Created January 17, 2018 14:26
Array from simple polyfill
if (!Array.from) {
Array.from = function (object) {
'use strict';
return [].slice.call(object);
};
}
<?php
/**
* Insert an attachment from an URL address.
*
* @param String $url
* @param Int $post_id
* @param Array $meta_data
* @return Int Attachment ID
*/
@johnie
johnie / fix_iterm.txt
Last active September 16, 2016 21:21
Fix the most useful keyboard shortcuts for iTerm
For this and other shortcuts go to preference -> profile -> keys, add the following shortcuts
⌥← : Send Escape Sequence Esc+ b
⌥→ : Send Escape Sequence Esc+ f
⌘← : Send Escape Sequence Esc+ [H
⌘→ : Send Escape Sequence Esc+ [F
@johnie
johnie / uninstall_docker.sh
Created September 8, 2016 21:01
Uninstall Docker
#!/bin/bash
# Uninstall Script
if [ "${USER}" != "root" ]; then
echo "$0 must be run as root!"
exit 2
fi
while true; do
@johnie
johnie / curl.php
Created August 26, 2016 07:51
Make Curl call
<?php
/**
* Make Curl call.
*
* @param string $url URL to curl
* @param string $method GET or POST, Default GET
* @param mixed $data Data to post, Default false
* @param mixed $headers Additional headers, example: array ("Accept: application/json")
* @param bool $returnInfo Whether or not to retrieve curl_getinfo()
@johnie
johnie / last_business_day_of_month.js
Created June 1, 2016 22:27 — forked from arch1t3ct/last_business_day_of_month.js
Javascript (Node.js) function for getting last working/business day of the month.
/**
* Finds last working/business day of the month.
*
* Not tested for cross-browser compability. Works in Node.js though.
*
* EXAMPLES:
*
* 1. Returns last day of the last month of the current year:
*
* var result = lastBusinessDayOfMonth();
<?php
/**
* Force enable a plugin.
*
* @param array $plugins
*
* @return array
*/
add_filter( 'option_active_plugins', function ( $plugins ) {
@johnie
johnie / ajax-action.php
Last active September 5, 2015 12:00 — forked from danielpataki/ajax-action.php
Ajax in WordPress
<?php
add_action( 'wp_ajax_button_click', 'user_clicked' );
function user_clicked() {
update_user_meta( get_current_user_id(), 'clicked_link', 'yes' );
wp_redirect( $_SERVER['HTTP_REFERER'] );
exit();
}
@johnie
johnie / customize-api.php
Last active August 29, 2015 14:21
Custom Controller for latest posts
<?php
$wp_customize->add_control( new WP_Customize_Latest_Post_Control( $wp_customize, 'latest_post_control', array(
'label' => __( 'Select A Featured Post', 'mytheme' ),
'section' => 'header_section',
'settings' => 'featured_post',
'post_type' => 'page'
)));