Skip to content

Instantly share code, notes, and snippets.

View kamal-github's full-sized avatar
:octocat:
Focusing

Kamal Namdeo kamal-github

:octocat:
Focusing
View GitHub Profile
#ex array
a = [3,4,5,1,2]
pivot = -1
(0..a.length-1).each do |i|
if a[i] > a[i+1]
pivot = i+1
break
end
end
@kamal-github
kamal-github / program-for-array-rotation-continued-reversal-algorithm
Created March 27, 2017 16:24
program-for-array-rotation-continued-reversal-algorithm
#ex array
def rev_rotation_by_d(a, d)
d.times do
a << a.shift
end
a
end
def rotation_by_d(a, d)
d.times do
type T struct {
A int
B string
}
t := T{23, "skidoo"}
s := reflect.ValueOf(&t).Elem()
typeOfT := s.Type()
for i := 0; i < s.NumField(); i++ {
@kamal-github
kamal-github / iterm2-solarized.md
Created May 4, 2016 10:58 — forked from kevin-smets/iterm2-solarized.md
iTerm2 + oh my zsh + solarized + Meslo powerline font (OSX)

Solarized

// Func is the type of the function to memoize.
type Func func(key string) (interface{}, error)
type result struct {
value interface{}
err error
}
type entry struct {
res result
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
@kamal-github
kamal-github / graceful.go
Created April 1, 2018 18:06 — forked from peterhellberg/graceful.go
*http.Server in Go 1.8 supports graceful shutdown. This is a small example.
package main
import (
"context"
"log"
"net/http"
"os"
"os/signal"
"time"
)
@kamal-github
kamal-github / priority_queue.go
Created April 6, 2018 08:38
using heap given by go library
// This example demonstrates a priority queue built using the heap interface.
package main
import (
"container/heap"
"fmt"
)
// An Item is something we manage in a priority queue.
type Item struct {
@kamal-github
kamal-github / sync_pool.go
Last active June 19, 2018 09:43
Pool implementation using buffered channel
// Pool holds Clients.
type Pool struct {
pool chan *Client
}
// NewPool creates a new pool of Clients.
func NewPool(max int) *Pool {
return &Pool{
pool: make(chan *Client, max),
}
@kamal-github
kamal-github / GoPattAllStartAtSameTime
Last active July 24, 2018 12:15
Pattern to start all go routines only after all are created
// Pattern to start all go routines only after all are created.
func goRoutine() {
<-start
// do whatever
}
func main() {
start := make(chan, struct{})