Skip to content

Instantly share code, notes, and snippets.

@eladchen
eladchen / CustomApolloServer.ts
Created July 10, 2020 07:06
An example of how to access apollo context in formatError() method.
import { Request, Response } from "express";
import { GraphQLError, GraphQLFormattedError } from "graphql";
import { GraphQLServerOptions } from "apollo-server-core/src/graphqlOptions";
import { ApolloServer, ApolloServerExpressConfig as C } from "apollo-server-express";
export type FormatError = (graphQLError: GraphQLError, context: unknown) => GraphQLFormattedError;
export type ApolloServerExpressConfig = Omit<C, "formatError"> & {
formatError?: FormatError;
};
@eladchen
eladchen / CdiDelegatedOpenAPISpecFilter.java
Created April 19, 2020 07:57
An example of OpenAPISpecFilter using CDI
package com.example;
import io.swagger.v3.core.filter.OpenAPISpecFilter;
import io.swagger.v3.core.model.ApiDescription;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.PathItem;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.parameters.Parameter;
import io.swagger.v3.oas.models.parameters.RequestBody;
@eladchen
eladchen / ParseRSAKeys.java
Last active January 15, 2020 13:13 — forked from destan/ParseRSAKeys.java
Parse RSA public and private key pair from string in Java
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
@eladchen
eladchen / host-specific-ssh-key.md
Last active May 20, 2020 14:28
An example of using a specific ssh key for a given host

Generate a dedicated SSH key

SSH key creation

ssh-keygen -t rsa -b 4096 -f ~/.ssh/id-rsa-github -C "github.com"
chmod 600 ~/.ssh/id-rsa-github

Edit ~/.ssh/config:

@eladchen
eladchen / color-conversion-algorithms.js
Created December 24, 2018 16:25 — forked from mjackson/color-conversion-algorithms.js
RGB, HSV, and HSL color conversion algorithms in JavaScript
/**
* Converts an RGB color value to HSL. Conversion formula
* adapted from http://en.wikipedia.org/wiki/HSL_color_space.
* Assumes r, g, and b are contained in the set [0, 255] and
* returns h, s, and l in the set [0, 1].
*
* @param Number r The red color value
* @param Number g The green color value
* @param Number b The blue color value
* @return Array The HSL representation
@eladchen
eladchen / open-ssl-cheet-sheet.md
Last active January 17, 2020 10:20
An exemplary gist for creating self signed ssl certificate.

Combine a key & certificate in a PKCS#12 bundle:

openssl pkcs12 -export -out key.pkcs12 -inkey key.pem -in certificate.pem

Create a PKCS#12 certificate from a pem certificate:

openssl pkcs12 -export -out certificate.pkcs12 -nokeys -in certificate.pem