Skip to content

Instantly share code, notes, and snippets.

View ru-rocker's full-sized avatar

ru rocker ru-rocker

View GitHub Profile
@ru-rocker
ru-rocker / model.go
Created February 20, 2017 08:27
lorem-grpc model layer
package lorem_grpc
import (
"context"
"github.com/ru-rocker/gokit-playground/lorem-grpc/pb"
)
//Encode and Decode Lorem Request
func EncodeGRPCLoremRequest(_ context.Context, r interface{}) (interface{}, error) {
req := r.(LoremRequest)
@ru-rocker
ru-rocker / endpoints.go
Created February 20, 2017 08:27
lorem-grpc endpoints layer
package lorem_grpc
import (
"github.com/go-kit/kit/endpoint"
"context"
"errors"
)
//request
@ru-rocker
ru-rocker / service.go
Created February 20, 2017 08:27
lorem-grpc service layer
package lorem_grpc
import (
gl "github.com/drhodes/golorem"
"strings"
"errors"
"context"
)
var (
@ru-rocker
ru-rocker / lorem.proto
Created February 20, 2017 08:26
protob descriptor
syntax = "proto3";
package pb;
service Lorem {
rpc Lorem(LoremRequest) returns (LoremResponse) {}
}
message LoremRequest {
string requestType = 1;
int32 min = 2;
@ru-rocker
ru-rocker / CyclicRotation.java
Last active January 27, 2017 16:34
codility example
public class CyclicRotation {
public int[] solution(int[] A, int K) {
int [] result = new int[A.length];
int idx = K % A.length;
for(int i = 0 ; i < idx; i++){
result[i] = A[A.length - idx + i];
}
for(int j = idx; j < A.length; j++){
@ru-rocker
ru-rocker / SwaggerConfig.java
Last active January 27, 2017 11:49
swagger configuration
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())
.paths(PathSelectors.regex("/api/.*")).build().apiInfo(apiInfo());
}
@ru-rocker
ru-rocker / command.sh
Last active February 1, 2017 12:21
Collection of useful command
cd $GOPATH
GOOS=windows GOARCH=386 go build -o runner.exe ru-rocker.com/runner/
# rename file using git
git mv --force Foo.js foo.js
Supplier<Stream<Integer>> supplier = () -> Stream.of(1, 2, 3, 4);
boolean anyMatch = supplier.get().anyMatch(s -> s > 0);
System.out.println(anyMatch);// true
boolean noneMatch = supplier.get().noneMatch(s -> s > 0);
System.out.println(noneMatch);// false
Stream<Integer> stream = Stream.of(1, 2, 3, 4);
boolean anyMatch = stream.anyMatch(s -> s > 0);
System.out.println(anyMatch);
// true
boolean noneMatch = stream.noneMatch(s -> s > 0);
System.out.println(noneMatch);
// java.lang.IllegalStateException: stream has already been operated upon or closed
@ru-rocker
ru-rocker / StreamReduceFourthSample.java
Last active December 18, 2016 13:33
Sample usage of reduce operation in Java Stream API with three parameters
String carModels = cars.parallelStream()
.map(c1 -> c1.getModel())
.distinct()
.reduce("Renault",
(s1, s2) -> {
System.out.printf("s1: %s and s2: %s \n", s1, s2);
return s1 + "|" + s2;
},
(com1, com2) -> {
System.out.printf("com1: %s and com2: %s \n", com1, com2);