Skip to content

Instantly share code, notes, and snippets.

Avatar

Adam DeHaven adamdehaven

View GitHub Profile
@adamdehaven
adamdehaven / uniqueArrayofObjects.js
Created Aug 7, 2020
Remove duplicate objects from JavaScript array
View uniqueArrayofObjects.js
/**
* Returns an array of objects with no duplicates
* @param {Array} arr Array of Objects
* @param {Array} keyProps Array of keys to determine uniqueness
*/
function uniqueArrayofObjects(arr, keyProps) {
return Object.values(arr.reduce((uniqueMap, entry) => {
const key = keyProps.map(k => entry[k]).join('|')
if (!(key in uniqueMap)) uniqueMap[key] = entry
return uniqueMap
View Parallax Star background in CSS.markdown
@adamdehaven
adamdehaven / rgb-inverse.js
Created May 14, 2020
Determine the inverse color (white or black) for a given RGB value
View rgb-inverse.js
function getRgbInverse(red, green, blue) {
const rgb = [parseInt(red), parseInt(green), parseInt(blue)]
let hsp = Math.sqrt(
0.299 * (rgb[0] * rgb[0]) +
0.587 * (rgb[1] * rgb[1]) +
0.114 * (rgb[2] * rgb[2])
)
@adamdehaven
adamdehaven / get-angles.js
Created Mar 4, 2020
Get the angle (in degrees or radians) between two points
View get-angles.js
let pointOne = {
x: 20,
y: 20,
}
let pointTwo = {
x: 40,
y: 40,
}
@adamdehaven
adamdehaven / vs-code-custom-font.md
Created Feb 7, 2020
VS Code Custom Font without Font Install Privileges
View vs-code-custom-font.md

VS Code Custom Font without Font Install Admin Privileges

  1. Open Help -> Toggle Developer Tools in the menu (Ctrl + Shift + I)
  2. Paste JavaScript code below into the Console and execute.
    var styleNode = document.createElement('style'); 
    styleNode.type = "text/css"; 
    var styleText = document.createTextNode(`
        @font-face {
            font-family: "Fira Code";
@adamdehaven
adamdehaven / parse-key-value-string.sql
Last active Oct 25, 2019
Parse URL or comma-delimited query string with SQL
View parse-key-value-string.sql
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Adam DeHaven
-- Create date: 2019-10-25
-- Description: Parses a key=value query string (delimited by a comma or ampersand) and return the key-value pairs as a table
@adamdehaven
adamdehaven / pagination.js
Created Mar 27, 2019
Pagination Algorithm
View pagination.js
pagination(currentPage, pageCount) {
let delta = 1,
left = currentPage - delta,
right = currentPage + delta + 1,
result = []
result = Array.from({ length: pageCount }, (v, k) => k + 1)
.filter(i => i && i >= left && i < right)
if (result.length > 1) {
@adamdehaven
adamdehaven / louarcade-modal.html
Last active Feb 27, 2019
Modal code for a friend
View louarcade-modal.html
<a class="louarcade-show-modal" href="#">Open Modal</a>
<div class="louarcade-modal-overlay">
<div class="louarcade-modal-container">
<div class="louarcade-modal-content">
<button class="louarcade-modal-x louarcade-hide-modal">&times;</button>
Insert modal content.
</div>
@adamdehaven
adamdehaven / split-string.sql
Created Feb 18, 2019
SQL Function to split a comma-delimited string into a table result
View split-string.sql
CREATE FUNCTION [dbo].[SplitCommaDelimitedString]
(
@string NVARCHAR(MAX),
@delimiter CHAR(1)
)
RETURNS @output TABLE(splitdata NVARCHAR(MAX)
)
BEGIN
DECLARE @start INT, @end INT
SELECT @start = 1, @end = CHARINDEX(@delimiter, @string)
@adamdehaven
adamdehaven / triggerEvent.js
Created Feb 7, 2019
JavaScript Trigger Event
View triggerEvent.js
function triggerEvent(el, type) {
if ('createEvent' in document) {
// modern browsers, IE9+
var e = document.createEvent('HTMLEvents');
e.initEvent(type, false, true);
el.dispatchEvent(e);
} else {
// IE 8
var e = document.createEventObject();
e.eventType = type;
You can’t perform that action at this time.