Skip to content

Instantly share code, notes, and snippets.

ethanpil

Block or report user

Report or block ethanpil

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ethanpil
ethanpil / gist:78e950942ef49bd254b40529b4b61f41
Created Jun 12, 2017
PHP Process Forks / Parallel Processing
View gist:78e950942ef49bd254b40529b4b61f41
<?php
// Source: https://www.stitcher.io/blog/process-forks
function async(Process $process) : Process {
socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $sockets);
[$parentSocket, $childSocket] = $sockets;
if (($pid = pcntl_fork()) == 0) {
socket_close($childSocket);
socket_write($parentSocket, serialize($process->execute()));
@ethanpil
ethanpil / regex.custom.pm
Created May 16, 2017
Custom regex rules for CSF/LFD and NginX plus Wordpress fail2ban plugin
View regex.custom.pm
#!/usr/bin/perl
###############################################################################
# Copyright 2006-2015, Way to the Web Limited
# URL: http://www.configserver.com
# Email: sales@waytotheweb.com
###############################################################################
sub custom_line {
my $line = shift;
my $lgfile = shift;
@ethanpil
ethanpil / wp-secure.conf
Created May 12, 2017
Wordpress Security for NginX
View wp-secure.conf
# wp-secure.conf
#
#
# This file includes common security considerations for wordpress using nginx.
#
# The goal is to block actions which are usually dangerous to wordpress.
# Additionally, we block direct access to PHP files and folders which should not
# be accessed directly from a browser.
#
# Also have included exceptions for plugins that are known to require this access.
View chromecastbg.xml
<?xml version="1.0" encoding="utf-8"?>
<rss version = "2.0" xmlns:media = "http://search.yahoo.com/mrss/">
<channel>
<title>Chromecast BG</title>
<link>http://chromecastbg.alexmeub.com</link>
<description>Chromecast Bakground Images</description>
<item>
<title>John Cavacas</title>
@ethanpil
ethanpil / example.php
Created Aug 3, 2016
HTML to PDF with PHP and wkhtmltopdf
View example.php
<?php
/******
I was using tcpdf then mpdf for years, and then I discovered wkhtmltopdf and it changed my life.
If you can exec() then you will enjoy super fast operation, no more memory/process time outs,
and overall easier and better PDFs... Check out http://wkhtmltopdf.org/ ... binaries for most platforms.
******/
//Setup file parameters
$cwd = getcwd();
@ethanpil
ethanpil / example.php
Created Aug 2, 2016
Upload file via FTP in Curl
View example.php
<?php
$ch = curl_init();
$localfile = '/path/to/file.zip';
$remotefile = 'filename.zip';
$fp = fopen($localfile, 'r');
curl_setopt($ch, CURLOPT_URL, 'ftp://ftp_login:password@ftp.domain.com/'.$remotefile);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
View gist:94455f8de76671aa9024
<?php
/**
* Reference/source: http://stackoverflow.com/a/1464155/933782
*
* I want a short alphanumeric hash that’s unique and who’s sequence is difficult to deduce.
* I could run it out to md5 and trim the first n chars but that’s not going to be very unique.
* Storing a truncated checksum in a unique field means that the frequency of collisions will increase
* geometrically as the number of unique keys for a base 62 encoded integer approaches 62^n.
* I’d rather do it right than code myself a timebomb. So I came up with this.
*
@ethanpil
ethanpil / gist:5d86a50d3cf44989a035
Created Jul 9, 2015
Ensure child theme's style.css is loaded after all parent theme's css, including layout.css (For woothemes products)
View gist:5d86a50d3cf44989a035
<?php
/*
The best solution to make sure that your child theme's style.css loads after the parent theme's layout.css.
Then you can easily override the small things you need in the usual manner via style.css and upgrade the
parent theme without worry Here is some code that works for WooThemes products, which ensures that your
child theme css is always loaded after the parent child's layout.css
It belongs in the child theme's functions.php
*/
@ethanpil
ethanpil / gist:8d430fc8c8d7b82c11ab
Created Jul 9, 2015
Useful CSV Parsing Function
View gist:8d430fc8c8d7b82c11ab
//Usage
$myData = csvParse(file_get_contents('csv.file'),true);
function csvParse($in, $hasHeaders=false, &$returnHeadersList=NULL){
$in .= "\n"; //NL required to allow reading when the last line hasn't been terminated.
$data=array(); //All Data here
$dataRow=array(); //Row of date being read
$dataInQuotes=false; //Is reading byte currently in Quotes?
$dataTemp = ''; //Storate of Value
@ethanpil
ethanpil / gist:51b2aae90c55d1a99ea7
Created Jul 24, 2014
Delete all WooCommerce Products from Wordpress Database
View gist:51b2aae90c55d1a99ea7
-- Delete all WooCommerce Products from Wordpress Database
-- Thanks to http://www.kc-webdesign.co.uk/e_commerce/woocommerce-how-to-delete-all-products/
DELETE relations.*, taxes.*, terms.*
FROM wp_term_relationships AS relations
INNER JOIN wp_term_taxonomy AS taxes
ON relations.term_taxonomy_id=taxes.term_taxonomy_id
INNER JOIN wp_terms AS terms
ON taxes.term_id=terms.term_id
WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type='product');
You can’t perform that action at this time.