Skip to content

Instantly share code, notes, and snippets.

@jps
jps / setup-osx.sh
Last active September 13, 2022 10:19
#bash <(curl -sL https://gist.githubusercontent.com/mob-sakai/174a32b95572e7d8fdbf8e6f43a528f6/raw/hello.sh)
#terminal
brew install vim
brew install zsh
brew install hyper
brew install bat
brew install z
#code
@jps
jps / has-path.js
Last active May 15, 2022 10:52
graphs depth first has path - https://structy.net/problems/has-path
//breadth first iterative
const hasPath = (graph, src, dst) => {
let queue = [src];
while(queue.length > 0)
{
let current = queue.shift()
if(current === dst)
{
@jps
jps / heap.ts
Created May 14, 2022 13:39
algo pratice typescript heap implementation
const assert = require('assert');
//i = item index
//left child index = 2i +1
//right child index = 2i +2
const heapPush = (heap:Array<number>, value: number) => {
heap.push(value)
let index = heap.length-1;
const assert = require("assert");
const nextPrime = (primes: Array<number>) : number => {
if(primes.length == 0)
{
return 2;
}else if(primes.length == 1)
{
return 3;
}
@jps
jps / fib-backtracking.js
Created April 18, 2022 11:35
fibonachi implementation with backtracking
const assert = require('assert');
const fib = (n: number, memo?: Array<number>): number => {
if (memo == null) {
memo = Array(n);
}
if (memo[n] === undefined) {
memo[n] = n == 0 || n == 1
? 1
: fib(n - 1, memo) + fib(n - 2, memo);
@jps
jps / sort-zero-to-left.js
Created April 9, 2022 12:21
soft zeros to left in an integer array
//Given an integer array
//move all elements that are equal to 0 to the left while maintaining the order of other elements in the array.
//[1,0,2,0,3] => [0,0,1,2,3];
/*
[1,0,2,0,3]
[0,1,2,0,3]
@jps
jps / find-bounds.js
Created April 8, 2022 21:05
find bound of value in an array
var Mocha = require('mocha')
var assert = require('assert')
var mocha = new Mocha()
// Bit of a hack, sorry!
mocha.suite.emit('pre-require', this, 'solution', mocha)
/*
Given a sorted array of integers
function getEndEnhancer() {
if (!statusIcon) {
return endEnhancer;
}
if (endEnhancer) {
return (
<>
{' '}
{statusIcon} <Block spaceInline="space020" /> {endEnhancer}{' '}
@jps
jps / factiva-newskit-grid.tsx
Created July 7, 2021 16:47
simplified example of how the factiva site could be built using the NewsKit Grid
import * as React from 'react';
import { getColorCssFromTheme, getSpacingCssFromTheme, styled } from '../../utils/style';
import { Grid, Cell } from '..';
import { Stack } from '../../stack';
import { Block } from '../../block';
const DowNav = styled.div`
${getColorCssFromTheme('background-color', 'interfaceBrand020')}
height: 72px;
width:100%;
@jps
jps / button-with-component-defaults.jsx
Last active February 5, 2021 11:45
component defaults example of Newskit button for blog
//Declare our custom theme
const myCustomTheme = createTheme({
name: 'newskit-component-defaults-change',
overrides: {
componentDefaults: {
button: {
medium: {
typographyPreset: 'utilityButton010',
stylePreset: 'buttonOutlinedPrimary',
},