Skip to content

Instantly share code, notes, and snippets.

@iwek
iwek / cookies.js
Created July 17, 2012 14:31
view and disable cookies in casperjs and phantomjs
//to disable cookies, run casperjs --cookies-file=/dev/null? cookies.js
var casper = require('casper').create();
casper.start('http://wordpress.org/', function() {
this.echo('Browser Cookie: ' + this.evaluate(function() {
return document.cookie;
}));
});
@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 / 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 / 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 / js-closure-better-example.js
Created January 20, 2013 05:33
JavaScript Better Closure Example
function one(y) {
var z = 1;
return function g(y) {
var all = y + z;
return all;
}
}
var z=10;
var b = one();
function two(t){
@iwek
iwek / js-variables-and-scope.js
Last active December 11, 2015 10:28
JavaScript Variables and Scope
v1 = 1; // Global Scope
var v2 = 2; // Variable defined with var keyword but not within a function: Global Scope
function f() {
v3 = 3; // No var keyword: Global Scope
var v4 = 4; // Local Scope only
var v5 = v1+v2+v3; //1+2+3=6 - Local Scope only, can access v1 and v2 variables from the Global Scope
}
v1; //1 - JavaScript can access the variable as it lives in the Global Scope
@iwek
iwek / pinterest-2.js
Last active December 14, 2015 13:19
Organize or Sort Pinterest Images by Repins
//cleanup and sort elemets that have repins
//grab all pins
var mylist = $('.Pin');
//find all pins that have repins
var listitems = mylist.find('.socialItem');
var list = listitems.filter(function(f,i){
var test = Number( $(i).text().trim().replace("repins", "").replace("repin", "") );
if(test>0){
@iwek
iwek / pinterest-3.js
Last active December 14, 2015 13:19
Show the sorted images on Pinterest
//empty main section
$(".Grid").before('<div id="organized"/>').remove();
//append sorted items
$.each(list, function(idx, itm) {
$("#organized").append($(itm).parents('.Pin'));
});
//style it up
$('.Pin').css({'clear': 'both', 'position': 'static'});