Skip to content

Instantly share code, notes, and snippets.

View sghall's full-sized avatar
🥊

Steve Hall sghall

🥊
  • San Francisco, CA
View GitHub Profile
@sghall
sghall / MarkedMessage.jsx
Created April 3, 2020 21:12
Marked Message
// Test Component:
interface MarkedMessageProps {
message: string;
matches: { offset: number; length: number }[];
}
const MarkedMessage: React.FC<MarkedMessageProps> = ({ message, matches }) => {
const parts: React.ReactNode[] = [];
let runningOffset = 0;
@sghall
sghall / three.phong.frag.glsl
Created March 23, 2019 21:19
Three Shaders
precision highp float;
precision highp int;
#define SHADER_NAME MeshPhongMaterial
#define GAMMA_FACTOR 2
uniform mat4 viewMatrix;
uniform vec3 cameraPosition;
#define TONE_MAPPING
#ifndef saturate
#define saturate(a) clamp( a, 0.0, 1.0 )
#endif
html {
background-color: grey;
}
.ReactTable {
position: relative;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
border: 1px solid rgba(0, 0, 0, 0.1);
@sghall
sghall / gist:634c1099e731542a0a076286f052eedc
Created January 23, 2017 21:05
Min Perimeter for Rectangle of Given Area in JavaScript
function minPerimeter(num) {
let min = 0;
for (let i = 0; i * i <= num; i++) {
if (num % i === 0) {
min = 2 * (i + (num / i));
if (!(i === num / i)) {
if (min > 2 * (i + (num / i))) {
min = 2 * (i + (num / i));
@sghall
sghall / gist:df3146a3290c1c40a3820ac154dcb820
Last active January 23, 2017 19:20
Count Factors of Number in JavaScript
function getFactorCount(num) {
if (num === 0) {
return;
}
if (num === 1) {
return 1;
}
@sghall
sghall / gist:1745a23a9aed9781a115660434788332
Created January 23, 2017 08:53
Max Sub-Array JavaScript
https://en.wikipedia.org/wiki/Maximum_subarray_problem
function maxSubArray(arr) {
const len = arr.length;
let cur = arr[0];
let max = arr[0];
for (let i = 1; i < len; i++) {
cur = Math.max(arr[i], cur + arr[i]);
@sghall
sghall / gist:b3d55273f480875e799e16dbf204fb9a
Last active January 25, 2017 15:35
toNegaBinary and toNegaQuaternary
https://en.wikipedia.org/wiki/Negative_base#Calculation
function toNegaBinary( number ) {
var Schroeppel2 = 0xAAAAAAAA;
return ( ( number + Schroeppel2 ) ^ Schroeppel2 ).toString(2);
}
function toNegaQuaternary( number ) {
var Schroeppel4 = 0xCCCCCCCC;
return ( ( number + Schroeppel4 ) ^ Schroeppel4 ).toString(4);
@sghall
sghall / gist:42eb3644db8ae48d2ea045569ec56c4a
Created January 23, 2017 07:30
Count Rectangles in Wall
function reactanlgeCount(arr) {
const stack = [];
let count = 0;
for (let i = 0; i < arr.length; i++) {
const next = arr[i];
while (stack.length && next < stack[stack.length - 1]) {
stack.pop();
@sghall
sghall / gist:0822376f668fda0664e497d8474aa0fd
Created January 23, 2017 06:25
Determine if Brackets/Parenthesis are Nested Correctly
const map = { '(': ')', '[': ']', '{': '}' };
function nestedBrackets(s) {
const stack = [];
for (let i = 0; i < s.length; i++) {
if (s[i] === '{' || s[i] === '[' || s[i] === '(') {
stack.push(s[i]);
} else if (s[i] === '}' || s[i] === ']' || s[i] === ')') {
if (map[stack[stack.length - 1]] !== s[i]) {