Skip to content

Instantly share code, notes, and snippets.

@anotheredward
anotheredward / synth
Last active August 29, 2015 14:16
List of constants for use with http://studio.substack.net
var otomata = [ 220, 233, 261, 293, 330, 349, 440, 523 ];
var harmonicMinotaur = [ 262, 293, 311, 349, 391 ];
var majorPentatonic = [ 262, 293, 329, 391, 440 ];
var C0 =16.35,
Cs0=17.32,
D0 =18.35,
Ds0=19.45,
E0 =20.60,
F0 =21.83,
@anotheredward
anotheredward / gist:ebbe30c6c2ac8cba0703
Created April 21, 2015 05:47
Functional Programming Exercise
//Copy this over the contents at tddbin.com
//Replace the [] in the assert statements with a functional equivalant
//Reference here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
//Lambda syntax: (x,y) => x + y, works in firefox, try it out :)
function range(start, end, jump) {
jump = jump || 1
if (start && !end)
return actualRange(0, start, jump)
return actualRange(start, end, jump)
@anotheredward
anotheredward / importFromLoopback.js
Created June 22, 2015 22:12
Creates an Ember model body from a loopback json model
var fs = require('fs')
function printFormat(key) {
console.log(key + ": attr('" + model.properties[key].type + "'),")
}
var model = JSON.parse(fs.readFileSync(process.argv[2], {encoding: 'ascii'}))
Object.keys(model.properties).map(printFormat)
@anotheredward
anotheredward / checklist.html
Created October 12, 2015 03:07
Starting point for a Code Review checklist
<h2>Code Review Checklist</h2>
<input type="checkbox"> Read Ticket <br>
<input type="checkbox"> Works from clean install <br>
<input type="checkbox"> Test Functionality: Does it solve the problem/satisfy the AC? <br>
<input type="checkbox"> Green path <br>
<input type="checkbox"> Red path <br>
<hr>
<p>Look for</p>
<input type="checkbox"> Errors in inspector <br>
@anotheredward
anotheredward / checkout.sh
Created November 22, 2015 19:21
checkout.sh
#! /usr/local/bin/zsh
vagrant up
npm prune
npm install
npm run migrate:down && npm run migrate:up
cd client
npm prune
npm install
@anotheredward
anotheredward / inputvalidation.md
Last active April 11, 2019 19:35
Input Validation Cheatsheet

1 SQL Injection

  • Search the codebase for "select", see if the queries are joined together with user input by + or string interpolation eg: `Name: ${user.name}`
  • Fix: Parameterized queries or replace with ORM queries

2 Cross-site Scripting (XSS)

  • Search the codebase for "{{{", if you see anywhere where the user input is displayed inside {{{ tags, it's probably vulnerable to XSS
  • Fix: Either remove {{{ tags or add sanitization if that's not possible
  • XSS Can also occur when creating elements with Javascript
  • XSS: Try pasting in one of the below XSS polyglots, and then inspecting the response to see if any tags got through:
@anotheredward
anotheredward / swaggerScan.js
Created July 10, 2016 22:49
Script for hitting all of the endpoints of a swagger API exposed by a Loopback Application
// Download swagger.json from /explorer/swagger.json
'use strict'
const api = require('./swagger.json')
const rp = require('request-promise')
const apiUrl = 'http://something.com/api'
let requests = []
for (let path of Object.keys(api.paths)) {
for (let method of Object.keys(api.paths[path])) {
@anotheredward
anotheredward / package.js
Last active August 29, 2016 02:43
get license, name, homepage of all direct npm dependencies script
'use strict'
// Prints the license, name and homepage of every top-level npm package
const fs = require('fs')
const folders = fs.readdirSync('node_modules')
const paths = folders.map(folder => 'node_modules/' + folder)
const directoryPaths = paths.filter(path => fs.statSync(path).isDirectory())
const packagePaths = directoryPaths.map(path => `${path}/package.json`)
const existingPackagePaths = packagePaths.filter(path => fs.existsSync(path))
const packageFiles = existingPackagePaths.map(path => fs.readFileSync(path))
@anotheredward
anotheredward / roguelike.html
Created July 27, 2016 23:08
11 Minute Roguelike
<pre id="maze"></pre>
<script>
'use strict'
const maze = [
'#####',
'#@..#',
'###.#',
'#...#',
'#.#####',
'#.#...###',
@anotheredward
anotheredward / rl.html
Last active August 2, 2016 03:12
CHCH.js Roguelike
<pre id="maze"></pre>
<script>
//Why a roguelike?
//A RL is a sweetspot between effort vs. new features
//You get something awesome every 5 LoC or even just by tweaking a single variable, and this makes it fun to program
//What's exciting about JS is that you can make something you can see in a browser, fast, and then share it with everyone
//JS being a simple to understand, practical, and easy to share language has helped it develop an awesome community
//Things to tweak
//Try adding a ghost trail to the player by not replacing their last position with a .
//Try making an AI that moves randomly, that moves towards the player, that runs away from the player (like tag)