Skip to content

Instantly share code, notes, and snippets.

package service
import (
"testing"
"testing-demo/dependency"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
)
package service
import (
"fmt"
"regexp"
"testing-demo/dependency"
)
type NotificationService interface {
SendTextNotification(number string, message string) (string, error)
package dependency
//go:generate mockgen -package=dependency -destination=sms_provider_mocks.go . SmsProvider
type SmsProvider interface {
SendSMS(number string, content string) (string, error)
}
type smsProviderImpl struct {
}
package dependency
//go:generate mockgen -package=dependency -destination=email_provider_mocks.go . EmailProvider
type EmailProvider interface {
SendEmail(from, to, subject, body string) (string, error)
}
type emailProviderImpl struct{}
func (e *emailProviderImpl) SendEmail(from, to, subject, body string) (string, error) {
@lakshanwd
lakshanwd / controlled_asynchronous.go
Last active July 5, 2023 17:45
controlled asynchronous execution
type Job struct{
result interface{}
}
func (self *Job) execute() {
// do some work
self.result = ....
}
// to be executed parallelly
doParallel := func(ctx context.Context, inputs <-chan Job, output chan<- Job) {
@lakshanwd
lakshanwd / uncontrolled_asynchronous.go
Last active September 3, 2022 05:47
uncontrolled asynchronous execution
type Job struct{
result interface{}
}
func (self *Job) execute() {
// do some work
self.result = ....
}
// an array of jobs
jobs := make([]Job)
@lakshanwd
lakshanwd / synchronous.go
Last active September 3, 2022 05:47
synchronous execution
type Job struct{
result interface{}
}
func (self *Job) execute() {
// do some work
self.result = ....
}
// an array of jobs
jobs := make([]Job)
@lakshanwd
lakshanwd / primes.rb
Last active January 6, 2018 20:13
Calculate nth prime in ruby
def isDivisibe(candidate, by)
candidate % by == 0
end
def isPrimeDivisible(primes, candidate, count)
for e in (0...count)
return false if Math.sqrt(candidate) < primes[e]
return true if isDivisibe(candidate, primes[e])
end
false
@lakshanwd
lakshanwd / primes.go
Last active August 31, 2022 20:53
Calculate nth prime in go
package main
import (
"log"
"math"
"time"
)
func main() {
for i, v := range []int{25000, 50000, 100000, 1000000} {
@lakshanwd
lakshanwd / JsonIgnore.java
Created June 18, 2017 04:11
Annotation for Ignore a field for Gson
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = {ElementType.FIELD})
public @interface JsonIgnore {
}