Skip to content

Instantly share code, notes, and snippets.

View GGAlanSmithee's full-sized avatar

Alan Smithee GGAlanSmithee

View GitHub Profile
@GGAlanSmithee
GGAlanSmithee / README.md
Last active October 21, 2021 13:20
simple C++ constant size array implementation

simple C++ constant size array implementation

Since you can only pass a pointer to an array - and not the array itself - as an argument to a function in C, the information regarding the length of the array is lost. While you can derrive the length with something like sizeof(arr) / sizeof(int), that is a run-time operation and quite ugly.

There are other data structures, such as std::vector, that solves this problem, but it comes with a lot of other aspects, such as dynamic memory allocation, that you might not be interested in.

This gist provides a super simple implementation of an array of a fixed size that is not dynamically allocated but has its length as a property. Just like a normal array, it allows indexed element read and write operations, but nothing more.

Considerations

@GGAlanSmithee
GGAlanSmithee / dealyed-redirect.ts
Last active July 13, 2020 03:17
react-router DelayedRedirect
import * as React from 'react'
import { Redirect, RedirectProps } from 'react-router'
interface DelayedProps {
delay: number
}
interface DelayedState {
timeToRedirect: boolean
}
@GGAlanSmithee
GGAlanSmithee / principles.md
Last active August 23, 2017 07:09
Principles I like

Principle of least astonishment

a component of a system should behave in a manner consistent with how users of that component are likely to expect it to behave

To avoid premature optimizations

make it work, make it right, make it fast

S.O.L.I.D (for object-oriented programming)

@GGAlanSmithee
GGAlanSmithee / awesome C++.md
Last active December 15, 2015 09:39
awesome C++
  • Locality matters

use arrays or vectors

  • Whole-Part Relationships and Composite Objects
    • Connected (all parts of the whole are reachable from the whole)
    • Noncircular (something can not be a part of itself (directly or indirectly)
    • Logically disjoint (an object can be shared between two other objects but if one of those objects are changed the other is not)
  • Owning (if an object is copied/deleted all its parts are copied/deleted too)
@GGAlanSmithee
GGAlanSmithee / index.md
Last active November 22, 2015 14:13
docker npm issues

Sometimes npm will turn very slow out and not install anything.

It seems to have something to do with using npm on a docker VM.

The fix for me was

npm cache clean

followed by

@GGAlanSmithee
GGAlanSmithee / quotes.md
Last active December 14, 2017 14:10
Quotes I like
@GGAlanSmithee
GGAlanSmithee / words.md
Last active August 23, 2017 07:07
Words I like
  • Actionable

capable of being acted on

  • Declarative

what, not how

  • Data structure

a way of organizing data so that it can be used efficiently

A structure utilizing value, physical, and representational relationships to encode sematic relationships on a collection of objects / Sean Parent

@GGAlanSmithee
GGAlanSmithee / awesome ES(6).md
Last active October 13, 2015 09:55
Reminder to myself of awesome ES(6) features

Reminder to myself of some nice ES(6) features

A nice way to avoid the options parameter so often used

function frob(arg1, arg2, {foo = defFoo, bar = defBar, baz = defBaz}) {
  // just use foo, bar, and baz instead of ops.foo, etc.
}