Skip to content

Instantly share code, notes, and snippets.

View thisismydesign's full-sized avatar

Csaba Apagyi thisismydesign

View GitHub Profile
@thisismydesign
thisismydesign / google-oauth.controller.ts
Last active September 6, 2023 12:42
OAuth2 in NestJS for social login (Google, Facebook, Twitter, etc) /3
import { Controller, Get, Req, Res, UseGuards } from '@nestjs/common';
import { Request, Response } from 'express';
import { GoogleOauthGuard } from './google-oauth.guard';
import { JwtAuthService } from '../jwt/jwt-auth.service';
@Controller('auth/google')
export class GoogleOauthController {
constructor(private jwtAuthService: JwtAuthService) {}
@Get()
@thisismydesign
thisismydesign / .env
Created June 18, 2021 09:44
Cognito via OAuth2 in NestJS: keep user data in your app, let Cognito handle passwords and social login /2
OAUTH_COGNITO_ID=abcd123
OAUTH_COGNITO_SECRET=abcd123
OAUTH_COGNITO_REDIRECT_URL=http://localhost:3000/auth/cognito/redirect
OAUTH_COGNITO_DOMAIN=https://test-app.auth.us-east-1.amazoncognito.com
@thisismydesign
thisismydesign / usePageTracking.js
Last active August 15, 2022 14:51
The ultimate guide to Google Analytics /2
import { useEffect } from "react";
import { useLocation } from "react-router-dom";
export const usePageTracking = () => {
const location = useLocation();
useEffect(() => {
window.gtag("event", "page_view", {
page_path: location.pathname + location.search + location.hash,
page_search: location.search,
@thisismydesign
thisismydesign / index.html
Created August 15, 2022 09:03
The ultimate guide to Google Analytics /1
<!DOCTYPE html>
<html lang="en">
<head>
<!-- ... -->
<script
async
src="https://www.googletagmanager.com/gtag/js?id=G-xxxxxxxxxx" >
</script>
<script>
@thisismydesign
thisismydesign / clever_solution.rb
Last active April 17, 2022 21:57
Ruby: how to use self.included meaningfully
module CreateClassMethodsUponInclude
def self.included(base)
# does what we want
end
end
module MyModule
include CreateClassMethodsUponInclude
# ...
@thisismydesign
thisismydesign / grpahql-client.ts
Last active March 27, 2022 19:47
Typed GraphQL queries and results /2 Typed client
import { ApolloClient, gql, InMemoryCache, QueryOptions } from '@apollo/client';
import {
Zeus,
ValueTypes,
ModelTypes,
GraphQLTypes,
InputType,
} from './types/zeus';
@thisismydesign
thisismydesign / install.sh
Last active March 27, 2022 12:48
Typed GraphQL queries and results /1 Install
yarn add --dev graphql-zeus
@thisismydesign
thisismydesign / xyz_service_get_entities_responses.rb
Created September 2, 2021 22:32
Ruby: Use factories for your webmocks /5
FactoryBot.define do
factory :xyz_service_get_entities_response, class: OpenStruct do
skip_create
initialize_with do
new(attributes.except(:body).merge({ body: attributes[:body].to_json }))
end
transient do
...
end
@thisismydesign
thisismydesign / xyz_service_spec.rb
Created September 2, 2021 22:17
Ruby: Use factories for your webmocks /5
allow(XyzService).to receive(:get_entities).and_return(
build(:xyz_service_get_entities_response, page: 2, ids: 10..19, total: 32)
)
@thisismydesign
thisismydesign / xyz_service_get_entities_responses.rb
Created September 2, 2021 22:13
Ruby: Use factories for your webmocks /4
FactoryBot.define do
factory :xyz_service_get_entities_response, class: Hash do
skip_create
initialize_with { { body: attributes[:body].to_json }.stringify_keys }
transient do
ids { [1, 2, 3] }
page { 1 }
count { ids.count }
end