Skip to content

Instantly share code, notes, and snippets.

@prantlf
prantlf / jquery.parseParams.js
Last active September 2, 2018 00:12
Reverses the $.param effect - parses the URL query part into an object
// jQuery.parseParams 0.1.0
// https://gist.github.com/prantlf/061e3911cd450491f84aac40292b7e7c
//
// Copyright (c) 2015-2017 Ferdinand Prantl
// Licensed under the MIT license.
//
// Reverses the $.param effect - parses the URL query part into an object
// with parameter names as keys pointing to parameter values; normalizes
// all parameter names to lower-case and saves multiple parameters with
// the same name to arrays
@prantlf
prantlf / require.config.js
Last active September 2, 2018 00:12
Loads JSON file, parses it to an object and passes it to require.config
// Loads JSON file, parses it to an object and passes it to require.config
//
// https://gist.github.com/prantlf/a7972320307580573eb715ed65e85a2b
// Copyright (c) 2016 Ferdinand Prantl
// Licensed under the MIT license.
//
// If you have a couple of pages and apply the same RequireJS configuration
// on them, you would like to maintain the configuration content at a single
// place. You could put the require.config statement to a script file and
// load it on the page by the script element before your main application
@prantlf
prantlf / deepClone.js
Last active September 2, 2018 00:12
JavaScript deepClone + integration to Undescore.js and Backbone.js
// Performs a deep clone of primitive values, arrays, object literals,
// and arbitrary objects, if requested. It is supposed to clone object
// literals, which are going to be modified, but the original should
// stay intact.
//
// The default behaviour works well with JSON REST API responses and
// and other objects, which contain only values of native types.
// If functions or HTML elements are encountered, they will not be
// actually cloned; they will be just copied, which works well with
// the typical options objects for Backbone constructors.
@prantlf
prantlf / Northwind.js
Last active September 2, 2018 00:12
Helps obtaining and using a local copy of the Northwind database in MongoDB and testing an OData server with JayData
// Northwind database schema for JayData
//
// Initially generated by JaySvcUtil on 2014/07/27
// using http://services.odata.org/Northwind/Northwind.svc/$metadata
//
// Sample usage with a local Northwind database, which you can get
// by running northwind-create.js with mongodb, for example:
//
// var context = new NorthwindContext({
// name: 'mongoDB',
@prantlf
prantlf / jasmine.toBeInstanceOf.js
Last active September 2, 2018 00:12
A Jasmine matcher checking if the actual object is an instance of the expected type
// Checks if the actual object is an instance of the expected type;
// the functional object `expected` can be any ancestor prototype.
//
// Example:
// expects(new Backbone.Model()).toBeInstanceOf(Backbone.Model);
jasmine.Matchers.prototype.toBeInstanceOf = function(expected) {
var actual = this.actual,
notText = this.isNot ? ' not' : '';
this.message = function() {
return 'Expected ' + actual + notText + ' to be an instance of ' + expected;
@prantlf
prantlf / jasmine.toBeTypeOf.js
Last active September 2, 2018 00:13 — forked from adamyanalunas/jasmine.toBeTypeOf.js
A Jasmine matcher checking if the actual object is of the expected type
// Checks if the actual object is of the expected type;
// the string `expected` is handled case-insensitively.
//
// Example:
// expects(123).toBeTypeOf("Number");
jasmine.Matchers.prototype.toBeTypeOf = function(expected) {
var actual = this.actual,
notText = this.isNot ? ' not' : '',
objType = actual ? Object.prototype.toString.call(actual) : '';
this.message = function() {
/**
* beautify_oscript.lxe - A code beautifier for OpenText Content Server OScript
*
* This script will beautify your OScript. Copy to a file within opentext/scripts/
* (e.g., opentext/scripts/beautify_oscript.lxe), restart Builder, place the focus on a
* script window, and run from the Tools menu.
*
* Some coding conventions assumed. Use at your own risk.
*
* Christopher Meyer (chris@schwiiz.org)
@prantlf
prantlf / Mac OSX Setup - Brew
Created November 15, 2018 18:02 — forked from jbelke/Mac OSX Setup - Brew
Mac OSX Setup - Brew and Cask
# Get Sudo.
if [ $EUID != 0 ]; then
sudo "$0" "$@"
exit $?
fi
# Install Xcode first - https://itunes.apple.com/us/app/xcode/id497799835?ls=1&mt=12
# Install Xcode command line tools.
xcode-select --install
@prantlf
prantlf / install_ruby_with_rbenv.md
Last active December 3, 2018 16:23 — forked from stonehippo/install_ruby_with_rbenv.md
Installing a new Ruby with rbenv on Mac OS

Install a new Ruby with rbenv on Mac OS (and make yourself a superhero)

If you're doing stuff with Ruby on a Mac, e.g. installling Jekyll or something, by default you'll end up having to use the sudo command to do stuff, since the permission to modify the default config is not available to your user account.

This sucks and should be avoided. Here's how to fix that.

Installing a new Ruby

To make this better, we are going install a new, custom Ruby. This used to be a big, scary thing, but thanks to the awesome tools Homebrew and rbenv, it's a snap.*

A word of warning: you will have to use Terminal to install this stuff. If you are uncomfortable with text, words, and doing stuff with your computer beyond pointing and hoping, this may not work well for you. But if that's the case, I'm not sure why you were trying to use Ruby in the first place.

@prantlf
prantlf / color-conversion-algorithms.js
Created February 25, 2019 01:12 — forked from mjackson/color-conversion-algorithms.js
RGB, HSV, and HSL color conversion algorithms in JavaScript
/**
* Converts an RGB color value to HSL. Conversion formula
* adapted from http://en.wikipedia.org/wiki/HSL_color_space.
* Assumes r, g, and b are contained in the set [0, 255] and
* returns h, s, and l in the set [0, 1].
*
* @param Number r The red color value
* @param Number g The green color value
* @param Number b The blue color value
* @return Array The HSL representation