Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View resouer's full-sized avatar
🏡
Sunnyvale

Lei Zhang (Harry) resouer

🏡
Sunnyvale
View GitHub Profile
@resouer
resouer / gist:10739898
Created April 15, 2014 15:05
Go fibonacci by closure
package main
import "fmt"
// fibonacci 函数会返回一个返回 int 的函数。
func fibonacci() func() int {
var x, y int = -1, 1
return func() int {
x, y = y, x + y
return y
@resouer
resouer / gist:10960783
Created April 17, 2014 07:26
Go lang error interface
package main
import (
"fmt"
"time"
)
type MyError struct {
When time.Time
What string
@resouer
resouer / gist:10990685
Last active August 29, 2015 13:59
Go exercise: HTTP Handlers
package main
import (
"fmt"
"net/http"
)
type String string
type Struct struct {
Greeting string
@resouer
resouer / gist:11145338
Created April 21, 2014 15:07
Go Exercise: Equivalent Binary Trees
package main
import (
"fmt"
"tour/tree"
)
// Walk walks the tree t sending all values
// from the tree to the channel ch.
func Walk(t *tree.Tree, ch chan int) {
@resouer
resouer / gist:27ba839831ca43f44c8e
Created May 22, 2014 04:28
cf-java-client usage example
import org.cloudfoundry.client.lib.CloudCredentials;
import org.cloudfoundry.client.lib.CloudFoundryClient;
import org.cloudfoundry.client.lib.domain.CloudApplication;
import org.cloudfoundry.client.lib.domain.CloudService;
import org.cloudfoundry.client.lib.domain.CloudSpace;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
@resouer
resouer / mq.c
Last active August 29, 2015 14:11 — forked from cloudwu/mq.c
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define QSZ (1 << 10)
#define QMSK (QSZ - 1)
struct queue {
volatile uint32_t head;
dog | bird | cat
----|------|----
foo | foo | foo
bar | bar | bar
baz | baz | baz
@resouer
resouer / pod1.yml
Last active March 13, 2023 08:40
How to implement volumes-from in Kubernetes Pod?
---
apiVersion: v1
kind: Pod
metadata:
name: server
spec:
containers:
- image: resouer/sample:v2
name: war
lifecycle:
//A simplest case to call a independently running remote container runtime (e.g. sever.go).
func (r *runtime) GetContainerLogs(pod *api.Pod, containerID kubecontainer.ContainerID, logOptions *api.PodLogOptions, stdout, stderr io.Writer) error {
args := &Args{Pod: pod, ContainerID: containerID, LogOptions: logOptions}
url := "http://localhost:1234/logs"
message, err := json.Marshal(args)
if err != nil {
log.Fatalf("Fail to marshal args %v", err)
}
apiVersion: v1
kind: Pod
metadata:
name: javaweb-2
spec:
initContainers:
- name: war
image: resouer/sample:v2
command: ["cp", "/sample.war", "/app"]
volumeMounts: