Skip to content

Instantly share code, notes, and snippets.

View capaj's full-sized avatar
🏠
Always working-be it from home or elsewhere

Jiri Spac capaj

🏠
Always working-be it from home or elsewhere
View GitHub Profile
@manuel-schoebel
manuel-schoebel / api-log-route.ts
Last active April 18, 2024 08:32
next.js simple logger
import { NextRequest, NextResponse } from 'next/server';
export async function POST(request: NextRequest, res: NextResponse) {
const data = await request.json();
switch (data.level) {
case 'error':
console.error(data);
break;
case 'warn':
console.warn(data);
@mcollina
mcollina / principles.md
Last active May 18, 2023 18:27
Matteo's Technical principles

Matteo Technical Principles

1. Conway’s Law is paramount.

Any organization that designs a system (defined broadly) will produce a design whose structure is a copy of the organization's communication structure.

In order to design a piece of software we need to “design” the team that is going to produce it.

2. Developer Experience is key to productivity

@sindresorhus
sindresorhus / esm-package.md
Last active May 4, 2024 15:48
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@gaelfoppolo
gaelfoppolo / retrieve_fastlane_session.rb
Created February 10, 2021 14:51
Auto-setting FASTLANE_SESSION on CI
lane :retrieve_fastlane_session do
# runs shell
# this needs SPACESHIP_SKIP_2FA_UPGRADE=1 flag
spaceauth_output = `bundle exec fastlane spaceauth`
# regex the output for the value we need
fastlane_session_regex = %r{Pass the following via the FASTLANE_SESSION environment variable:\n(?<session>.+)\n\n\nExample:\n.+}
new_session = nil
if match = spaceauth_output.match(fastlane_session_regex)
# strip out the fancy formatting
@KonradSzwarc
KonradSzwarc / omit.ts
Created August 1, 2020 08:54
Type-safe omit function.
export const omit = <T extends Record<string, unknown>, K extends [...(keyof T)[]]>(
originalObject: T,
keysToOmit: K,
): {
[K2 in Exclude<keyof T, K[number]>]: T[K2];
} => {
const clonedObject = { ...originalObject };
for (const path of keysToOmit) {
delete clonedObject[path];
@aelbore
aelbore / esm-cjs-modules.md
Last active January 22, 2024 13:57
Publish your npm package as ES Module, and backward compatibility CommonJS

Create your library

  • Initialize project npm init -y
  • Create esm module ./src/esm/my-lib.js
    function addNumber(value, value2) {
      return value + value2;
    }
    
    export { addNumber };

Everything I Know About UI Routing

Definitions

  1. Location - The location of the application. Usually just a URL, but the location can contain multiple pieces of information that can be used by an app
    1. pathname - The "file/directory" portion of the URL, like invoices/123
    2. search - The stuff after ? in a URL like /assignments?showGrades=1.
    3. query - A parsed version of search, usually an object but not a standard browser feature.
    4. hash - The # portion of the URL. This is not available to servers in request.url so its client only. By default it means which part of the page the user should be scrolled to, but developers use it for various things.
    5. state - Object associated with a location. Think of it like a hidden URL query. It's state you want to keep with a specific location, but you don't want it to be visible in the URL.
@sibelius
sibelius / drawerStyled.tsx
Created July 16, 2019 14:54
how to use styled-components instead of clsx
const styles = theme => ({
drawer: {
position: 'absolute',
overflowX: 'hidden',
zIndex: theme.zIndex.drawer + 2,
[theme.breakpoints.up('sm')]: {
position: 'relative',
width: drawerWidth,
flexShrink: 0,
@mfellner
mfellner / graphql.ts
Created July 8, 2019 20:42
Using Apollo Server in Next.js 9 with API route in pages/api/graphql.ts
import { ApolloServer, gql } from 'apollo-server-micro';
const typeDefs = gql`
type Query {
sayHello: String
}
`;
const resolvers = {
Query: {