Skip to content

Instantly share code, notes, and snippets.

View gomezcabo's full-sized avatar

Juan Gómez gomezcabo

  • Tenerife, España
View GitHub Profile
@gomezcabo
gomezcabo / auth.json
Created January 25, 2022 19:03 — forked from miguelmota/auth.json
AWS Cognito Identity authenticate using cURL
{
"AuthParameters" : {
"USERNAME" : "alice@example.com",
"PASSWORD" : "mysecret"
},
"AuthFlow" : "USER_PASSWORD_AUTH",
"ClientId" : "9..............."
}
@gomezcabo
gomezcabo / recursive-required.ts
Last active April 19, 2024 01:52
Typescript RecursiveRequired generic type
type RecursiveRequired<T> = Required<{
[P in keyof T]: T[P] extends object | undefined ? RecursiveRequired<Required<T[P]>> : T[P];
}>;
type ExampleType = {
a?: number;
b: number;
c?: {
d?: {
e?: number;
type Method = "GET" | "POST" | "PUT" | "DELETE";
type RouteCallback = (request?: MockRequest) => unknown;
interface Route {
method: Method;
url: string;
callback: RouteCallback;
}
type MockRequest = {
/*
https://typescript-exercises.github.io/#exercise=15&file=%2Findex.ts
export class ObjectManipulator {
constructor(protected obj) {}
public set(key, value) {
return new ObjectManipulator({...this.obj, [key]: value});
}
@gomezcabo
gomezcabo / object-map-exercise.ts
Last active June 23, 2021 16:09
Object Map excercise
// https://www.typescriptlang.org/play?ssl=20&ssc=1&pln=1&pc=1#code/MYewdgzgLgBAZgJxAWwKJigglgUwjAXhgAosocEBDAIwBscAuGSsATwEpCA+GAbQDpBZCjXoBdfghwATAK7AcxYiGoArADR8A1jlaaAbpVpjOBHgG8AUDBswVq3jtZjCMQ7Wu2pUWQjB21TwBfTXMg9ktLOFkwYCgscADVHDiAWUoABwAeABUuYk8oAAscAHk1FKgmHPVPJ3SMjIomYi0mJxA4GBzTHmhsMABzWpt3WRwGpoQWtu7HXU7uk24YGK0wEAB3MFrOKxtvX39EFHRMXAgC2xhy5Lj+HAxsPGJisoq49n5kTKVHA2WZm0ukmFFazHwHS6PQMRnGoIQxH07BMIxg7AA3JYgljLKBILBkKxbpVXOZmEwAIyaahMABMmmATAAzDAcXjwNAYGAcJsSXFXPZKg1iET+VBNFoVgADJwAfQyUjgWAAHgwACTmLRBaUGFaUgAMRpgACo3JjIviICB6PxaCBBsRyWKPhLubzxWyLUA
const fromEntries = (iterable: any) => [...iterable].reduce((obj, [key, val]) => {
obj[key] = val
return obj
}, {})
function objectMap<T>(
theObject: T,
keyMapper: (k: keyof T) => string,

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@gomezcabo
gomezcabo / parser
Last active February 16, 2021 09:35
Simple query to SQL parser
// ================================
// Simple query to SQL parser
//
// Copy and paste to https://pegjs.org/online
//
// It parses expressions like:
//
// (flag == True) AND (name == 'Paco' OR (name LIKE '%garcia%') OR (age > 18 AND age <= 45))
//
// ================================
import Sum from './Sum';
describe('Sum', () => {
it('should render', () => (
));
it('should have two inputs to add the numbers', () => (
));
it('should have a button to fire the sum action', () => (
));
it('should have text to show the result', () => (
));
@gomezcabo
gomezcabo / create-fragment-function.js
Last active July 8, 2019 08:24
Why you should give Svelte a try
function create_fragment(ctx) {
var button, t1, p, t2, t3, t4, t5, t6_value = ctx.count1 + ctx.count2, t6, dispose;
return {
c: function create() {
button = element("button");
button.textContent = "Click";
t1 = space();
p = element("p");
t2 = text(ctx.count1);
function Snippet1() {
return 'Hola'
}