Skip to content

Instantly share code, notes, and snippets.

@iwek
iwek / pinterest-4.js
Last active December 14, 2015 13:19
Sort and Organize Pinterest Images by Likes
//cleanup for likes
$(".likes").each(function() {
var num = Number($(this).text().trim().replace("likes", "").replace("like", ""));
$(this).html(num);
});
//sort
var mylist = $('.Pin');
var listitems = mylist.find('.likes:not(:contains(0))'); //do not match on elements that have 0 likes
listitems.sort(function(a, b) {
@iwek
iwek / maxmind.php
Created March 11, 2013 20:30
Retrieve Location from MaxMind Database in MySQL with PHP
<?php
//check the POST
$ips = $_POST["ips"];
if (empty($ips)) {
echo 'Please provide ips.';
} else {
//connect to mysql and select the maxmind database
@iwek
iwek / geo-convert.js
Created March 18, 2013 18:43
JavaScript Geographic Coordinate Conversion
function convert(geo){
var latlonrg = /(\d+(?:\.\d+)?)[\xb0\s]?\s*(?:(\d+(?:\.\d+)?)['\u2019\u2032\s])?\s*(?:(\d+(?:\.\d+)?)["\u201d\u2033\s])?\s*([SNEW])?/i;
var m = String(geo).split(latlonrg),
lat = m && +m[1] + (m[2] || 0) / 60 + (m[3] || 0) / 3600;
if (m[4].toUpperCase() == "S") {
lat = -lat;
}
@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'];
@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());
}
?>
@iwek
iwek / plugin_admin_page_function.php
Last active December 31, 2015 08:28
Building a WordPress Plugin Admin Page with a Function
<?php
add_action('admin_menu', 'plugin_admin_add_page');
function plugin_admin_add_page() {
add_options_page('Custom Plugin Page', 'Custom Plugin Options Page', 'manage_options', 'page_slug', 'plugin_options_page'); //settings menu page
}
function plugin_options_page() {
//HTML and PHP for Plugin Admin Page
echo "<h2>The Custom Plugin Options Page</h2>";
}
@iwek
iwek / adminpage.php
Created December 14, 2013 22:34
wp query
<?php
//http://codex.wordpress.org/Class_Reference/wpdb
global $wpdb;
echo "<h2>Plugin Admin Page</h2>";
$arr = $wpdb->get_results("SELECT * FROM $wpdb->users");
echo '<div id="dt_example"><div id="container"><form><div id="demo">';
echo '<table cellpadding="0" cellspacing="0" border="0" class="display" id="example"><thead><tr>';
@iwek
iwek / qc.php
Created December 14, 2013 23:37
Quick Contact WordPress Plugin Part 1
<?php
/**
* @package Quick Contact
* @version 0.1
*/
/*
Plugin Name: Quick Contact
Plugin URI: http://techslides.com/
Description: Quick Contact WordPress Plugin to make an Ajax form submission, store it in the database, and show it in a Admin backend page.
Version: 0.1
@iwek
iwek / js-closure-example.js
Last active January 14, 2016 16:42
JavaScript Closure Example
function f(y) {
var z = 1;
return function g(y) {
alert(y + z);
}
}
var z=10;
f(); //returns the function: function g(y) {alert(y + z);}
f()(2); //grabs function g, assings 2 to y, knows z is 1 through closure scope and makes an alert(3)
@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);