Skip to content

Instantly share code, notes, and snippets.

@zaus
zaus / parse-hash-bang-arguments-in-javascript.js
Last active December 15, 2015 04:29 — forked from miohtama/parse-hash-bang-arguments-in-javascript.js
Parse "hashbang" `#!` arguments like url query-string. [original source](https://gist.github.com/miohtama/1570295)
/**
* Parse hash bang parameters from a URL as key value object.
* For repeated parameters the last parameter is effective.
* If = syntax is not used the value is set to null.
* #!x&y=3 -> { x:null, y:3 }
* @param url URL to parse or null if window.location is used
* @return Object of key -> value mappings.
* @source https://gist.github.com/zaus/5201739
*/
function hashbang(url, i, hash) {
@zaus
zaus / jquery.removeClassWhere.js
Created March 22, 2013 13:30
The missing jQuery function to easily remove classes matching a filter -- combines `$el.removeClass` and `$.grep`.
$.fn.removeClassWhere = function (filter) {
/// <summary>
/// Remove classes matching a filter fn(class, index_in_list) -- combines .removeClass and .grep
/// <example>$('.things').removeClassWhere(function (cl) { return -1 != cl.indexOf(matches); });</example>
/// </summary>
return $(this).removeClass(function (i, classes) {
return $.grep(classes.split(' '), filter).join(' ');
});
};//-- fn removeClassWhere
@zaus
zaus / index.html
Created June 20, 2013 13:12
Nice complementary colors. A #CodePen by JB Price.
<div class="box red"></div>
<div class="box orange"></div>
<div class="box yellow"></div>
<div class="box green"></div>
<div class="box teal"></div>
<div class="box blue"></div>
<div class="box purple"></div>
<div class="box pink"></div>
@zaus
zaus / text-input-love.html
Last active December 20, 2015 20:49
A CodePen by Michael Arestad. Text input love - I wanted to play with some input styles that don't rely on hover, don't add clutter, show the label at all times, and show placeholder text when it is actually relevant.
<div class="row">
<p>Click every input.</p>
</div>
<div class="row">
<span>
<input class="basic-slide" id="name" type="text" placeholder="Your best name" /><label for="name">Name</label>
</span>
<span>
<input class="basic-slide" id="email" type="text" placeholder="Your favorite email" /><label for="email">Email</label>
</span>
@zaus
zaus / ExtensionMethods.cs
Created October 8, 2013 13:37
Comparing results of Nested Property/Field extraction via Reflection or Expression Tree; testing in LinqPad -- from http://stackoverflow.com/questions/536932/how-to-create-expression-tree-lambda-for-a-deep-property-from-a-string
public static class ObjectExtensions {
public static object ReflectValue(this object o, string path) {
// http://stackoverflow.com/a/4474015/1037948
return path.Split('.').Aggregate(o, (current, component) => {
var property = current.GetType().GetProperty(component);
if(null == property) {
var field = current.GetType().GetField(component);
if(null == field) return null;
return field.GetValue(current);
}
@zaus
zaus / Platform-game-engine.markdown
Created December 12, 2013 16:27
A Pen by suffick.

Platform game engine

A simple platform game engine, the map is customisable and scriptable. Refer to the comments in the "map" variable for instructions.

I plan to expand the engine in the future, the ability to use images for tiles and the player is one thing that I have in mind. Any suggestions are welcome.

A Pen by suffick on CodePen.

License.

@zaus
zaus / Random-Maze-Generator.markdown
Created December 18, 2013 14:42
A Pen by Gabriel Valfridsson.

Random Maze Generator

Generating a maze with a simple algorithm

  1. Find available directions
  2. pick one at random
  3. if no available directions, backtrack to last position loop step 1 to 3 until back at start location

A Pen by Gabriel Valfridsson on CodePen.

@zaus
zaus / compObj.js
Last active January 18, 2016 16:36
Simple javascript comparison of two objects with console logging/warning when different
/**
* Compare versions of objects and warn of differences
* @param {object} v1 variant 1
* @param {object} v2 variant 2
* @param {bool} stringify optionally (if provided and `true`) stringify the variant parameters when dumping
* @param {string} root [internal use] nested key placeholder
* @example <caption>Example comparing two things:</caption>
* // should result in warnings for 'foo' and 'somebool'
* compObj({foo: "bar", id: 123, somebool: true}, {bar: "foo", id: 123, somebool: 'true'});
* @returns {void} nothing -- see console logging
void Main()
{
var headers = new System.Net.WebHeaderCollection();
headers.Add("xxx", "yyy");
headers.Add("zzz", "f&&ff");
headers.Add("xxx", "ttt");
headers.Add("yyy", "33,3");
headers.Dump("raw");
headers.ToString().Dump("string'd");