Skip to content

Instantly share code, notes, and snippets.

@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';
@dmfigol
dmfigol / asyncio_loop_in_thread.py
Last active April 21, 2024 17:32
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
@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/'
];
@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]
}
}
@ericelliott
ericelliott / essential-javascript-links.md
Last active May 7, 2024 01:25
Essential JavaScript Links
@martinaglv
martinaglv / 01.js
Last active May 10, 2019 07:03
What do these functions do?
function whatDoesItDo(val){
return val ? 1 : 2;
}
@twalker
twalker / backbone-promises.js
Last active September 3, 2023 17:08
Monkey patch Backbone sync operations to return ES6 promises
/**
* backbone-promises returns ES6 Promises for Backbone.sync operations.
* @return {Object} monkey-patched Backbone.
*
*/
define(['backbone-lib', 'es6-promise'], function(Backbone, Promise){
// Backbone.ajax to return native ES6 promises for ajax calls insead of jQuery.Deferreds
Backbone.origAjax = Backbone.ajax;
Backbone.ajax = function ajax(){
@mikeblum
mikeblum / backboneSync
Created February 15, 2014 22:31
Override backbone sync
sync: function (method, model, options) {
Backbone.sync.call(method, model, options);
}
//from http://stackoverflow.com/a/18839219/1377866
anonymous
anonymous / сан.цп
Created November 28, 2013 09:32
пер ДуховноеЛицо = действо(признак) {
сие._признак = признак;
};
ДуховноеЛицо.прообраз.помолиться = действо(молитва) {
паства.внемли(молитва + "\пАминь!");
};
пер Диакон = действо(признак) {
ДуховноеЛицо.вызвать(сие, признак);
сие.сан = "диакон";