Skip to content

Instantly share code, notes, and snippets.

View timneutkens's full-sized avatar
👋

Tim Neutkens timneutkens

👋
View GitHub Profile
@timneutkens
timneutkens / countposts.php
Created July 11, 2016 12:57
WPML wp_count_posts fix. Taken from http://pastebin.com/E5nMcF25
function count_posts($language_code = '', $post_type = 'post', $post_status = 'publish'){
global $sitepress, $wpdb;
//get default language code
$default_language_code = $sitepress->get_default_language();
//adjust post type to format WPML uses
switch($post_type){
case 'page':
@timneutkens
timneutkens / config-load-data-infile.yml
Created July 4, 2016 08:24
Enable LOAD DATA INFILE Symfony Doctrine
doctrine:
dbal:
option:
# This is PDO::MYSQL_ATTR_LOCAL_INFILE
1001: true
@timneutkens
timneutkens / rewriterules.js
Last active July 4, 2016 08:25
Fast way to create apache rewrite rules
// Create RewriteRule from given variables
function createRewriteString(oldUrl, newUrl, removeDomainPrefix) {
return 'RewriteRule ^' + oldUrl.replace(removeDomainPrefix, '') + '/?$ ' + newUrl + ' [NC,L,R=301]'
}
// Url to path mapping. Seperated by one space.
const urls = `http://example.com/foo/bar /bar/foo
http://example.com/foo/baz /baz/foo`
// Split by line break
@timneutkens
timneutkens / bootstrap-popover-hover.js
Last active June 2, 2021 13:24
Keep Bootstrap popover open when the popover itself is being hovered
jQuery('[data-toggle="popover-hover"]').popover({
trigger: 'manual',
html: true,
animation:false,
viewport: '.container'
}).on('mouseenter', function () {
var self = this;
jQuery(this).popover("show");
jQuery(".popover").on('mouseleave', function () {
jQuery(self).popover('hide');
/**
* detect a click outside of an element and trigger callbacks based on that click.
* @param trigger
* @param element
* @param openCallback
* @param closeCallback
*/
function DetectClickOutsideOfElement (trigger, element, openCallback, closeCallback) {
var enabled = false;
GITDIR='remote'; echo ssh://${USER}@${HOSTNAME}:${PWD}/${GITDIR}.git
@timneutkens
timneutkens / get-excerpt.php
Last active May 26, 2025 09:54
Get excerpt of string
<?php
/**
* Small utility function to get an excerpt. Standard length is 100 characters
*
* @param $string
* @param int $start_postion
* @param int $max_length
*
* @return string
*/
@timneutkens
timneutkens / codeigniter-export-language.php
Created April 29, 2016 07:13
Export specific language directory to csv
<?php
/**
* PHP version 5.4
* @category Export
* @package Language
* @author Tim Neutkens <[email protected]>
* @license MIT <https://opensource.org/licenses/MIT>
* @link <weprovide.com>
*/
@timneutkens
timneutkens / wordpress-dbsync.sh
Created April 24, 2016 20:45
Export / import wordpress database oneliner
# Uses these 2 tools:
# http://wp-cli.org/
# https://github.com/xwp/wp-cli-ssh
# Remote to local
wp ssh db export - --host=production | wp db import -
# Local to remote BEWARE THIS IS DANGEROUS BUT KEPT AS REFERENCE
wp db export - | wp ssh db import - --host=production
@timneutkens
timneutkens / fpdf-image.php
Created April 14, 2016 14:36
Insert base64 image data into fpdf
<?php
// load the 'fpdf' extension
require('fpdf.php');
// just for demonstration purpose, the OP gets the content from a database instead
$h_img = fopen('img.jpg', "rb");
$img = fread($h_img, filesize('img.jpg'));
fclose($h_img);
// prepare a base64 encoded "data url"