Skip to content

Instantly share code, notes, and snippets.

View mhseiden's full-sized avatar
🏗️

Max Seiden mhseiden

🏗️
View GitHub Profile
@mhseiden
mhseiden / NumberTemplate.cpp
Created February 5, 2012 04:09
Very Basic Number Template
template <typename T> class Number
{
public:
Number()
: data(0)
{ }
Number(const T& val)
: data(val)
{ }
@mhseiden
mhseiden / mdn_bind.js
Created February 9, 2012 18:54
Learning JavaScript's Bind | MDN's Implementation
if (!Function.prototype.bind) {
Function.prototype.bind = function (oThis) {
if (typeof this !== "function") {
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
}
var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function () {},
fBound = function () {
@mhseiden
mhseiden / HTTP-WS-Proxy.js
Created April 10, 2012 00:39
Lightweight "node-http-proxy" HTTP/WS Proxy Server
// Node Modules
////////////////////////////////////////////////////////////////////////////////
var http_m = require("http");
// 3rd Party Modules
////////////////////////////////////////////////////////////////////////////////
var http_proxy_m = require("http-proxy");
// Utilities
////////////////////////////////////////////////////////////////////////////////
@mhseiden
mhseiden / gist:2654497
Created May 10, 2012 17:07
One-liner #1
loc.tid = loc.ns ? ((opts.tid === 0) ? 0 : (opts.tid || "*")) : null;
@mhseiden
mhseiden / gist:4027452
Created November 6, 2012 20:52
Simple Shell Injection
# Not an immediate vector
touch ‘safe_file.txt$(echo “Shell Injection” > safe_file.txt)’
# Quite unsafe
touch “bad_file.txt$(echo “Shell Injection” > bad_file.txt)”
/**
* NOTE - I haven't compiled this, so there may be small errors.
* However, the concepts shown are correct.
*/
// In the *.h file
class MyClass;
class MyClass {
public:
@mhseiden
mhseiden / TypedObject.js
Created May 1, 2013 19:27
Version 1 a "typed object" implementation.
/**
Copyright (c) 2012 - Max Seiden <140dbs@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
@mhseiden
mhseiden / download_decode_downsample.js
Last active March 23, 2021 09:19
Downloading, Decoding, and Downsampling an Audio File with the WebAudio API
/**
* In this gist, assume that we're using Chrome, and the following variables are in scope and have already been assigned to the following:
*
* var url = "http://upload.wikimedia.org/wikipedia/commons/b/be/Toccata_et_Fugue_BWV565.ogg";
* var webaudio = new webkitAudioContext();
* var renderCallback = function renderCallback(data) { return "render!"; } // a function which will render the given audio data on a canvas
*/
// Fetch the data with an AJAX request
var xhr = new XMLHttpRequest();
function renderAudioData(canvas, data) {
// Grab handy variables with local names
var height = canvas.height;
var width = canvas.width;
var length = data.length;
var stepSize = width / length;
// Helper functions to make the index selection logic more readable further down
var xCoord = function(idx) { return stepSize * idx; };
var xNext = function(idx) { return xCoord(idx + 1); };
### Keybase proof
I hereby claim:
* I am mhseiden on github.
* I am mhs (https://keybase.io/mhs) on keybase.
* I have a public key whose fingerprint is EA16 953E 006D 61B9 B6AC 8A3A 1B5A EC10 D7A9 50E4
To claim this, I am signing this object: