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
@kamal-github
kamal-github / gist:b89802cc06b1fae85666fa0028b9526a
Created August 25, 2016 04:53
Include this module to make your class instance variable accessible to subclass which doesn't declare that variable(ref - http://www.railstips.org/blog/archives/2006/11/18/class-and-instance-variables-in-ruby/)
module ClassLevelInheritableAttributes
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def inheritable_attributes(*args)
@inheritable_attributes ||= [:inheritable_attributes]
@inheritable_attributes += args
args.each do |arg|
@kamal-github
kamal-github / jpaContext.xml
Created October 18, 2016 04:15 — forked from v-r/jpaContext.xml
jpaConfig.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
<context:annotation-config />
<context:component-scan base-package="com.lorem.Todo" />
#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++ {
// 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),
}