Skip to content

Instantly share code, notes, and snippets.

@iwek
iwek / AZ-Template-Page.php
Created October 30, 2012 02:43
AZ Category Index Template Page
<?php
/*
Template Name: Page Template for AZ Categories Index
Author URI: http://techslides.com/
*/
?>
<?php get_header(); ?>
<div id="content" class="widecolumn">
<?php
@iwek
iwek / A-Z-Category-Index.php
Created October 30, 2012 02:42
A-Z Category Index
<?php
/**
* @package A-Z Category Index
* @version 0.1
*/
/*
Plugin Name: A-Z Category Index
Plugin URI: http://wordpress.org/
Description: A-Z Category Index where each letter takes you to a page with a list of categories that start with that letter.
Version: 0.1
@iwek
iwek / simple-wp-import-example.xml
Created October 30, 2012 01:43
Simple WordPress Import Structure XML Example
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0"
xmlns:excerpt="http://wordpress.org/export/1.2/excerpt/"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:wp="http://wordpress.org/export/1.2/"
>
@iwek
iwek / grab-html-source.js
Created October 21, 2012 19:00
grab html source in casperjs or phantomjs
//phantomjs
var page = require('webpage').create();
var url = 'http://instagram.com/';
page.open(url, function (status) {
var js = page.evaluate(function () {
return document;
});
console.log(js.all[0].outerHTML);
phantom.exit();
@iwek
iwek / document.js
Created October 21, 2012 18:55
document json
//phantomjs
var page = require('webpage').create();
var url = 'http://instagram.com/';
page.open(url, function (status) {
var js = page.evaluate(function () {
return document;
});
console.log(JSON.stringify(js));
phantom.exit();
@iwek
iwek / find-in-json.js
Created October 20, 2012 21:43
Searching through JSON
//return an array of objects according to key, value, or key and value matching
function getObjects(obj, key, val) {
var objects = [];
for (var i in obj) {
if (!obj.hasOwnProperty(i)) continue;
if (typeof obj[i] == 'object') {
objects = objects.concat(getObjects(obj[i], key, val));
} else
//if key matches and value matches or if key matches and value is not passed (eliminating the case where key matches but passed value does not)
if (i == key && obj[i] == val || i == key && val == '') { //
@iwek
iwek / json-example.json
Created October 20, 2012 19:06
JSON Example
{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
@iwek
iwek / address-GeoLocation.js
Created October 10, 2012 20:57
GeoLocation with Google API Reverse Geocoding Form Filler
var find1 = document.getElementById("find1");
var find2 = document.getElementById("find2");
var info = document.getElementById("info");
//use array to determine how it goes into DOM, I think you could use Data Attributes: http://html5doctor.com/html5-custom-data-attributes/
var selector = [];
find1.addEventListener("click", function() {
@iwek
iwek / drag-drop-upload-unzip.js
Created October 2, 2012 19:43
Drag and Drop, Upload and Unzip
/* Drag'n drop stuff */
var drag = document.getElementById("drag");
drag.ondragover = function(e) {e.preventDefault()}
drag.ondrop = function(e) {
e.preventDefault();
var length = e.dataTransfer.items.length;
for (var i = 0; i < length; i++) {
var entry = e.dataTransfer.items[i].webkitGetAsEntry();
var file = e.dataTransfer.files[i];
@iwek
iwek / html5-upload-part1
Created October 2, 2012 19:27
Drag and Drop HTML with JavaScript Event Handlers
<style>
body {text-align: center;}
#drag { border: 10px solid black; text-align: center; padding:20px; width: 500px; margin: auto; font-size: 40px; display: inline-block;}
#einput {width:400px;}
#output {margin:20px;}
#filesinput, #directoryinput, #zipinput {
visibility: collapse;
width: 0px;
}
#output img{