Skip to content

Instantly share code, notes, and snippets.

View gibrown's full-sized avatar

Greg Ichneumon Brown gibrown

View GitHub Profile
<?php
// This uses the wpes-lib framework to build the index: https://github.com/automattic/wpes-lib
class WPOrg_Plugins_Index_Builder extends VIP_Index_Builder {
//override to add support for all analyzers
public function get_settings( $args ) {
$defaults = array(
);
$args = wp_parse_args( $args, $defaults );
@gibrown
gibrown / sim_score.py
Created March 13, 2017 22:55
Simple graphing of Elasticsearch scoring functions.
from __future__ import division
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from pylab import *
import math
from scipy.stats import beta, norm, uniform
from scipy.special import betaln
from random import random, normalvariate
import numpy as np
@gibrown
gibrown / index-data.sh
Created February 15, 2017 16:48
Populate an Elasticsearch index from bash and json files
#!/bin/bash
# To prep a file for this script:
# - take a list of docs orig.json with one json doc per line
# - run: split -l 1000 orig.json orig-split
export ESINDEX="$1" #ES index name
export ESTYPE="$2" #ES document type name
JSONFILE="$3" #JSON file path name. One doc per line.
@gibrown
gibrown / bulk_test_queries.py
Created April 10, 2017 17:01
Querying wp.org plugin search
#/bin/python
import sys
import org_search as org
import pprint
import csv
#Configuration
lang='en_US'
min_count=1000
<?php
class Theme_Support_Index_Builder extends WPES_Abstract_Index_Builder {
public function get_config( $args ) {
$defaults = array(
'lang' => 'en',
);
$args = wp_parse_args( $args, $defaults );
@gibrown
gibrown / gist:23dc6ee65f5bcd41cd09
Created January 6, 2016 18:49
Query WP posts and weight recent posts more heavily
//These are some params I've used elsewhere, may want to try adjusting
$date_scale = '5d';
$date_decay = 0.99999;
$date_origin = date( 'Y-m-d' );
$query = array(
'query' => array(
"function_score" => array(
'query' => array( 'filtered' => array(
'query' => array( 'multi_match' => array(
'query' => $query,
function es_api_detect_lang( $text ) {
$lang = false;
//if we can't tell the lang with 5000 characters we probably can't tell the language
$text = mb_substr( $text, 0, 5000 );
//replace non-breaking spaces so they don't match the \p{L} char class
$text = preg_replace( '/[\x{00A0}\x{2007}\x{202F}]/u', ' ', $text );
//replace unicode symbols: see: http://www.utf8-chartable.de/unicode-utf8-table.pl
Մեր հÕ րևÕ Õ բÕ կում երկու եղբÕ յր Õ Õ Õ Õ պրում ՄÕ օր եղբÕ յրÕ երը որոÕ եցÕ Õ բÕ րձրÕ Õ Õ լ Õ րեÕ ց Õ Õ Õ Õ Õ Õ Õ քը ՔÕ Õ եցÕ Õ բերեցÕ Õ ծÕ Õ ր սÕ Õ դուղքը ու բÕ րձրÕ ցÕ Õ մութ Õ Õ Õ Õ քը Փոքր եղբÕ յրը Õ Õ Õ վÕ խկոÕ Õ ր Õ սկ մեծ եղբÕ յրը Õ Õ ըÕ դհÕ Õ Õ րÕ Õ հÕ մոզում Õ ր որ Õ մեÕ Õ Õ չ լÕ վ կլÕ Õ Õ որ չվÕ խեÕ Õ ՀÕ զÕ վ Õ Õ Õ բÕ րձրÕ ցել վերև երբ փոքր եղբÕ յրը չÕ կÕ Õ եց գեÕ Õ Õ Õ դրվÕ ծ Õ Õ խÕ Õ կÕ երը ոÕ քով դÕ պÕ վ դրÕ Õ ց ու վÕ յր ըÕ կÕ վ ՔÕ Õ Õ որ փոքր Õ ր Õ սկույÕ սկսեց լÕ ց լÕ Õ ել Õ սկ մեծ եղբÕ յրը Õ րÕ Õ հÕ Õ գսÕ Õ ցրեց Õ սելով որ դÕ կլÕ Õ Õ Õ րեÕ ց գÕ ղÕ Õ Õ քը և ոչ ոք Õ յդ մÕ սÕ Õ չÕ Õ մÕ Õ Õ
WordPress.com Debug
11:42 AM (32 minutes ago)
to greg
Text:
<?php
/**
* VIPs need some special vetting as they can have custom code in the functions.php
* to setup custom taxonomies / post types and the like.
*
* We need to load the functions.php file for these themes.
*
* An other problem is that things which are usually attached to early hooks such as init or after_theme_setup
* in order to register custom taxonomies or post types are not working as the init hook already fired off when the jobs action is executed.
* So we copy all functions attached to the hooks we need ( currently after_theme_setup, init ) to an other hook and fire it off
@gibrown
gibrown / gist:7122061
Created October 23, 2013 16:38
ES lang detect API text cleaning code.
//if we can't tell the lang with 5000 characters we probably can't tell the language
$text = mb_substr( $text, 0, 5000 );
//replace non-breaking spaces so they don't match the \p{L} char class
$text = preg_replace( '/[\x{00A0}\x{2007}\x{202F}]/u', ' ', $text );
//replace unicode symbols: see: http://www.utf8-chartable.de/unicode-utf8-table.pl
$text = preg_replace( '/[\x{2000}-\x{2BFF}]/u', ' ', $text ); //symbols
$text = preg_replace( '/[\x{1f000}-\x{1ffff}]/u', ' ', $text ); //symbols, emoticons