Skip to content

Instantly share code, notes, and snippets.

@iwek
iwek / save_wp_error.php
Last active December 31, 2015 08:19
Send WordPress Plugin Activation Errors to a File
<?php
add_action('activated_plugin','save_error');
function save_error(){
file_put_contents(ABSPATH. 'wp-content/plugins/PLUGIN_FOLDER/error.html', ob_get_contents());
}
?>
{
"status": "success",
"search_nag": {},
"code": 0,
"bookmark": "b28xMDB8MDQ0NWZiOTBjNzNiODlkOTQ1ZTk3ZjY0ZTBhYjU0YjM0ZDYyNDg3NjU3ZWQ3OGJmZjI4ZTliZGRmODBlMzJlNQ==",
"debug_data": {
"query_data": {}
},
"message": "ok",
"data": [
{
"status": "success",
"code": 0,
"message": "ok",
"data": {
"last_name": "Alba",
"domain_verified": false,
"following_count": 71,
"image_medium_url": "http://media-cache-ec0.pinimg.com/avatars/jessicamalba_1360689715_75.jpg",
"implicitly_followed_by_me": false,
@iwek
iwek / tsv-to-json.js
Last active March 20, 2023 02:46
TSV to JSON Conversion in JavaScript
//var tsv is the TSV file with headers
function tsvJSON(tsv){
var lines=tsv.split("\n");
var result = [];
var headers=lines[0].split("\t");
for(var i=1;i<lines.length;i++){
@iwek
iwek / csv-to-json.js
Last active April 24, 2024 19:05
CSV to JSON Conversion in JavaScript
//var csv is the CSV file with headers
function csvJSON(csv){
var lines=csv.split("\n");
var result = [];
var headers=lines[0].split(",");
for(var i=1;i<lines.length;i++){
@iwek
iwek / imagedata-to-filename.js
Created October 23, 2013 20:37
Convert CANVAS data to binary data and then to a filename using a Blob
function binaryblob(){
var byteString = atob(document.querySelector("canvas").toDataURL().replace(/^data:image\/(png|jpg);base64,/, ""));
var ia = new Uint8Array(ab);
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
var dataView = new DataView(ab);
var blob = new Blob([dataView], {type: "image/png"});
var DOMURL = self.URL || self.webkitURL || self;
var newurl = DOMURL.createObjectURL(blob);
@iwek
iwek / svg-image2.js
Created October 23, 2013 16:26
D3js click function to save SVG as dataurl in IMG tag, load into CANVAS and save as PNG dataurl, and auto download the actual PNG file.
d3.select("#save").on("click", function(){
var html = d3.select("svg")
.attr("version", 1.1)
.attr("xmlns", "http://www.w3.org/2000/svg")
.node().parentNode.innerHTML;
//console.log(html);
var imgsrc = 'data:image/svg+xml;base64,'+ btoa(html);
var img = '<img src="'+imgsrc+'">';
d3.select("#svgdataurl").html(img);
@iwek
iwek / svg-image1.js
Created October 23, 2013 16:02
D3 click function to save SVG as dataurl in IMG tag
d3.select("#save").on("click", function(){
var html = d3.select("svg")
.attr("version", 1.1)
.attr("xmlns", "http://www.w3.org/2000/svg")
.node().parentNode.innerHTML;
//console.log(html);
var imgsrc = 'data:image/svg+xml;base64,'+ btoa(html);
var img = '<img src="'+imgsrc+'">';
d3.select("#svgdataurl").html(img);
@iwek
iwek / api-cache.php
Created August 16, 2013 20:32
PHP Caching Multiple API Calls with PHP Simple Cache
<?php
require('simpleCache.php');
$cache = new SimpleCache();
$minx = $_GET['minx'];
$maxx = $_GET['maxx'];
$miny = $_GET['miny'];