Skip to content

Instantly share code, notes, and snippets.

View hackintoshrao's full-sized avatar
📚
Exploring AI agents on code search and understanding

Karthic Rao hackintoshrao

📚
Exploring AI agents on code search and understanding
View GitHub Profile
@hackintoshrao
hackintoshrao / fib_test.go
Last active December 26, 2015 06:39
Benchmark test for new version of Fib function
package main
import (
"testing"
)
func BenchmarkFibV1(b *testing.B) {
// run the Fib function b.N times
k := make(map[int]int)
k[0] = 0
@hackintoshrao
hackintoshrao / header.go
Created December 29, 2015 08:59
header middleware
func (h Headers) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
for _, rule := range h.Rules {
if middleware.Path(r.URL.Path).Matches(rule.Path) {
for _, header := range rule.Headers {
if strings.HasPrefix(header.Name, "-") {
w.Header().Del(strings.TrimLeft(header.Name, "-"))
} else {
w.Header().Set(header.Name, header.Value)
}
}
@hackintoshrao
hackintoshrao / kafka_wrapper.go
Last active January 14, 2016 04:48
Just a mock up code which I'm using to test
package main
import (
"encoding/json"
"fmt"
"github.com/Shopify/sarama"
"strings"
"time"
)
@hackintoshrao
hackintoshrao / noconcurrency.go
Created January 15, 2016 03:19
Code without any concurrent execution
package main
import (
"fmt"
"time"
)
func main() {
my_sleep_func()
fmt.Println("Control doesnt reach here till my_sleep_func finishes executing")
@hackintoshrao
hackintoshrao / withconcurrency.go
Last active January 15, 2016 03:42
Simple function called concurrently
package main
import (
"fmt"
"time"
)
func main() {
//by using the go construct the function execution can be made concurrent
go my_sleep_func()
@hackintoshrao
hackintoshrao / syncchallenge.go
Created January 15, 2016 04:38
The Synchronization challenge
package main
import (
"fmt"
"time"
)
func main() {
go my_func()
@hackintoshrao
hackintoshrao / channelforone.go
Last active January 15, 2016 07:41
First time use of channels
package main
import (
"fmt"
)
func main() {
//building a bridge
//its important to specify the data type the bridge would carry
bridgeForOne := make(chan int)
@hackintoshrao
hackintoshrao / non_block_single_write.go
Created January 15, 2016 07:46
non blocking single write into the channel
package main
import (
"fmt"
)
func main() {
//building a bridge for one person
//its important to specify the data type the bridge would carry
bridgeForOne := make(chan int, 1) // specifying the size of the bridge to be one
@hackintoshrao
hackintoshrao / share_go_routines.go
Last active January 15, 2016 12:26
sending data and synchronizing with new goroutine
package main
import (
"fmt"
)
func main() {
//step 1: create the bridge
bridgeForOne := make(chan int)
//call the function in a new goroutine
@hackintoshrao
hackintoshrao / sync_challenge.go
Last active January 15, 2016 12:39
the synchronization challenge
package main
import (
"fmt"
"time"
)
func main() {
bridge := make(chan int) //creating the channel