Skip to content

Instantly share code, notes, and snippets.

View Bengejd's full-sized avatar
🏠
Working from home

Jordan Benge Bengejd

🏠
Working from home
View GitHub Profile
@Bengejd
Bengejd / SpreadReduceObject-NoArg.examples.ts
Last active April 6, 2022 18:50
Reduce & Spread an array of object values to a singular object with mapped [keyValue]: newValue pairs instead of [key]: value pairs.
const dataMap = (data, valueArgs) => {
return data
.map( (obj) => ({
date: new Date(obj.date),
manual: true,
...valueArgs.reduce((prev, curr, index) => ({
...prev,
[curr.name]: curr.split
? Number(obj.value.split("/")[index])
: Number(obj.value),
@Bengejd
Bengejd / Difference.ts
Last active July 26, 2022 19:14
Lodash Deep Object Diff Comparison with details
// Lodash Diff comparison from a couple years ago
getDiff() {
const changes = (object, base) => {
let arrayIndexCounter = 0;
return _.transform(object, function (result, value, key) {
if (!_.isEqual(value, base[key])) {
let resultKey = _.isArray(base) ? arrayIndexCounter++ : key;
result[resultKey] = (_.isObject(value) && _.isObject(base[key])) ? changes(value, base[key]) : value;
console.log("Result: " + JSON.stringify(result));
}
@Bengejd
Bengejd / resolve.ts
Created July 23, 2021 15:51
Accessing nested JavaScript objects and arrays by string path
const resolve = (path, obj) => path.split(".").reduce((prev, curr) => prev ? prev[curr] : null, obj || self);
@Bengejd
Bengejd / Util.lua
Created May 8, 2020 19:50
Utility functions that I use in WoW Addon Development
local _, core = ...;
local _G = _G;
local L = core.L;
local Util = core.Util;
local PDKP = core.PDKP;
local Defaults = core.defaults;
-- WoW Classic Alliance Classes
local classes = {
@Bengejd
Bengejd / example.html
Created February 10, 2019 21:12
Simulate natural typing on a page
{{value | naturalType}}
@Bengejd
Bengejd / debounce.pipe.ts
Created February 10, 2019 21:10
Debounce a user input
@Pipe({name: 'debounce', pure: false})
export class DebouncePipe {
private currentValue: any = null;
private transformValue: any = null;
private timeoutHandle: number = -1;
constructor(
private changeDetector: ChangeDetectorRef,
private zone: NgZone,
) {
}
@Bengejd
Bengejd / default.pipe.ts
Created February 10, 2019 21:07
Returns a provided default pipe if the initial value is falsy.
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({name: 'default', pure: true})
export class DefaultPipe implements PipeTransform {
transform(value: any, defaultValue: any): any {
return value || defaultValue;
}
}
@Bengejd
Bengejd / _push-from-bottom.scss
Created February 10, 2019 21:01
Push the screen up from the bottom, while maintaining a correct list order. Meant for chat pages mostly.
@mixin pushFromBottom() {
overflow: auto;
display: flex;
flex-direction: column-reverse;
}
...
.push-from-bottom-container {
@include pushFromBottom();
}
@Bengejd
Bengejd / _scroll-in-textarea.scss
Created February 10, 2019 20:56
Ionic scroll in text-areas.
@mixin scrollInText() {
overflow: initial !important;
}
@Bengejd
Bengejd / _aspect-ratio.scss
Last active February 10, 2019 20:50
Maintain aspect ratio in scss (height = width).
@mixin aspectRatio($ratio: '1:1', $width: 100%) {
width: $width;
@if($ratio == '1:1') {
padding-top: 100%; /* 1:1 Aspect Ratio */
}
@else if($ratio == '16:9') {
padding-top: 56.25%; /* 16:9 Aspect Ratio */
}
@else if($ratio == '4:3') {
padding-top: 75%; /* 4:3 Aspect Ratio */