Skip to content

Instantly share code, notes, and snippets.

View adamdehaven's full-sized avatar

Adam DeHaven adamdehaven

View GitHub Profile
@adamdehaven
adamdehaven / rgb-inverse.js
Created May 14, 2020 12:23
Determine the inverse color (white or black) for a given RGB value
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 March 4, 2020 14:12
Get the angle (in degrees or radians) between two points
let pointOne = {
x: 20,
y: 20,
}
let pointTwo = {
x: 40,
y: 40,
}
@adamdehaven
adamdehaven / vs-code-custom-font.md
Created February 7, 2020 19:06
VS Code Custom Font without Font Install Privileges

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 November 18, 2020 00:09
Parse URL or comma-delimited query string with 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 March 27, 2019 19:59
Pagination Algorithm
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 February 27, 2019 02:23
Modal code for a friend
<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 February 18, 2019 21:50
SQL Function to split a comma-delimited string into a table result
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 February 7, 2019 19:23
JavaScript Trigger Event
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;
@adamdehaven
adamdehaven / paste-events.js
Last active December 13, 2018 15:22
jQuery Paste Events
$.fn.pasteEvents = function( delay ) {
if (delay == undefined) delay = 20;
return $(this).each(function() {
var $el = $(this);
$el.on('paste', function() {
$el.trigger('prepaste');
setTimeout(function() { $el.trigger('postpaste'); }, delay);
});
});
};
@adamdehaven
adamdehaven / parse.php
Last active October 10, 2018 17:21
PHP and XML Namespace
<?php
// LOAD FROM FILE
$xml = simplexml_load_file('sample.xml');
// ALTERNATE LOAD FROM STRING
// $xml = simplexml_load_string($xmlResponse);
foreach($xml->data as $data) {
$namespaces = $data->getNameSpaces(true);
$a = $data->children($namespaces['a']);