Skip to content

Instantly share code, notes, and snippets.

window.resolveLocalFileSystemURI(filePath, function(fileEntry) {
fileEntry.file(function(fileObj) {
console.log("Size = " + fileObj.size);
console.log("Size = " + fileObj.fullPath);
});
});
@ethanpil
ethanpil / gist:2c2820db71312a5004b1
Created May 23, 2014 21:02
Delete All Products From WooCommerce
#Delete all products from WooCommerce DB
#http://wordpress.org/support/topic/remove-all-woocommerce-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');
@ethanpil
ethanpil / example.php
Last active August 29, 2015 14:02
Wordpress Add Custom Meta Box to Page
//Code for template file:
global $post;
if ( get_post_meta($post->ID, 'active_page_showzipform', true ) ) :
//Checkbox is checked... do somehting
endif;
//Code for functions.php --- Begin Custom Code for Page Metabox
function active_add_meta_box() {
add_meta_box(
@ethanpil
ethanpil / gist:51b2aae90c55d1a99ea7
Created July 24, 2014 21:56
Delete all WooCommerce Products from Wordpress Database
-- 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');
@ethanpil
ethanpil / gist:8d430fc8c8d7b82c11ab
Created July 9, 2015 13:29
Useful CSV Parsing Function
//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 / example.php
Created August 2, 2016 19:41
Upload file via FTP in Curl
<?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));
@ethanpil
ethanpil / gist:78e950942ef49bd254b40529b4b61f41
Created June 12, 2017 14:39
PHP Process Forks / Parallel Processing
<?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 / chromecastbg.xml
Last active September 2, 2017 05:48
chromecastbg
<?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 / gist:4074756
Created November 14, 2012 20:56
Simple Code Obfuscator for PHP
<?php
/* Simple Code Obfuscator for PHP
* See: http://stackoverflow.com/questions/232736/code-obfuscator-for-php/3781356#3781356
*/
$infile=$_SERVER['argv'][1];
$outfile=$_SERVER['argv'][2];
if (!$infile || !$outfile) {
@ethanpil
ethanpil / gist:8675160
Created January 28, 2014 20:01
Insert A Random String from List in MySQL
UPDATE tablename
SET columnname = ELT(0.5 + RAND() * 6, 'value 1','value 2','value 3','value 4','value 5','value 6')