This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package repository | |
import ( | |
"context" | |
"fmt" | |
"github.com/jackc/pgx/v5/pgxpool" | |
"github.com/quantum-wealth/search-service/internal/repository/model" | |
"github.com/quantum-wealth/search-service/pkg/pg" | |
"github.com/rs/zerolog/log" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare global { | |
interface SubtleCrypto { | |
timingSafeEqual(a: ArrayBuffer, b: ArrayBuffer): boolean // cloudflare workers has a timingSafeEqual method | |
} | |
} | |
export const generateTOTP = async (secret: string): Promise<string> => { | |
const time = Math.floor(Date.now() / 1000) // get the current time in seconds | |
const timeWindow = 15 * 60 // 15-minute time window | |
const timeStep = Math.floor(time / timeWindow) // calculate the time step |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type Branded<T, K extends string = 'BRANDED_TYPE'> = T & { __opaque__?: K }; | |
type Brand = { | |
User: Branded<string, 'User'>, | |
Product: Branded<string, 'Product'>, | |
} | |
function getUser(userId: Brand['User']) { | |
// get user | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::fs::File; | |
use std::io::{self, prelude::*, BufReader}; | |
#[derive(Clone)] | |
pub struct Property { | |
key: String, | |
value: String, | |
} | |
impl Property { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
sudo rm -rf /var/lib/apt/lists/* | |
apt-get update | |
apt-cache gencaches | |
echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alias az="docker run -it -u $UID:$GID --entrypoint='' -v $(pwd):/build --workdir='/build' -v ${HOME}/.azure:/.azure:rw -v ${HOME}/.azure-devops:/.azure-devops:rw mcr.microsoft.com/azure-cli az" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Source string | |
func (src Source) CopyTo(dest string) error { | |
return CopyFile(dest, string(src)) | |
} | |
func main() { | |
var from Source = "presentation.md" | |
from.CopyTo("/tmp/backup") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type secret string | |
func (s secret) String() string { | |
return "*****" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Action func(context.Context) (string, error) | |
func Retry(action Action, retries int, delay time.Duration) Action { | |
return func(ctx context.Context) (string, error) { | |
for r := 0; ; r++ { | |
response, err := action(ctx) | |
if err == nil || r >= retries { | |
// Return when there is no error or the maximum amount | |
// of retries is reached. | |
return response, err |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
type role uint | |
const ( | |
Unknown role = iota | |
Guest | |
Member | |
Moderator |
NewerOlder