Define interfaces at the point of use, not at the point of implementation. — Idiomatic Go best practice
This file contains hidden or 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 utils | |
import ( | |
"context" | |
"time" | |
) | |
// RetryConfig defines settings for retry behavior | |
type RetryConfig struct { | |
Attempts int // Total number of attempts (including initial) |
This file contains hidden or 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 RetryConfig = { | |
attempts?: number; // Total number of attempts (including initial) | |
baseDelayMs?: number; // Starting delay in milliseconds | |
maxDelayMs?: number; // Maximum delay in milliseconds | |
retryIf?: (err: any) => boolean; // Optional: Retry only if this returns true | |
onRetry?: (attempt: number, err: any) => void; // Optional: Called after each failed attempt | |
}; | |
/** | |
* Delays execution for a given number of milliseconds. |
This file contains hidden or 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
// routes/api.php | |
Route::post('/webhook', function (Request $request) { | |
$signature = $request->header('X-Signature'); | |
$calculatedHash = hash_hmac('sha256', $request->getContent(), env('WEBHOOK_SECRET')); | |
return [ | |
'message' => '', | |
]; | |
}); |
This file contains hidden or 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
import Redis, { Callback, Result } from "ioredis"; | |
const SCRIPT_TOKEN_BUCKET = ` | |
-- Returns 1 if allowed, 0 if not | |
local key = KEYS[1] | |
local max = tonumber(ARGV[1]) | |
local refillIntervalSeconds = tonumber(ARGV[2]) | |
local cost = tonumber(ARGV[3]) | |
local now = tonumber(ARGV[4]) -- Current unix time in seconds |
This file contains hidden or 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
VERSION ?= latest | |
REGISTRY ?= registry-name | |
# export SERVER_ADDRESS="111.222.333.444" | |
SERVER_ADDRESS ?= ${SERVER_ADDRESS} | |
# Commands | |
deploy: build save upload run-deploy remove-file |
This file contains hidden or 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 strict'; | |
class PubNub { | |
constructor(config) { | |
this.listener = {} | |
} | |
addListener(params) { | |
this.listener = params; | |
} | |
subscribe(params) { |
This file contains hidden or 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
abstract class LocalStorage { | |
Future<void> add(String key, Object? value); | |
Future<T> read<T>(String key, T defaultValue); | |
Future<void> delete(String key); | |
} | |
class SecureStorage implements LocalStorage { | |
late FlutterSecureStorage storage; | |
SecureStorage() { |
This file contains hidden or 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
import React from "react"; | |
const DebounceInput = () => { | |
const [inputValue, setInputValue] = React.useState(""); | |
const [debouncedInputValue, setDebouncedInputValue] = React.useState(""); | |
const handleInputChange = (event) => { | |
setInputValue(event.target.value); | |
}; |
This file contains hidden or 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
import React, { useState } from "react"; | |
const initialValues = { | |
company: "", | |
position: "", | |
link: "", | |
date: "", | |
note: "", | |
}; |