Skip to content

Instantly share code, notes, and snippets.

View ScottKaye's full-sized avatar
🌎

Scott Kaye ScottKaye

🌎
View GitHub Profile
@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 / 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 / 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 / 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");
D̝͍I̓ͪ͌ͤṢ̗̌̌̍͐̅̾ͤR̬̹̠͚̬͖ͣͣ͐ͪ̽̊Ư̝͔ͪ̄̏̈́̕P̷̼͆ͥ̉͒͂͒ͨ͐̆͠ͅT̫̜̜̜̟̎ͫ͋̑̅͛I̶̶̧̖̟̩̭̪̻̳͍̳̠̺̻̣̓̂̑̚͝V̈́ͭ̄ͣ̾̋̎̑͐ͤͪ͂͊̍́ͮ͊̉҉̷͙͔̤̮̣͍̺̮̳͍̭̭͘È̡͙̖̪͙͔̦͉̭̖͍̜͉̪̪͈̺͍͇ͫ̓͐̄ͬ̈́̏͊͒̌͌͗͟͝͡
@ScottKaye
ScottKaye / Preferences.sublime-settings
Last active April 1, 2016 03:20
Because Sublime keeps forgetting this fscking file, I'm saving it here.
{
"always_show_minimap_viewport": true,
"bold_folder_labels": true,
"caret_extra_bottom": 1,
"caret_extra_top": 1,
"caret_extra_width": 1,
"caret_style": "phase",
"color_scheme": "Packages/User/SublimeLinter/Oceanic Next (SL).tmTheme",
"drag_text": false,
"draw_minimap_border": true,
@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()
"use strict";
const vm = require("vm");
const util = require("util");
const Constants = require("../constants");
let helpText = `you can evaluate **JS code and expressions** with \`!eval\`!
:information_source: Just use \`!eval <code>\`.