Skip to content

Instantly share code, notes, and snippets.

View wholypantalones's full-sized avatar

Jason Dare wholypantalones

View GitHub Profile
@wholypantalones
wholypantalones / paramsToObject.js
Last active February 15, 2018 14:20
Convert params to object
var search = window.location.search // ?param1=value1&param2=value2
search?JSON.parse('{"' + search.replace(/\?/g, '').replace(/&/g, '","').replace(/=/g,'":"') + '"}',
function(key, value) { return key===""?value:decodeURIComponent(value) }):{};
@wholypantalones
wholypantalones / objectToParams.js
Created February 1, 2018 14:55
Convert object to params
/* params = {paramOne: '1', paramTwo: '2'} */
var str = Object.keys(params).map(function(key) {
return key + '=' + encodeURIComponent(params[key]);
}).join('&');
function getRandomColor() {
var letters = '012345'.split('');
var color = '#';
color += letters[Math.round(Math.random() * 5)];
letters = '0123456789ABCDEF'.split('');
for (var i = 0; i < 5; i++ ) {
color += letters[Math.round(Math.random() * 15)];
}
return color;
}
@wholypantalones
wholypantalones / ishtml5_storage_athing.js
Created August 28, 2017 14:37
Angular localStorage support run function
// usage
// var thisThing = localStores.getItem('this thing);
.run(function ($window) {
function supports_html5_storage() {
try {
return 'localStorage' in window && window['localStorage'] !== null;
} catch (e) {
return false;
}
'use strict';
/* config provide */
/* ignores unhandled rejection for cancelled in Angular 1.6 */
/* */
/* http requests middleware service */
/* if no groupingId is specified, each req is a duplicate by default */
/* usage: */
/* httpQueueService.add(useThisFunction, {timeout: 1000, groupingId:'myCustomQueue'}); */
/* usage with params: */
/* httpQueueService.add(function(){updateCart(product,qty),{timeout:300, groupingId:'cart'}} */
@wholypantalones
wholypantalones / mdl-update.js
Last active June 13, 2017 19:35
Update Google Material Design Lite elements
function updateMDL() {
$timeout(function () {
componentHandler.upgradeAllRegistered();
}, 300);
}
var film = this.props.data.slice(0, 5).map((item) => {
return <FilmItem key={item.id} film={item} />
});
return film;
@wholypantalones
wholypantalones / ngFormCommit.js
Created January 25, 2017 20:15
Submit a form with angular directive
// usage:
// <form ng-form-commit action="/" name='payForm' method="post" target="_top">
// <input type="hidden" name="currency_code" value="USD">
// <button type='button' ng-click='save(payForm)'>buy</button>
// </form>
.directive("ngFormCommit", [function(){
return {
require:"form",
link: function($scope, $el, $attr, $form) {
@wholypantalones
wholypantalones / KC60-Map.kbd.json
Last active September 13, 2016 00:14 — forked from arkhaen/KC60-Map.kbd.json
KC60 Map
[
{
"name": "KC60 Map"
},
[
"Esc",
"!\n1",
"@\n2",
"#\n3",
"$\n4",
@wholypantalones
wholypantalones / percent-filter
Created September 1, 2016 13:28
Angularjs format percentage
// In app.js or main.js or whatever:
// var myApp = angular.module('askchisne', ['ngSanitize', 'ngAnimate', 'ui.bootstrap', 'ui.bootstrap.tpls']);
// This filter makes the assumption that the input will be in decimal form (i.e. 17% is 0.17).
myApp.filter('percentage', ['$filter', function ($filter) {
return function (input, decimals) {
return $filter('number')(input * 100, decimals) + '%';
};
}]);