Skip to content

Instantly share code, notes, and snippets.

@penguinboy
penguinboy / Object Flatten
Created January 2, 2011 01:55
Flatten javascript objects into a single-depth object
var flattenObject = function(ob) {
var toReturn = {};
for (var i in ob) {
if (!ob.hasOwnProperty(i)) continue;
if ((typeof ob[i]) == 'object') {
var flatObject = flattenObject(ob[i]);
for (var x in flatObject) {
if (!flatObject.hasOwnProperty(x)) continue;
@cobyism
cobyism / gh-pages-deploy.md
Last active November 19, 2024 09:32
Deploy to `gh-pages` from a `dist` folder on the master branch. Useful for use with [yeoman](http://yeoman.io).

Deploying a subfolder to GitHub Pages

Sometimes you want to have a subdirectory on the master branch be the root directory of a repository’s gh-pages branch. This is useful for things like sites developed with Yeoman, or if you have a Jekyll site contained in the master branch alongside the rest of your code.

For the sake of this example, let’s pretend the subfolder containing your site is named dist.

Step 1

Remove the dist directory from the project’s .gitignore file (it’s ignored by default by Yeoman).

// The only difference between a stub and a spy is this:
// - a spy wraps existing function and allows you to assert against its behavior
// - a stub replaces an existing function and allows you to assert against its behavior
// This creates a normal function that can be invoked.
const spy = sandbox.spy();
// Do something with it... and then you can make assertions against it later.
expect(spy).to.have.been.calledOnce;
// This wraps `someObject.someMethod` in another function. After wrapping,