Skip to content

Instantly share code, notes, and snippets.

/* Produces a dump on the state of WordPress when a not found error occurs */
/* useful when debugging permalink issues, rewrite rule trouble, place inside functions.php */
ini_set( 'error_reporting', -1 );
ini_set( 'display_errors', 'On' );
echo '<pre>';
add_action( 'parse_request', 'debug_404_rewrite_dump' );
function debug_404_rewrite_dump( &$wp ) {
if ( !class_exists( 'HijackMe' ) ) {
class HijackMe {
public function hijack_menu($objects) {
/**
* If user isn't logged in, we return the link as normal
*/
if ( !is_user_logged_in() ) {
return $objects;
}
/**
This gist contains two files for simple indexing of PDF files.
== requirements ==
First you need to install Solr (which requires a Java JDK): Download a tar or zipfile at http://www.apache.org/dyn/closer.cgi/lucene/solr/ and unpack it to a directory of your choice. Go into this directory and start solr running in jetty by:
$ cd example
$ java -jar start.jar
Then locate your browser to http://localhost:8983/solr/
$mock = Mockery::mock('SceneMongo');
$mock->shouldReceive('where')->with('visible', 1)->once()->andReturn($mock);
$mock->shouldReceive('where')->with('published_at', '<=', Mockery::type('int'))->once()->andReturn($mock);
$mock->shouldReceive('take')->with($limit)->once()->andReturn($mock);
$mock->shouldReceive('orderBy')->with('rating', 'DESC')->once()->andReturn($mock);
$mock->shouldReceive('get')->once()->andReturn($collection);
@ivanhoe011
ivanhoe011 / split.php
Created November 4, 2014 15:41
Split huge csv vertically
<?php
$split_on_column = 150; // on which column we split
$fp = fopen('big.csv', 'r'); // input
$f1 = fopen('out1.csv', 'w'); // output1
$f2 = fopen('out2.csv', 'w'); // output2
while ($row = fgetcsv($fp)) {
@ivanhoe011
ivanhoe011 / scrapper.js
Last active August 29, 2015 14:11
Tutsplus lesson scrapper (save in Chrome's Dev tools as a snippet)
// run from the index page of the course
(function () {
var urls = [],
videos = [];
// get lesson urls
$('.lesson-index__lesson-link').each( function () {
urls.push( $(this).attr('href') );
function scaleImage(ev)
{
var data = ev.data,
editor = ev.editor;
var img = data.image;
// maximum size allowed for images
var maxX = 400;
var maxY = 300;
@ivanhoe011
ivanhoe011 / laravel_auth_user_types.php
Last active August 29, 2015 14:15
How to authorize different types of users in L4/5
// in User.php model add few checks
public function is_admin()
{
return ($this->account_type === 'admin'); // account_type is ENUM field
}
public function has_rights($acc_type)
{
if ($this->is_admin()) { // if admin always true
return true;
@ivanhoe011
ivanhoe011 / wp_adv_search.php
Last active August 29, 2015 14:17
Advanced search example
<?php
// filter je upit koji zavisi od toga sta je popunjeno u pretrazi
$filter = array('relation' => 'AND');
// zavisno sta je od polja poslato u upitu kreiramo upit:
if ( ! empty($_GET['tip'])) { // ako pretrazujes po tipu nekretnine
$filter[] = array(
'key' => 'tip', // ovo je ime custom polja, recimo da je 'tip'
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working directory clean" ]] && echo "*"
}
parse_git_branch() {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\] $(parse_git_branch)\[\033[00m\]\$ '