Skip to content

Instantly share code, notes, and snippets.

View zemd's full-sized avatar
🇺🇦

Dmytro Zelenetskyi zemd

🇺🇦
  • Ikea IT AB
  • Malmö, Sweden
View GitHub Profile
@zemd
zemd / chroma.ts
Created July 2, 2024 17:41 — forked from Artoria2e5/chroma.ts
Maximize chroma in Oklch without changing L and h
// This is just https://bottosson.github.io/posts/gamutclipping/ crudely translated to TS
type Lab = { L: number; a: number; b: number };
type RGB = { r: number; g: number; b: number };
type sRGB = { r: number; g: number; b: number };
function linear_srgb_to_oklab(c: RGB): Lab {
const l = 0.4122214708 * c.r + 0.5363325363 * c.g + 0.0514459929 * c.b;
const m = 0.2119034982 * c.r + 0.6806995451 * c.g + 0.1073969566 * c.b;
const s = 0.0883024619 * c.r + 0.2817188376 * c.g + 0.6299787005 * c.b;
@zemd
zemd / Portal.tsx
Created March 23, 2024 09:27
Minimal sufficient Portal implementation for react.js
"use client";
import { createPortal } from "react-dom";
const getContainer = (container: TPortalProps["container"]) => {
return typeof container === "function" ? container() : container;
};
type TPortalProps = React.PropsWithChildren<{
container?: Element | (() => Element | null) | null;
@zemd
zemd / createProperty.ts
Created February 21, 2023 19:50
class-validator compose
// import {validate, IsEmail, MinLength} from "class-validator";
//
// const EmailProperty = createProperty(
// IsEmail({host_blacklist: ["example.com"]}, {message: "EMAIL IS NOT VALID."}),
// MinLength(40)
// );
//
// class User {
// @EmailProperty()
// email?: string;
@zemd
zemd / keybase.md
Created October 24, 2018 15:09
keybase.md

Keybase proof

I hereby claim:

  • I am zemd on github.
  • I am demetrio (https://keybase.io/demetrio) on keybase.
  • I have a public key ASBxq8_JkCuSLGLuMkDV4IHH6bpS6i1-rHo2pl07qKgSEwo

To claim this, I am signing this object:

@zemd
zemd / postgres-cheatsheet.md
Created August 13, 2018 19:46 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@zemd
zemd / index.html
Last active May 3, 2017 20:51
Golden grid layout using CSS Grid Layout Module Level 1 source https://jsbin.com/ludapar
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
:root {
--grid-gutter-width: calc(24em / 16);
--grid-column-size: calc(100% / 18);
RemoteException {
errorCode: 39,
className: 'java.lang.NullPointerException',
message: null,
stackTrace:
[ StackTraceElement {
declaringClass: 'com.hazelcast.replicatedmap.impl.operation.ContainsKeyOperation',
methodName: 'run',
fileName: 'ContainsKeyOperation.java',
lineNumber: 46 },
@zemd
zemd / RouteChecker.php
Created December 11, 2015 19:00
Twig function extension for router checker
<?php
namespace AppBundle\Twig\Extension;
use Symfony\Component\HttpFoundation\RequestStack;
use Twig_SimpleFunction;
class RouteChecker extends \Twig_Extension
{
/** @var RequestStack */
@zemd
zemd / DataUriExtension.php
Last active November 14, 2017 16:18
Simple twig extension function that returns datauri string for given file
<?php
namespace AppBundle\Twig\Extension;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpKernel\KernelInterface;
/**
* Usage example,
* <img src="{{ data_uri('@AcmeBundle/Resources/public/images/logo.svg') }}">
@zemd
zemd / AppBundle.php
Last active December 11, 2015 17:40
Due to standard symfony's mime guessers doesn't detect proper svg files' mime, there should be some simple way to detect it
<?php
namespace AppBundle;
use AppBundle\File\MimeType\SVGMimeTypeGuesser;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class AppBundle extends Bundle