Skip to content

Instantly share code, notes, and snippets.

View icewind's full-sized avatar

Nikolay Osaulenko icewind

View GitHub Profile
@icewind
icewind / README.md
Created November 26, 2023 16:10
Nextjs approuter prevent the loss of unsaved changes

React hook to catch page unload event in Nextjs and app router to prevent unsaved data loss. Example

const listener = usePageUnloadGuard();
listener.onBeforeUnload = () => !!someCondition;
@icewind
icewind / gist:9a7a73e15bb133629a8627f6d0a594d4
Created November 26, 2018 14:54 — forked from phuysmans/gist:4f67a7fa1b0c6809a86f014694ac6c3a
docker compose health check example
version: '2.1'
services:
php:
tty: true
build:
context: .
dockerfile: tests/Docker/Dockerfile-PHP
args:
version: cli
volumes:
@icewind
icewind / examples.md
Created August 8, 2018 18:59 — forked from jonschlinkert/examples.md
Three files: examples.md, yaml-cheatsheet.md and yaml-cheatsheet.yml

adapted from this blog

# YAML
name: Jon
# YAML
object:
@icewind
icewind / SSL-certs-OSX.md
Created April 4, 2018 12:56 — forked from croxton/SSL-certs-OSX.md
Generate ssl certificates with Subject Alt Names

Generate ssl certificates with Subject Alt Names on OSX

Open ssl.conf in a text editor.

Edit the domain(s) listed under the [alt_names] section so that they match the local domain name you want to use for your project, e.g.

DNS.1   = my-project.dev

Additional FQDNs can be added if required:

@icewind
icewind / how-to-generate-and-use-private-keys-with-openssl-tool.md
Created March 13, 2018 10:54 — forked from briansmith/how-to-generate-and-use-private-keys-with-openssl-tool.md
How to generate & use private keys using the OpenSSL command line tool

How to Generate & Use Private Keys using OpenSSL's Command Line Tool

These commands generate and use private keys in unencrypted binary (not Base64 “PEM”) PKCS#8 format. The PKCS#8 format is used here because it is the most interoperable format when dealing with software that isn't based on OpenSSL.

OpenSSL has a variety of commands that can be used to operate on private key files, some of which are specific to RSA (e.g. openssl rsa and openssl genrsa) or which have other limitations. Here we always use

@icewind
icewind / cors.nginxconf
Created December 8, 2017 13:59 — forked from pauloricardomg/cors.nginxconf
Nginx configuration for CORS-enabled HTTPS proxy with origin white-list defined by a simple regex
#
# Acts as a nginx HTTPS proxy server
# enabling CORS only to domains matched by regex
# /https?://.*\.mckinsey\.com(:[0-9]+)?)/
#
# Based on:
# * http://blog.themillhousegroup.com/2013/05/nginx-as-cors-enabled-https-proxy.html
# * http://enable-cors.org/server_nginx.html
#
server {
@icewind
icewind / docker-cleanup-resources.md
Created November 16, 2017 08:46 — forked from bastman/docker-cleanup-resources.md
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

@icewind
icewind / node-command-line-options.txt
Created November 9, 2017 05:38 — forked from listochkin/node-command-line-options.txt
Node V8 GC-related options
--log_gc (Log heap samples on garbage collection for the hp2ps tool.)
type: bool default: false
--expose_gc (expose gc extension)
type: bool default: false
--max_new_space_size (max size of the new generation (in kBytes))
type: int default: 0
--max_old_space_size (max size of the old generation (in Mbytes))
type: int default: 0
--max_executable_size (max size of executable memory (in Mbytes))
type: int default: 0
@icewind
icewind / mediancut.js
Created November 4, 2017 21:04 — forked from mrflix/mediancut.js
A implementation of the median cut algorithm to cluster the colors in an image.
// data = ctx.getImageData(0, 0, image.width, image.height).data;
//
// mediancut(data, colorCount);
// returns [[255,55,255], [233,34,233], [144,34,233], [89,34,233]];
function mediancut(data, n){
var boxes = [getBoundingBox(data)];
if(n !== 1){
boxes = cut(boxes[0]);
while(boxes.length < n){