Skip to content

Instantly share code, notes, and snippets.

View kriscooke's full-sized avatar

kriscooke

  • British Columbia, Canada
View GitHub Profile
@kriscooke
kriscooke / github-pages-101.md
Last active February 21, 2021 17:53
GitHub Pages 101 aka. free hosting for all your public demos

GitHub Pages, aka. free hosting for all your public demos:

Without your writing any webserver code, GitHub can recognize specifically-named repos/branches and will serve a static page (including HTML/CSS/JS and other static files) at a certain GitHub-based URL. This means free hosting for your public demos, and makes it really easy to host a doc/demo site associated with each of your repositories. You can even set it up with a custom domain.

User Page (or Organization)

  • Accessible at: yourusername.github.io
  • GitHub automatically reserves this URL for every user and organization to use as their User page, although nothing is published there until you publish.
  • To deploy a static site to this URL:
    1. Create a Github repo with the exact name: yourusername.github.io
  1. Commit an index.html in the root folder to the master branch and push. (From the index page you can link to other folders/files as usual)
const path = require('path');
const gulp = require('gulp');
const del = require('del');
const gulpif = require('gulp-if');
const uglify = require('gulp-uglify');
const htmlMinifier = require('gulp-html-minifier');
const mergeStream = require('merge-stream');
const polymer = require('polymer-build');
'use strict';
@kriscooke
kriscooke / git-mv-with-history
Created May 6, 2016 01:10 — forked from emiller/git-mv-with-history
git utility to move/rename file or folder and retain history with it.
#!/bin/bash
#
# git-mv-with-history -- move/rename file or folder, with history.
#
# Moving a file in git doesn't track history, so the purpose of this
# utility is best explained from the kernel wiki:
#
# Git has a rename command git mv, but that is just for convenience.
# The effect is indistinguishable from removing the file and adding another
# with different name and the same content.
@kriscooke
kriscooke / descriptor.json
Created April 22, 2016 02:14
Example hydrolysis descriptor of a paper-dialog element
"{"type":"element","desc":"\nMaterial design: [Dialogs](https://www.google.com/design/spec/components/dialogs.html)\n\n`<paper-dialog>` is a dialog with Material Design styling and optional animations when it is\nopened or closed. It provides styles for a header, content area, and an action area for buttons.\nYou can use the `<paper-dialog-scrollable>` element (in its own repository) if you need a scrolling\ncontent area. See `Polymer.PaperDialogBehavior` for specifics.\n\nFor example, the following code implements a dialog with a header, scrolling content area and\nbuttons.\n\n <paper-dialog>\n <h2>Header</h2>\n <paper-dialog-scrollable>\n Lorem ipsum...\n </paper-dialog-scrollable>\n <div class=\"buttons\">\n <paper-button dialog-dismiss>Cancel</paper-button>\n <paper-button dialog-confirm>Accept</paper-button>\n </div>\n </paper-dialog>\n\n### Styling\n\nSee the docs for `Polymer.PaperDialogBehavior` for the custom properties available for styling\nthis e
@kriscooke
kriscooke / $_data.js
Created April 20, 2015 23:01
Updating data-attributes using jQuery plugins or $.data(): If updating a DOM element's data-attributes directly, do NOT expect the jQuery .data() method to reference the updated data-attribute. Instead, it stores an object in memory based on the initial value of the data-attribute (a string) and references that SAME object with every $item.data(…
// Original DOM element:
// <div id="item" data-tags="popcorn,chickens"></div>
// SET (for eg: based on an ajax response):
// The first call (with .attr) updates the DOM element only:
$item.attr('data-tags',response.tag); // "popcorn,chickens"
$item.attr('data-tags'); // "popcorn,chickens,dandelions"
// <div id="item" data-tag="popcorn,chickens,dandelions"></div>
$item.data('tags',response.tag); // [popcorn,chickens]
@kriscooke
kriscooke / 0_reuse_code.js
Last active August 29, 2015 14:19
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@kriscooke
kriscooke / gist:574ac5f3c218c3b0c1ce
Created April 6, 2015 16:26
Reversing an array (replace Array.prototype.reverse())
Array.prototype.reverse = function() {
// .splice(0) Empties out the entire array and returns the removed elements to arr.
// (Uses deleteCount = Array.length)
var arr = this.splice(0);
// While arr.length is not falsy (arr.length > 0)
// Pop off the end of arr, and push it back into the empty "this" array:
while(arr.length) {
this.push(arr.pop());
}
@kriscooke
kriscooke / gist:d410500df32a6e2ed6f6
Created April 4, 2015 22:42
Manufacture a string of specified length with a preset repeat value
String.prototype.repeat = function(count) {
return new Array(count+1).join(this);
};
@kriscooke
kriscooke / gist:8863c0aaf0f2fce1a957
Last active August 29, 2015 14:18
JS: Validate/Coerce arguments object to an array
function needsArray(a){
var args = Array.isArray(a)? a : Array.prototype.slice.call(arguments);
// Now, use args as an array
}

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000