Skip to content

Instantly share code, notes, and snippets.

@lxm7
lxm7 / new.ts
Created April 7, 2020 18:31
Re-write of reducers that are using custom redux hooks
import useReduxState from 'utils/hooks/useReduxState';
// Interfaces
import ICreditPack, { emptyCreditPack } from 'utils/interfaces/ICreditPack';
import ICreditPackExecutiveSummary from 'utils/interfaces/ICreditPackExecutiveSummary';
import ICreditPackApplicationFace from 'utils/interfaces/ICreditPackApplicationFace';
import ICreditPackAppraisal, {
ICreditPackAppraisalSubSection,
TSectionKey,
TClippingType,
@lxm7
lxm7 / merge.js
Created February 9, 2019 12:36
Merge 2 arrays v.efficiently set against the match of one field from one and one field form the other set. Maintain properties from both
const rootResolvers = {
Query: {
coins: async (_, { limit, offset }) => {
const initialLimit = process.env.LIMIT || limit;
const initialOffset = offset || 0;
const cmc = await fetchCmcListFn(initialLimit, initialOffset);
const cc = await fetchCcListFn();
const coinListWithCcId = lodash(cmc) // start sequence
@lxm7
lxm7 / gist:8fc90153b05d101bfff6198a12545ecf
Last active February 9, 2019 12:36
Show git branch in ubuntu terminal
# Add git branch if its present to PS1
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ '
@lxm7
lxm7 / gist:264ef43d5dae276b0099d0316a4c15bf
Created November 20, 2017 17:35
Helpful map, reduce, filtering data
const prizesArr = [{id:1, value: "100"}, {id:2, value: "10"}, {id:3, value: "100"}];
let values = [] as string[];
// This checks for the highest occurence of the property value in each prize.
// They're wont be any higher than 3, and this 3x occurence is the prize
// amount that's passed to the promotionTriggerOptIn function
return prizesArr
.reduce((prev, curr) => { prev.push(curr.value); return prev; }, values = [])
.sort((a, b) => values.filter((v) => v === a).length - values.filter((v) => v === b).length)
.pop();
@lxm7
lxm7 / Sublime Text settings
Created February 18, 2017 15:26
Slick, readable UI.
{
"color_scheme": "Packages/Oceanic Next Color Scheme/Oceanic Next.tmTheme",
"ensure_newline_at_eof_on_save": true,
"folder_exclude_patterns":
[
".svn",
".git",
".hg",
"CVS",
"node_modules"