Skip to content

Instantly share code, notes, and snippets.

@martinaglv
martinaglv / 01.js
Last active July 25, 2024 03:38
What do these functions do?
function whatDoesItDo(val){
return val ? 1 : 2;
}
@ericelliott
ericelliott / essential-javascript-links.md
Last active February 23, 2026 21:20
Essential JavaScript Links
@mattmccray
mattmccray / component-with-mixins.js
Created February 17, 2015 19:42
ES6 Classes w/Mixins -- Idea -- React 0.13
export function ComponentWithMixins( ...mixins) {
class MixedComponent extends React.Component { }
for( let mixin of mixins) {
// TODO: Would need to handle mixin collisions...
for( let name of Object.keys( mixin)) {
MixedComponent.prototype[ name]= mixin[ name]
}
}
@brandonrozek
brandonrozek / basic-serviceworker.js
Last active November 7, 2023 09:10
A basic serviceworker implementation for offline website viewing
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// http://creativecommons.org/publicdomain/zero/1.0/
var version = 'v2.0.24:';
var offlineFundamentals = [
'/',
'/offline/'
];
@dmfigol
dmfigol / asyncio_loop_in_thread.py
Last active November 24, 2025 13:16
Python asyncio event loop in a separate thread
"""
This gist shows how to run asyncio loop in a separate thread.
It could be useful if you want to mix sync and async code together.
Python 3.7+
"""
import asyncio
from datetime import datetime
from threading import Thread
from typing import Tuple, List, Iterable
@stepanselyuk
stepanselyuk / LFUCache.php
Created February 12, 2021 08:26
LFUCache Leetcode (Hard, #460)
<?php
/*
* Least Frequently Used (LFU) is a caching algorithm in which the least frequently used cache block is removed whenever the cache is overflowed.
* In LFU we check the old page as well as the frequency of that page and if the frequency of the page is larger than the old page we cannot remove it
* and if all the old pages are having same frequency then take last i.e FIFO method for that and remove that page.
*/
include_once '../../runner.php';