Skip to content

Instantly share code, notes, and snippets.

View mspanish's full-sized avatar

Stacey Reiman mspanish

View GitHub Profile
@hay
hay / dlcat.py
Created November 6, 2010 21:53
Download all images in a category on Wikimedia Commons. Requires pywikipedia
#!/usr/bin/python
# -*- coding: utf-8 -*-
# -cat:Images_from_Wiki_Loves_Monuments
import sys, os
# Set your path to pywikipedia here
sys.path.append("/Users/hay/htdocs/checkouts/pywikipedia/")
import wikipedia, config, pagegenerators
import urllib2, codecs
@ericchen
ericchen / keyup_delay.js
Created April 29, 2011 02:21
Jquery keyup delay
var delay = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
})();
$('input').keyup(function() {
@milligramme
milligramme / sort_layers_for_AI.js
Created June 22, 2011 08:45
for Illustrator Sorting Layers
#target "Illustrator"
/**
* sort layers (with sublayer)
*/
var doc = app.documents[0];
var lay = doc.layers;
var array_primary = [];
for (var i=0, iL=lay.length; i < iL ; i++) {
@scottmessinger
scottmessinger / walkthrough.js
Created July 27, 2011 17:26
Common Curriculum Knockout.js Walkthrough
// index.haml
$(function() {
App.init();
});
//application.js
var App = {
VMs : {
global : {
mainTemplate : ko.observable()
@freeeve
freeeve / colortest.html
Created August 20, 2011 00:38
A random color generator in javascript/jQuery. Just playing around.
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
var colortest = $("#colortest");
for (i = 1; i <= 300; i++) {
var c = genColor();
var newhtml = "<span style='font-family:\"Courier\",monospace;width:50px;height:30px;background-color:#" + c + "'>#" + c + "</span>";
colortest.html(colortest.html() + newhtml);
@andyburke
andyburke / facebook-photo-post-javascript.js
Created December 19, 2011 20:37
How to post a photo to Facebook from client-side Javascript
// This bit is important. It detects/adds XMLHttpRequest.sendAsBinary. Without this
// you cannot send image data as part of a multipart/form-data encoded request from
// Javascript. This implementation depends on Uint8Array, so if the browser doesn't
// support either XMLHttpRequest.sendAsBinary or Uint8Array, then you will need to
// find yet another way to implement this. (This is left as an exercise for the reader,
// but if you do it, please let me know and I'll integrate it.)
// from: http://stackoverflow.com/a/5303242/945521
if ( XMLHttpRequest.prototype.sendAsBinary === undefined ) {
@robnyman
robnyman / blob-filereader-localStorage.js
Last active April 21, 2024 08:32
Get file as a blob, read through FileReader and save in localStorage
// Getting a file through XMLHttpRequest as an arraybuffer and creating a Blob
var rhinoStorage = localStorage.getItem("rhino"),
rhino = document.getElementById("rhino");
if (rhinoStorage) {
// Reuse existing Data URL from localStorage
rhino.setAttribute("src", rhinoStorage);
}
else {
// Create XHR and FileReader objects
var xhr = new XMLHttpRequest(),
@droot
droot / use_async_if.js
Created February 26, 2012 17:01
Use of Async IF construct
/* function to detect if a box of given color is visible on screen or not */
is_box_visible = function(color) {
var selector;
selector = "." + color + "box:visible";
return $(selector).length > 0;
};
$.when(async_if(is_box_visible, 'green') /* green box is visible */,
async_if(is_box_visible, 'red') /* red box is visible */
).then(
@neuronix
neuronix / gist:2016071
Created March 11, 2012 11:20
Rendering dynamic parameters in a dust.js helper
// Handy function to render dynamic parameters in a dust.js helper
function renderParameter(name, chunk, context, bodies, params) {
if (params && params[name]) {
if (typeof params[name] === "function") {
var output = "";
chunk.tap(function (data) {
output += data;
return "";
}).render(params[name], context).untap();
return output;
@mxriverlynn
mxriverlynn / 1.js
Created March 28, 2012 14:26
composite views
// The recursive tree view
var TreeView = Backbone.Marionette.CompositeView.extend({
template: "#node-template",
tagName: "ul",
initialize: function(){
// grab the child collection from the parent model
// so that we can render the collection as children
// of this parent node