Skip to content

Instantly share code, notes, and snippets.

View thisismydesign's full-sized avatar

Csaba Apagyi thisismydesign

View GitHub Profile
@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 / 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
@thisismydesign
thisismydesign / xyz_service_spec.rb
Created September 2, 2021 22:08
Ruby: Use factories for your webmocks /3
allow(XyzService).to receive(:get_entities).and_return(
build(:xyz_service_get_entities_response, body: { data: ... })
)
@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 / cognito-oauth.controller.ts
Last active June 18, 2021 11:30
Cognito via OAuth2 in NestJS: keep user data in your app, let Cognito handle passwords and social login /1
import { Controller, Get, Req, Res, UseGuards } from '@nestjs/common';
import { Response, Request } from 'express';
import { CognitoOauthGuard } from './cognito-oauth.guard';
@Controller('auth/cognito')
export class CognitoOauthController {
constructor(private jwtAuthService: JwtAuthService) {}
@Get()
@UseGuards(CognitoOauthGuard)
@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 / jwt-auth.guard.ts
Last active September 6, 2023 12:42
OAuth2 in NestJS for social login (Google, Facebook, Twitter, etc) /2
import { Injectable } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
@Injectable()
export class JwtAuthGuard extends AuthGuard('jwt') {}