Skip to content

Instantly share code, notes, and snippets.

View ozh's full-sized avatar
🍷
More wine, please.

྅༻ Ǭɀħ ༄༆ཉ ozh

🍷
More wine, please.
View GitHub Profile
@ozh
ozh / yourls.js
Created May 8, 2014 12:22
YOURLS Google Analytics isogram snippet
(function(y,o,u,r,l,s){y.GoogleAnalyticsObject=r,y[r]||(y[r]=function(){(y[r].q=y[r].q||[]).push(arguments)}),
y[r].l=+new Date,l=o.createElement(u),s=o.getElementsByTagName(u)[0],l.src="//www.google-analytics.com/analytics.js",
s.parentNode.insertBefore(l,s)}(this,document,"script","ga"));
ga("create", "UA-XXXXX-X");ga("send", "pageview");
@ozh
ozh / pidof.sh
Created May 16, 2014 08:57
get PID of a process (win32 + shell utils)
#!/bin/sh
# return pid of a process
[[ $@ ]] || { echo "Usage: pidof <executable, eg prog.exe>"; exit 1; }
PIDOF=$(/c/Windows/system32/tasklist | grep "$1" | tr -s " " | cut -d" " -f2)
if [ "$PIDOF" != "" ]; then
echo $PIDOF;
fi
@ozh
ozh / keybase.md
Created September 23, 2014 19:31
keybase.md

Keybase proof

I hereby claim:

  • I am ozh on github.
  • I am ozh (https://keybase.io/ozh) on keybase.
  • I have a public key whose fingerprint is C3BF EF81 40E5 59EA F68E 85CB 3DDC 2FE0 1127 13EA

To claim this, I am signing this object:

@ozh
ozh / gist:29e69a927d52b4d91047
Last active August 29, 2015 14:08
Test URL to molest YOURLS (URL torture test)
https://www.google.com/search?q=it%27s+OK
https://www.google.com/search?q=it's+nice
https://www.google.com/search?q=it\'s+nice
https://www.google.com/search?q=it's+very OK
https://www.google.com/search?q=hey%jude
https://www.google.com/search?q=hey%%jude
https://www.google.com/search?q=hey%%%jude
https://www.google.com/search?q=url+with+%2525
https://www.google.com/search?q=@OMG (issue 1890)
http://blah.com#SoMeThing (issue 1630)
@ozh
ozh / gist:42eb3a09d3de088ff11b
Created December 5, 2014 18:46
Split string on every protocol found and build a query to be able to compute the string back
// Split a string on every URL scheme (protocol) found
function split_on_proto( st, tok ) {
// Find all protocols (eg 'http://', 'mailto:', 'whatever23://')
var protos = st.match( /[a-zA-Z0-9\+\.-]+:\/*/g );
// No protocol found? Return
if( !protos ) return st;
// Filter array of protocols to get only uniques
function aru( value, index, self ) {
@ozh
ozh / gist:e588c713f53f71ad0a2e
Last active August 29, 2015 14:11
WP patches
- https://core.trac.wordpress.org/ticket/27736
- Change smilies functions so it can return any text, not just images
- add a reset button for the title <-> slug?
- to schedule a post: how about a fucking calendar popup?
- add a reset button for scheduled posts?
@ozh
ozh / gist:0cd11817a4767d87bb72
Created January 19, 2015 11:42
Manual CRON in WP

wp-config.php:

define( 'DISABLE_WP_CRON', true );

Cronjob: one of:

*/15 * * * * wget -q -O - http://www.website.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
*/15 * * * * curl http://www.website.com/wp-cron.php?doing_wp_cron > /dev/null 2>&1
*/15 * * * * cd /home/user/public_html; php wp-cron.php &gt; /dev/null 2&gt;&amp;1
@ozh
ozh / bench.php
Created May 2, 2015 20:33
Stupid PHP benchmark
<?php
$timestart = $timeend = 0;
function timer_start() {
global $timestart;
$timestart = microtime( true );
return true;
}
function timer_stop( $display = 0, $precision = 5 ) {
global $timestart, $timeend;
$timeend = microtime( true );
@ozh
ozh / plugin.php
Created May 5, 2015 04:36
Example of how to add and remove filters (or actions) within a YOURLS plugin class
<?php
/**
* Example of how to add and remove filters (or actions) within a plugin class
*/
class Add_Remove_Filter {
function __construct() {
yourls_add_filter( 'ozh', array( $this, 'do_something' ) );
@ozh
ozh / this-does-not-work.php
Created May 10, 2015 20:34
Using $this or self:: in anonymous closures, PHP 5.3 and after
<?php
class Something {
public static $counter;
public function meh() {
self::$counter = 0;
for ( $i = 1; $i <= 5; $i++ ) {
$func = function() { ++self::$counter; return true; };