Skip to content

Instantly share code, notes, and snippets.

View vinodhalaharvi's full-sized avatar

Vinod Halaharvi vinodhalaharvi

View GitHub Profile
@vinodhalaharvi
vinodhalaharvi / gist:7de9bd3694ff5af63d88ba23600267ae
Created September 30, 2025 12:49
Segregate interface type functional binding approach to testing
// MockDatabase provides test database functionality
type MockDatabase struct {
// Processor related mocks
InsertProcessorFunc func(ctx context.Context, description string, physicalCores, logicalCores int) error
ListProcessorsFunc func(ctx context.Context, unverifiedOnly bool) ([]database.ProcessorRecord, error)
// Add other mock functions as needed
}
@vinodhalaharvi
vinodhalaharvi / gist:ef522bcc7facee153b81b55a12113066
Last active December 20, 2024 20:25
Applicative Functors as in Category Theory
package main
import (
"fmt"
"strings"
)
// Applicative represents a container for SVG elements that can be composed
type Applicative struct {
Elements []Element
package main
import (
"fmt"
"net"
"time"
)
// TCPHandler is an interface for handling TCP connections
type TCPHandler interface {
package main
import (
"context"
"database/sql"
"errors"
"testing"
"time"
)
@vinodhalaharvi
vinodhalaharvi / openWeather_Swagger.yaml
Created February 17, 2024 15:54
partial swagger file for Open Weather
openapi: 3.0.0
info:
title: OpenWeather Proxy API
description: This API provides processed weather data from OpenWeather One Call API 3.0.
version: "1.0.0"
servers:
- url: http://localhost:8080/api/v1
description: Development server
paths:
/weather:
@vinodhalaharvi
vinodhalaharvi / yamlToJson.go
Created February 16, 2024 13:29
yaml for json pretty print
package main
import (
"encoding/json"
"fmt"
"gopkg.in/yaml.v3"
)
func main() {
yamlString := `
@vinodhalaharvi
vinodhalaharvi / ConcurrentURLFetcher.go
Created January 24, 2024 21:30
Fetch URL Concurrently
package main
import (
"fmt"
"io/ioutil"
"net/http"
"sync"
)
// URLFetcher is a type for functions that fetch from a URL.
package main
import "fmt"
type TreeNode struct {
Val int
Left *TreeNode
Right *TreeNode
}
@vinodhalaharvi
vinodhalaharvi / GraphTest.java
Created June 2, 2022 23:14
There are literally tens of graph implementations, I like to do it my way.
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
class Node {
private final int id;
Set<Node> adj = new HashSet<>();
import java.util.ArrayDeque;
import java.util.HashSet;
import java.util.Objects;
import java.util.Optional;
import java.util.Queue;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
class EventListener {