Skip to content

Instantly share code, notes, and snippets.

View karol-majewski's full-sized avatar

Karol Majewski karol-majewski

View GitHub Profile
@buren
buren / cross-origin-local-storage.js
Created November 1, 2017 10:21
Cross origin local storage sharing example (using an iframe and postMessage)
const CrossOriginLocalStorage = function(currentWindow, iframe, allowedOrigins, onMessage) {
this.allowedOrigins = allowedOrigins;
let childWindow;
// some browser (don't remember which one) throw exception when you try to access
// contentWindow for the first time, it works when you do that second time
try {
childWindow = iframe.contentWindow;
} catch(e) {
childWindow = iframe.contentWindow;
@timvisee
timvisee / falsehoods-programming-time-list.md
Last active April 10, 2025 14:31
Falsehoods programmers believe about time, in a single list

Falsehoods programmers believe about time

This is a compiled list of falsehoods programmers tend to believe about working with time.

Don't re-invent a date time library yourself. If you think you understand everything about time, you're probably doing it wrong.

Falsehoods

  • There are always 24 hours in a day.
  • February is always 28 days long.
  • Any 24-hour period will always begin and end in the same day (or week, or month).
@OliverJAsh
OliverJAsh / foo.md
Created December 8, 2017 11:29
Avoiding CSS overrides in responsive components

Avoiding CSS overrides in responsive components

I would like to demonstrate some of the benefits of scoped styles over mobile-first CSS with overrides for wider breakpoints. I'll start by explaining the two approaches, before listing the benefits.

Mobile-first with overrides for wider breakpoints

h2 {
  color: black;
 font-size: 2em;
@sebmarkbage
sebmarkbage / Infrastructure.js
Last active February 26, 2025 13:57
SynchronousAsync.js
let cache = new Map();
let pending = new Map();
function fetchTextSync(url) {
if (cache.has(url)) {
return cache.get(url);
}
if (pending.has(url)) {
throw pending.get(url);
}
@vjeux
vjeux / x.md
Last active January 6, 2024 07:15
Ocaml / functional programming

I'm taking down this post. I just posted this as a side comment to explain a sentence on my latest blog post. This wasn't meant to be #1 on HN to start a huge war on functional programming... The thoughts are not well formed enough to have a huge audience. Sorry for all the people reading this. And please, don't dig through the history...

@ygrenzinger
ygrenzinger / CleanArchitecture.md
Last active April 8, 2025 17:22
Summary of Clean Architecture by Robert C. Martin

Summary of book "Clean Architecture" by Robert C. Martin

Uncle Bob, the well known author of Clean Code, is coming back to us with a new book called Clean Architecture which wants to take a larger view on how to create software.

Even if Clean Code is one of the major book around OOP and code design (mainly by presenting the SOLID principles), I was not totally impressed by the book.

Clean Architecture leaves me with the same feeling, even if it's pushing the development world to do better, has some good stories and present robust principles to build software.

The book is build around 34 chapters organised in chapters.

@OliverJAsh
OliverJAsh / foo.js
Last active September 20, 2022 18:18
GitHub PR snippets
// Expand all collapsed commits
$$('.js-timeline-progressive-disclosure-button').forEach(el => el.click());
// Expand all collapsed conversations
$$('button')
.filter(el => el.innerText === 'Load more…')
.forEach(el => el.click());
void function() {
class ChessError extends Error { }
class InvalidMoveError extends ChessError { }
class NoLineOfSightError extends ChessError { }
class NotYourTurnError extends ChessError { }
// Represents a chess game
class Game {
private board = new Board
@oyvindym
oyvindym / resolve-declaration-collision.md
Created April 11, 2018 06:56
How to resolve TS2717 error with declaration collision between dependencies

Resolving declaration collision between dependencies

Getting a flood of TS2717 Typescript errors when running your application?

Deleting the @types-package mentioned in the logs from the node-modules/@types folder and upgrading it again using yarn should solve the problem.

Example

@types/react-redux is complaining about subsequent property declarations (see logs below).

@surma
surma / findall_elements_deep.js
Last active October 25, 2020 16:41 — forked from ebidel/findall_elements_deep.js
Finds all elements on the page, including those within shadow dom — iterator version
/**
* Inspired by ebidel@ (https://gist.github.com/ebidel/1b418134837a7dde7d76ed36288c1d16)
* @author surma@
* License Apache-2.0
*/
function* collectAllElementsDeep(selector = '*', root = document.all) {
for (const el of root) {
if (!el.matches(selector))
continue;