Skip to content

Instantly share code, notes, and snippets.

View holmberd's full-sized avatar

holmberd holmberd

View GitHub Profile
@holmberd
holmberd / github.md
Created January 11, 2024 19:03
Github Convinces

Auto create remote branch when pushing local branch.

git config --global --add --bool push.autoSetupRemote true

@holmberd
holmberd / go-notes.md
Last active December 9, 2023 01:03
Go Notes

Slices

// https://www.dolthub.com/blog/2023-10-20-golang-pitfalls-3/
type slice struct {
    array unsafe.Pointer
    len   int
    cap   int
}

sliceA := []int{1, 2, 3}
@holmberd
holmberd / rob-pikes-5-rules-of-programming.txt
Created November 1, 2023 15:32
Rob Pike's 5 Rules of Programming
Rob Pike's 5 Rules of Programming
Rule 1. You can't tell where a program is going to spend its time. Bottlenecks occur in surprising places, so don't try to second guess and put in a speed hack until you've proven that's where the bottleneck is.
Rule 2. Measure. Don't tune for speed until you've measured, and even then don't unless one part of the code overwhelms the rest.
Rule 3. Fancy algorithms are slow when n is small, and n is usually small. Fancy algorithms have big constants. Until you know that n is frequently going to be big, don't get fancy. (Even if n does get big, use Rule 2 first.)
Rule 4. Fancy algorithms are buggier than simple ones, and they're much harder to implement. Use simple algorithms as well as simple data structures.
Rule 5. Data dominates. If you've chosen the right data structures and organized things well, the algorithms will almost always be self-evident. Data structures, not algorithms, are central to programming.
Pike's rules 1 and 2 restate Tony Hoare's famous maxim "Premature
@holmberd
holmberd / assignments.md
Last active March 20, 2023 17:39
Assignments

Exercises

There are two exercises in this document that are expected to be completed.

The source-code for each exercise should live in a separate repository, Github or GitLab, and should be accessible to the reviewer of the assignment. Each repository should contain a README file explaining the purpose of the repository and how to run it locally.

For each exercise you are free to use whatever libraries and technologies you like, but a combination of Javascript/Typescript/React is preferred for the first exercise, and Nodejs/PHP for the second.

Please do your best to write production-quality code.

Once completed, links to both of the repositories should be sent to: [email protected]

@holmberd
holmberd / web-components.js
Last active March 29, 2022 15:04
Web Components height/width
static get observedAttributes() {
return ['height', 'width'];
}
get height() {
return this.hasAttribute('height') && Number(this.getAttribute('height').replace('px', ''));
}
set height(val) {
if (val) {

Code Review

  1. Explain the Game of life rules to the candidate, make sure they understand it.
  2. Walk through the program and its various parts with the candidate. Have the candidate read the code and explain what it does.
  3. Explain to the candidate to treat this as a regular code review where they are allowed to ask questions to clarify code/logic and that they should aim to make suggestions for how this code can be improved/refactored.

Required

  • Candidate should be able to read and explain each section of the code.
  • Candidate should be able to highlight parts of the code that is not considered good practice, e.g. code-smells, anti-patterns.
  • Candidate should suggest places for validations in the code.
@holmberd
holmberd / game_of_life_example.py
Last active May 18, 2022 14:52
Game of life Python [1]
CELL_ALIVE_CHAR = '*'
CELL_DEAD_CHAR = '.'
class Location:
def __init__(self, row_index, col_index):
self.row = row_index
self.col = col_index
class Cell:
def __init__(self, state):
@holmberd
holmberd / game_of_life_example.js
Last active May 18, 2022 14:52
Game of life Javascript [1]
/**
* Conway's Game of Life
*
* The world of the Game of Life is an infinite two-dimensional orthogonal grid of square
* "cells", each of which is in one of two possible states, alive or dead.
*
* Rules:
* 1. Any live cell with fewer than two live neighbours dies, as if by underpopulation.
* 2. Any live cell with two or three live neighbours lives on to the next generation.
* 3. Any live cell with more than three live neighbours dies, as if by overpopulation.
@holmberd
holmberd / game_of_life_bad.js
Last active November 26, 2021 19:27
Game of life Javascript [2]
/**
* Conway's Game of Life
*
* The world of the Game of Life is an infinite two-dimensional orthogonal grid of square
* "cells", each of which is in one of two possible states, alive or dead.
*
* Rules:
* 1. Any live cell with fewer than two live neighbours dies, as if by underpopulation.
* 2. Any live cell with two or three live neighbours lives on to the next generation.
* 3. Any live cell with more than three live neighbours dies, as if by overpopulation.
@holmberd
holmberd / useVisibleElementsIndex.js
Created May 28, 2021 15:08
React Hook: useVisibleElementsIndex
import { useState, useEffect } from 'react';
import { debounce } from 'lodash';
/**
* React Hook that returns an index for the right-most element that is horizontally
* visible within the boundaries of the container.
*/
function useVisibleElementsIndex(containerRef, items) {
const [visibleElementsIndex, setVisibleElementsIndex] = useState(0);