Skip to content

Instantly share code, notes, and snippets.

View scribu's full-sized avatar

Cristi Burcă scribu

View GitHub Profile
@scribu
scribu / man.go
Last active December 15, 2015 03:49
man.go
package main
import (
"bytes"
"encoding/json"
"io"
"log"
"os"
"os/exec"
"strings"
@scribu
scribu / functional.php
Created March 16, 2013 01:54
A few utilities for functional programming in PHP.
<?php
/**
* Returns a callable which is the composition of all the arguments,
* which should be callable themselves.
*/
function fn_compose( $fn ) {
$funcs = func_get_args();
$last = array_pop( $funcs );
@scribu
scribu / test.php
Created February 8, 2013 03:12
Simulate threads in PHP using only proc_open() and co.
<?php
include __DIR__ . '/threads.php';
$commands = array();
for ( $i=0; $i<10; $i++ ) {
$commands[] = "bash -c 'sleep `shuf -i 1-5 -n 1`; echo $i'";
}
@scribu
scribu / git-fix-remote.sh
Last active November 19, 2017 16:27
Fixes the annoying "You can't push to X. Use Y" git error.
#!/usr/bin/env bash
# Fixes the annoying "You can't push to X. Use Y" git error.
while read -r line
do
read -a array <<< "$line"
remote="${array[0]}"
url="${array[1]}"
<?php
/**
* Iterates over results of a query, split into many queries via LIMIT and OFFSET
*/
class QueryIterator implements Iterator {
var $limit = 500;
var $query = '';
var $global_index = 0;
@scribu
scribu / gist:4150626
Created November 26, 2012 21:09
P2P Admin Dropdown
# author: sdls
# source: http://wordpress.org/support/topic/p2p-admin-view-sort-by-drop-down#post-3446538
function restrict_posts_by_relation() {
global $typenow;
$post_type = 'yourfirstposttype'; // change HERE
$related_post = 'yoursecondposttype'; // change HERE
$related_post_drop_down = 'related_'. $related_post. '_post';
if ($typenow == $post_type) {
@scribu
scribu / gist:4140592
Created November 24, 2012 17:19
P2P collect post types
foreach ( P2P_Connection_Type_Factory::get_all_instances() as $p2p_type => $ctype ) {
$post_types = array();
foreach ( $ctype->side as $direction => $side ) {
if ( 'post' == $side->get_object_type() ) {
$post_types[ $direction ] = $side->query_vars['post_type'];
}
}
}
@scribu
scribu / Cakefile
Created November 24, 2012 03:21
Implementation of concurrent query in CoffeeScript
# We have several database replicas and want to minimize latency by querying them
# all and returning the first response to arrive.
#
# http://concur.rspace.googlecode.com/hg/talk/concur.html#slide-54
class Connection
constructor: (@name) ->
query: (query, continuation) ->
@op = setTimeout(=>
@scribu
scribu / router.php
Created November 16, 2012 15:32 — forked from tamagokun/router.php
Run a Wordpress site via PHP's built-in web server
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
chdir( $root );
$path = '/'.ltrim( parse_url( $_SERVER['REQUEST_URI'] )['path'],'/' );
if ( file_exists( $root.$path ) )
{
if ( is_dir( $root.$path ) && substr( $path,strlen( $path ) - 1, 1 ) !== '/' )
{
@scribu
scribu / php-init.sh
Created November 12, 2012 16:35
Ubuntu PHP Dev Setup
#!/bin/bash
# LEMP
apt-get -y install nginx mysql-server php5-mysql php5-fpm
# extra php packages
apt-get -y install php5-cli php5-gd php5-curl php5-xdebug
# change user from www-data to scribu
sed -i 's/www-data/scribu/g' /etc/nginx/nginx.conf /etc/php5/fpm/pool.d/www.conf