Skip to content

Instantly share code, notes, and snippets.

@iwek
iwek / nodejs-curl-bad.js
Created August 31, 2012 20:09
Incorrect example of curl with nodejs
var fs = require('fs');
var request = require('request');
var urls = new Array("http://www.yahoo.com","http://www.bing.com");
for (var i = 0; i < urls.length; i++) {
var file = 'log'+[i]+'.txt';
var url = urls[i];
@iwek
iwek / curl-nodejs.js
Created August 31, 2012 20:13
Corrent example of curl with NodeJS
var fs = require('fs');
var request = require('request');
var urls = new Array("http://www.yahoo.com","http://www.bing.com");
function scrape(url,file){
request(url, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log('request url: '+url);
@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{
@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 / 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 / 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 / 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 / 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 / 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 / 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/"
>