Skip to content

Instantly share code, notes, and snippets.

View Finesse's full-sized avatar

Sergey M. Finesse

  • Seoul
View GitHub Profile
@Finesse
Finesse / sudokuSolver.go
Last active November 27, 2022 16:41
Solves sudoku
// A solution for https://leetcode.com/problems/sudoku-solver/
type Cache struct {
row [9][9]bool
column [9][9]bool
box [9][9]bool
}
var oneCode = "1"[0]
var dotCode = "."[0]
@Finesse
Finesse / render_audio_context.js
Created March 15, 2021 03:35
Render audio context
/**
* Renders an offline audio context into an audio buffer.
* Considers timeout and suspension.
*
* The `context` argument is an instance of OfflineAudioContext.
*/
function renderAudio(context) {
return new Promise((resolve, reject) => {
context.oncomplete = (event) => resolve(event.renderedBuffer)
@Finesse
Finesse / babel.js
Last active April 7, 2019 06:59
Babel gentleman setup. Adds only the transforms and polyfills that are required by the browsers you support. Each file is a setup for a different use case.
/*
Setup for using only Babel. It produces a file which require()s Babel helpers (ok for Node.js environment).
NPM dependencies (check the output file to know which of them are really required):
core-js ^3
@babel/runtime ^7.4
NPM dev-dependencies:
@babel/core ^7.4
@babel/plugin-transform-runtime ^7.4
@Finesse
Finesse / getArraysDifference.php
Last active July 10, 2018 07:43
A PHP function to find a difference between 2 arrays. Can use a custom compare logic.
<?php
/**
* Compares 2 arrays. Detects what needs to be removed from and added to the first array to turn it to the second array.
*
* @param array $array1
* @param array $array2
* @param callable|null $areEqual Detects whether two array elements are equal. The first argument is a first array
* value, the second argument is a second array value.
* @return array[] An array with keys:
@Finesse
Finesse / assertException.php
Last active June 27, 2018 02:23
PHPUnit assert exception method
<?php
// Add this method to your test class
/**
* Asserts that the given callback throws the given exception.
*
* @param string $expectClass The name of the expected exception class
* @param callable $callback A callback which should throw the exception
* @param callable|null $onException A function to call after exception check. It may be used to test the exception.
@Finesse
Finesse / image_caption.js
Created September 21, 2017 02:41
My image caption plugin for Froala Editor 2
(function($) {
var IMAGE_MIRROR_CLASSES = ['fr-dii', 'fr-fil', 'fr-fir', 'fr-dib'];
var IMAGE_MIRROR_STYLES = ['width'];
$.FroalaEditor.DEFAULTS = $.extend($.FroalaEditor.DEFAULTS, {
imageCaptionFigureAll: false
});
$.FroalaEditor.PLUGINS.imageCaption = function(editor)
{
@Finesse
Finesse / bnovo.js
Last active April 17, 2017 04:42
Bnovo widget init bug fix. This file should replace the http://widget.bnovo.ru/v2/js/bnovo.js file.
;(function(window) {
var isit;
var init_callbacks = new Array();
var base = is_secure() ? 'https://widget.bnovo.ru' : 'http://widget.bnovo.ru';
function is_local() {
return window._bnovo_local_;
}
function local_host() {
@Finesse
Finesse / PHP cache proposal.php
Last active April 25, 2018 06:21
PSR cache interfaces have the same problem: they don't consider race condition when a cache is stale and a process starts updating cache when another process is already doing it. This proposal make this problem solving be incapsulated into a cache object while keeping it simple.
<?php
$cache = new Cache(); // A cache implementation
/* Basic usage */
/*
This method returns a cached value.
If the value needs to be recalculated, the function from the second argument is called.
The $cache object makes this function not to be called too often in any race conditions by setting locks, updating before expiration or any other method.