Skip to content

Instantly share code, notes, and snippets.

@cmawhorter
cmawhorter / cors-xhr-html.js
Created October 20, 2014 22:31
CORS XHR request of remote HTML with credentials, using jquery
// Description: This details how to make a CORS XHR request to a remote HTML resource with credentials, using jquery
// Origin website: https://www.origin.example/hello.html
// Remote resource: https://www.remote.example/world.html
// You can test this locally by configuring your local web server to allow cross origin requests from
// google.com. Then you can run the snippet below in devtools from the google homepage.
// Remote resource prerequisites:
//
REM What is the working directory of this script?
REM Reports will be relative to that.
if not exist reports echo "no" && mkdir reports
cd reports
type nul > report.xml
REM this is probably the source of your problem
REM echo ^<?xml version="1.0" encoding="UTF-8"?> >> report.xml
<div class="row">
<div class="col">8/27 9:21 AM</div>
<!-- calculateHeight(...) returns something like '112px' -->
<div class="col" ng-style="{ height: calculateHeight(statusStart, statusStop) }">
Prep Name (Prep)
Screens Burned
</div>
<div class="col">
<!-- placeholder for sub-status changes, like printing statuses -->
</div>
@cmawhorter
cmawhorter / tiptop-overloads.js
Created August 12, 2014 01:56
All the joy of loose typing, combined with a little more strictness
// Playing with overloads and stricter typing in JS -- https://github.com/cmawhorter/tiptop
var fn = require('../lib/tiptop');
function MyObj() {
}
MyObj.prototype.save = fn.overloaded(
function() {
@cmawhorter
cmawhorter / convert-to-svg.bat
Last active August 29, 2015 14:03
Converts all (vector) files in a directory to svg using ps2pdf, uniconvertor and inkscape.
@echo off
REM This will fail with "the input line is too long" if you have a lot of files... maybe?
REM Don't know why, but I think the solution is breaking the body of the for () into a separate
REM batch. But... IDGAF.
echo Starting...
for %%i in (*.*) do (
echo Looking at... %%~di%%~pi%%~ni%%~xi
@cmawhorter
cmawhorter / async-download.js
Created July 10, 2014 18:32
Downloads all files in an array 2 at a time
var fs = require('fs');
var path = require('path');
var async = require('async');
var request = require('request');
var tasks = {};
var json = { /* your records */ };
@cmawhorter
cmawhorter / grunt-build.bat
Last active April 19, 2016 13:30
Script to build grunt/yeoman project from jenkins on windows 7
@echo off
REM You may need to add `cd %WORKSPACE%` in the jenkins project prior to
REM calling this script. I have it in mine and didn't test without.
REM Correct paths to respective applications as-needed
SET PATH=%PATH%;C:\Program Files (x86)\nodejs;C:\Program Files (x86)\Git\bin;%AppData%\npm;C:\Ruby200-x64\bin
echo Installing or updating bower...
@cmawhorter
cmawhorter / proxy.js
Created June 26, 2014 05:36
Node script to forward all http requests to another server and return the response with an access-control-allow-origin header. Follows redirects.
// Simple proxy/forwarding server for when you don't want to have to add CORS during development.
// Usage: node proxy.js
// Open browser and navigate to http://localhost:9100/[url]
// Example: http://localhost:9100/http://www.google.com
// This is *NOT* for anything outside local development. It has zero error handling among other glaring problems.
// This started as code I grabbed from this SO question: http://stackoverflow.com/a/13472952/670023
@cmawhorter
cmawhorter / fabricjs-thumbnail.js
Created June 26, 2014 04:54
The only way I could generate real-time thumbnails of a fabricjs canvas
// see mawhorter.net for full post
// Put this in an after:render event handler.
// Be warned: Ripped out of working code and renamed variables without testing.
var fabricMain = new fabric.Canvas('main')
, fabricThumb = new fabric.Canvas('screenshot')
, ctxThumbnail = $('canvas#thumbnail')[0].getContext('2d');
<?php
// Stampr API - Create a Batch for Testing
require 'vendor/autoload.php';
require 'src/Stampr/Stampr.php';
$stampr_login = "[email protected]";
$stampr_password = "your.stampr.password";
$endpoint = "https://stam.pr/api";