Skip to content

Instantly share code, notes, and snippets.

View ScottKaye's full-sized avatar
🌎

Scott Kaye ScottKaye

🌎
View GitHub Profile
@ScottKaye
ScottKaye / Hide URL Parameters.js
Last active August 24, 2024 12:24
Hide URL parameters using Javascript's history.replaceState methods. The server (PHP or whatever) will still see it of course, but this script will quickly 'hide' the parameters. Don't use this to hide anything sensitive - there shouldn't be anything sensitive in GET anyway, but I use this to hide various un-pretty things like ?error=invalidPass…
function getURLParameter(name) {
return decodeURI((RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]);
}
function hideURLParams() {
//Parameters to hide (ie ?success=value, ?error=value, etc)
var hide = ['success','error'];
for(var h in hide) {
if(getURLParameter(h)) {
history.replaceState(null, document.getElementsByTagName("title")[0].innerHTML, window.location.pathname);
}
@ScottKaye
ScottKaye / HandyDandyPrototypes.js
Last active July 10, 2023 19:16
A collection of potentially useful prototypes to make some things easier. Each of these should be crushable with http://www.iteral.com/jscrush/ . "Don't modify objects you don't own" is completely thrown out the window here in favour of coolness.
//Get a range of numbers between two numbers
//Usage: [1, 10].range returns [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Object.defineProperty(Array.prototype, "range", {
get: function () {
var range = [this[0]], i;
for (var i = this[0], len = this[1]; i < len; range.push(++i));
return range;
}
});
// Golfed TypeScript:
<svg class="loader" width="60" height="60" xmlns="http://www.w3.org/2000/svg">
<g>
<ellipse ry="25" rx="25" cy="30" cx="30" stroke-width="5" stroke="#000" fill="none"/>
</g>
</svg>
@ScottKaye
ScottKaye / Query String Manipulations.js
Last active October 8, 2015 14:09
A library for managing the query string and hash.
(function (url, undefined) {
"use strict";
var _params = {};
var _hash = {};
function buildParams(obj) {
return Object.keys(obj).length ?
"?" + Object.keys(obj).map(function(e) {
return encodeURIComponent(e) + "=" + encodeURIComponent(obj[e]);
@ScottKaye
ScottKaye / Duplicate Element.js
Last active August 29, 2015 14:19
Duplicates an element, including computed styles, but only keeping non-default values.
function duplicateElement(element) {
var newElement = document.createElement(element.tagName);
document.body.appendChild(newElement);
var newStyle = window.getComputedStyle(element, null).cssText;
var baseProperties = window.getComputedStyle(newElement, null).cssText.split(';').map(function (e) {
return e.trim();
});
newElement.innerHTML = element.innerHTML;
//Remove styles with default value
newElement.style.cssText = newStyle.split(';').map(function (e) {
@ScottKaye
ScottKaye / Timeout.js
Created April 27, 2015 13:16
Timeout - will run a function and forcibly terminate after a given time.
function timeout(func, limit) {
var url = URL.createObjectURL(new Blob(
['(', func.toString(), ')()'], {
type: 'application/javascript'
}));
worker = new Worker(url);
URL.revokeObjectURL(url);
setTimeout(function () {
@ScottKaye
ScottKaye / garbage.js
Last active April 2, 2016 19:02
I'm not proud of this. 2009 baby!
<script type="text/javascript">
/***********************************************
* Javascript Generator Script by PGReviews (Physicsguy's Reviews)
* Visit /web/20090808182931/http://www.execulink.com/~kayes/physicsguy/web/ for reviews, guitar tablature, and more!
* This notice must stay intact for legal use
***********************************************/
function welcome3()
@ScottKaye
ScottKaye / jquery.shadow.js
Last active September 10, 2015 02:30
Disables control-f results, text selection, and all other interaction for any bit of text.
(function ($) {
$.fn.shadow = function () {
this.each(function () {
var text = this.innerText;
this.createShadowRoot()
.innerHTML = "<style>:host::after{content:'" + text + "'}</style>";
});
return this;
};
@ScottKaye
ScottKaye / palindrome.js
Last active October 13, 2015 16:49
Wanted to make sure I can actually do this. isPalindrome is almost cheating, so isPalindromeAcademic does this problem in a more "classical" way. jsperf: http://jsperf.com/high-level-vs-lower-level-palindrome-test
function normalize(s) {
return s.toLowerCase().replace(/[^a-z]/g, "");
}
Object.defineProperty(String.prototype, "isPalindrome", {
get: function () {
var rev = this.split("").reverse().join("");
return normalize(rev) === normalize(this);
}
});
var gulp = require("gulp");
var buffer = require("vinyl-buffer");
var source = require("vinyl-source-stream");
var sourcemaps = require("gulp-sourcemaps");
var sass = require("gulp-ruby-sass");
var rename = require("gulp-rename");
var autoprefixer = require("gulp-autoprefixer");
var minifycss = require("gulp-minify-css");