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
@capaj
capaj / zodSchemaDefaults.ts
Created September 20, 2022 12:51
generates default object for a given zod schema, you can supply an object to override the defaults
import { z } from 'zod'
/**
* generates default object for a given zod schema, you can supply an object to override the defaults
*/
export const zodSchemaDefaults = <Schema extends z.ZodFirstPartySchemaTypes>(
schema: Schema,
override?: Partial<z.TypeOf<Schema>>
): z.TypeOf<Schema> => {
if (override !== undefined && typeof override !== 'object') {
@capaj
capaj / AuthyToOtherAuthenticator.md
Last active February 8, 2022 14:55 — forked from gboudreau/AuthyToOtherAuthenticator.md
Export TOTP tokens from Authy to Authier

Generating Authy passwords on other authenticators


There is an increasing count of applications which use Authy for two-factor authentication. However many users who aren't using Authy, have their own authenticator setup up already and do not wish to use two applications for generating passwords.

Since I use 1Password for all of my password storing/generating needs, I was looking for a solution to use Authy passwords on that. I couldn't find any completely working solutions, however I stumbled upon a gist by Brian Hartvigsen. His post had a neat code with it to generate QR codes for you to use on your favorite authenticator.

His method is to extract the secret keys using Authy's Google Chrome app via Developer Tools. If this was not possible, I guess people would be reverse engineering the Android app or something like that. But when I tried that code, nothing appeared on the screen. My guess is that Brian used the

document.body.querySelectorAll('input').forEach((inputEl) => {
inputEl.addEventListener('input', (ev) => {
console.log('ev', ev)
})
})
@capaj
capaj / PostTypesTweaked.ts
Created December 12, 2021 10:30
prisma-oop
import { Field, ID, ObjectType, Int } from 'type-graphql'
import { UserGQL } from './User'
import { Prisma, PrismaClient, Post, prisma } from '@prisma/client'
import { plainToInstance } from 'class-transformer'
import { prismaClient } from './../../prisma/prismaClient'
type Constructor<T> = {
new (): T
relations: Record<keyof Prisma.PostInclude, Function>
baseRelations: Record<keyof Prisma.PostInclude, Function>
@capaj
capaj / gentest.ts
Created November 21, 2021 17:09
generate test on the fly
import path from 'path'
import fs from 'fs'
const jestSpecTemplate = ({
moduleName,
fnName,
args
}: {
moduleName: string
fnName: string
[INFO] 19:02:10 Restarting: /home/capaj/work-repos/interview-tests/KrakenFiatPaymentsTest/src/fiatWorker.ts has been modified
Deposited for Jadzia Dax: count=6 sum=3160.73 USD
Deposited for James T. Kirk: count=5 sum=2087.89 USD
Deposited for Jean-Luc Picard: count=3 sum=1573.55 USD
Deposited for Jonathan Archer: count=7 sum=3763.39 USD
Deposited for Leonard McCoy: count=3 sum=839.65 USD
Deposited for Montgomery Scott: count=4 sum=2360.65 USD
Deposited for Spock: count=10 sum=5312.81 USD
Deposited for Wesley Crusher: count=3 sum=1694.19 USD
Deposited without known user: count=4 sum=1786.67 USD
import moment from 'moment-timezone'
export const shiftUtcDayTimeToTimezone = (
utcDayTime: string,
timezone: string
) => {
const offsetMinutes = moment.tz(moment.utc(), timezone).utcOffset()
const [hours, minutes] = utcDayTime.split(':')
const quotient = Math.floor(offsetMinutes / 60)
import moment from 'moment-timezone'
export const shiftUtcDayTimeToTimezone = (
utcDayTime: string,
timezone: string
) => {
const offsetMinutes = moment.tz(moment.utc(), timezone).utcOffset()
const [hours, minutes] = utcDayTime.split(':')
const quotient = Math.floor(offsetMinutes / 60)
const remainder = offsetMinutes % 60
@capaj
capaj / init-ts-tdd
Created January 2, 2020 00:30
init-ts-tdd
git init
npm init
adds gitignore with node_modules
creates a file index.ts and index.spec.ts
creates tsconfig.json
runs be-pretty
@capaj
capaj / schema.js
Last active November 5, 2018 11:30
schema.ts
@Schema()
class SuperSchema {
@Query({type: [PropertyModel]})
async allProperties(first: number, filter: FilterInput): Promise<PropertyModel[]> {
const query = PropertyModel.query()
if (filter) {
query.where('appraisedValue', '<', filter.appraisedValue.lessThan)
}
if (first) { query.limit(first) }
return query