Skip to content

Instantly share code, notes, and snippets.

View shrunyan's full-sized avatar

Stuart Runyan shrunyan

View GitHub Profile
@shrunyan
shrunyan / index.js
Created November 20, 2019 00:18
Proof case for unexpected 404 responses
// This test ensures there is no render gap between when a page is published and made available.
// Specifically we expect to get a 200 response (vs 404) immediately, within milliseconds, after a page is published.
// We will prove this by making a request to site-engine every X milliseconds and then triggering a publish
// At no time should we recieve a 404 response
const ZESTY_INSTANCE_DOMAIN = "http://zesty.pw/";
const ZESTY_USER_EMAIL = "";
const ZESTY_USER_PASSWORD = "";
const ZESTY_INSTANCE_ZUID = "8-f48cf3a682-7fthvk";
@shrunyan
shrunyan / tracker.js
Created June 26, 2014 16:55
Google analytics tracking augmentation.
jQuery(document).ready(function ($) {
/* <a> TAG TRACKER
* @Version: 0.0.2
* @Author: Stuart Runyan
* @Documentation: http://code.google.com/apis/analytics/docs/tracking/eventTrackerGuide.html
* @trackList: Add all domains that you want to track as "internal".
* Allow regular expressions
* It is not neccessary to include the domain this code resides on.
* If the active domain is include in the list there are checks to insure
* we don't double track.
@shrunyan
shrunyan / get-all-url-parameters.js
Last active May 21, 2018 11:10
Javascript function which returns an Array of all URL parameters.
/**
* Returns an Array of all url parameters
* @return {[Array]} [Key Value pairs form URL]
*/
function getAllUrlParams() {
var keyPairs = [],
params = window.location.search.substring(1).split('&');
for (var i = params.length - 1; i >= 0; i--) {
keyPairs.push(params[i].split('='));
};
@shrunyan
shrunyan / index.js
Created March 21, 2018 17:20
Take screenshots of urls. Inspired by https://meowni.ca/posts/2017-puppeteer-tests/
const puppeteer = require('puppeteer')
const express = require('express')
const querystring = require('querystring')
const server = express()
/**
* Screenshot a url
* e.g. /screenshot?url=https://www.npmjs.com&width=800&height=600
*/
server.get('/screenshot', async (req, res) => {
@shrunyan
shrunyan / prestart.js
Created February 6, 2017 19:55
npm prestart script for triggering sub-app builds
// @see https://strongloop.com/strongblog/modular-node-js-express/
var fs = require('fs')
var resolve = require('path').resolve
var join = require('path').join
var cp = require('child_process')
// get library path
var src = resolve(__dirname, '../src/')
@shrunyan
shrunyan / app.js
Last active January 7, 2017 14:40
Example Gulp build for Riotjs + ES6 + Browserify + Babelify + Riotify
import './app.tag'
riot.mount('#app', 'app')
@shrunyan
shrunyan / pipeline.js
Last active August 26, 2016 22:05
Streaming pipeline for requesting, modifying and uploading an image.
'use strict'
var http = require('http')
var request = require('request')
var gm = require('gm')
var fs = require('fs')
var FormData = require('form-data')
let r1 = request('https://upload.wikimedia.org/wikipedia/commons/e/eb/Ash_Tree_-_geograph.org.uk_-_590710.jpg')
@shrunyan
shrunyan / sniff.js
Created August 26, 2016 20:59
Node.js module to sniff the bytes from a stream for mimetype detection
'use strict'
import stream from 'stream'
export default function sniff(rs, sniffLength = 16384) {
return new Promise((resolve, reject) => {
let buffer = Buffer.from([])
let ws = new stream.Writable()
@shrunyan
shrunyan / dropbox-form-upload.js
Last active August 7, 2016 22:42
Example xhr request to post file from form to dropbox
<form action="/" method="post" name="newsletter">
<input type="text" name="first_name" value="stuart" />
<input type="file" id="resume" />
<input type="hidden" id="dropbox" />
<input type="hidden" name="zlf" value="1" />
<button type="submit">Submit</button>
</form>
<script>
document.forms.newsletter.addEventListener('submit', function cb(evt) {
evt.preventDefault()
@shrunyan
shrunyan / index.js
Created May 14, 2016 20:11 — forked from anonymous/index.js
Experimenting with Koajs and the Spotify api
'use strict'
const koa = require('koa')
const r = require('koa-route')
const https = require('https')
const app = koa()
app.use(r.get('/search/:term', function *(term) {
const req = https.request({
method: 'get',