Skip to content

Instantly share code, notes, and snippets.

View isonno's full-sized avatar

J. Peterson isonno

View GitHub Profile
@isonno
isonno / test-server.py
Last active August 29, 2015 14:08
Simple python demo script for koding.com. Unlike their sample, it shows how to gather information from the incoming URL.
#!/usr/bin/python
import os, platform, sys, cgi, cgitb
cgitb.enable() # Make debug info available
def printBreak(msg):
print "</pre>\n" + msg + "\n<pre>"
def printEnv(var):
print var[0]
print " " + var[1] + ": " + os.getenv(var[1])
@isonno
isonno / deferredDemo.js
Created March 1, 2015 17:38
Demonstrate jQuery Deferred objects
/*
Documentation for <a href="http://learn.jquery.com/code-organization/deferreds/">jQuery Deferred</a> objects.
<p>
<div>
<button id="concur">Concurrent</button>
<button id="sequent">Sequential</button>
</div>
<p>
<div id="result">
</div>
@isonno
isonno / DrawSVG.js
Last active August 29, 2015 14:17
Sample JS code to parse SVG formatted path data (handles M,L,C & Z operations)
//
// Sample code for parsing SVG style coordinates.
//
/* Assumes HTML:
<div id="content" >
<canvas id="drawing">
</canvas>
</div>
*/
@isonno
isonno / PSMinText.jsx
Created April 28, 2015 22:48
Sample code for creating a text layer in Photoshop using raw PS events
const kfontNameStr = app.stringIDToTypeID("fontName");
const kfontPostScriptNameStr = app.stringIDToTypeID("fontPostScriptName");
const kfontStyleNameStr = app.stringIDToTypeID("fontStyleName");
const kfromStr = app.stringIDToTypeID("from");
const khorizontalStr = app.stringIDToTypeID("horizontal");
const kmakeStr = app.stringIDToTypeID("make");
const kmodalToolChangeKindPaint = app.stringIDToTypeID("paint");
const knullStr = app.stringIDToTypeID("null");
const kpercentUnitStr = app.stringIDToTypeID("percentUnit");
const kpointsUnitStr = app.stringIDToTypeID("pointsUnit");
@isonno
isonno / VectorBoundsMask.js
Last active November 3, 2015 23:20
Sample DS code for creating a vector mask
//
// Code sample for creating a rectangular vector mask
// around the target paint layer. J. Peterson
//
function getLayerBounds()
{
var p = new Promise(function(resolve, reject)
{
_spaces.ps.descriptor.get({_ref:[{"_ref":"property","_property":"bounds"},
@isonno
isonno / VectorBoundsMask2.js
Last active November 3, 2015 23:09
VectorBoundsMask using BatchPlay
//
// Code sample for creating a rectangular vector mask
// around the target paint layer. J. Peterson
//
function getLayerBounds()
{
var p = new Promise(function(resolve, reject)
{
_spaces.ps.descriptor.get({_ref:[{"_ref":"property","_property":"bounds"},
@isonno
isonno / GeneratorToggle.js
Last active August 29, 2015 14:27
Sample code to enable/disable from DesignSpace JavaScript
//
// Sample code to enable/disable Generator from DesignSpace JavaScript
// J. Peterson aug-'15
//
// Reference to the generator keys
function appRef(key)
{ // either generatorStatus or pluginPicker
return {"_ref":[{"_ref":"property","_property":key},
{"_ref":"application","_enum":"ordinal",
@isonno
isonno / layerBounds.js
Last active November 3, 2015 23:16
Demo code for retrieving layer bounds un-clipped by the vectorMask
//
// Sample code to retrieve the bounds of the layer's vector mask, and
// also get the unclipped bounds of the mask by temporarily disabling the
// vector mask.
//
// Get attribute from the active layer.
// Records the requested result in "state".
function promiseLayerGet(resultKey, state)
{
@isonno
isonno / ShapeToVectorMask.js
Last active December 2, 2015 23:00
Sample Spaces code to convert a shape layer to a vector mask.
// Take a shape specified by clipShapeID, and use it to
// create a vectorMask for layer clippedLayerID.
// Shape layer is deleted.
function createMaskFromShape(clipShapeID, clippedLayerID)
{
var clipShapeDesc = {"null":{"_ref":[{"_ref":"layer","_id":clipShapeID}]}};
var clippedLayerDesc = {"null":{"_ref":[{"_ref":"layer","_id":clippedLayerID}]}};
var vecMaskRef = {"_ref":"path","_enum":"path","_value":"vectorMask"};
@isonno
isonno / moveMaskFrom.js
Created December 22, 2015 23:05
Copy a vector mask from a shape to another (non-shape) layer.
//
// Copy the vector mask from a shape to another layer.
// This takes layer names, modify as indicated below to take
// layer ID's instead.
// The shape is not deleted or modified.
function createMaskFromShape(srcShapeName, layerToClip)
{
srcLayerRef = {"_ref":"layer","_name":srcShapeName}; // Replace "_name" with "_id"
dstLayerRef = {"_ref":"layer","_name":layerToClip}; // to use layer ID's instead.