Skip to content

Instantly share code, notes, and snippets.

@zonggen
zonggen / pic.go
Created June 17, 2018 21:41
A Tour of Go - Slices Exercise Answer
package main
import "golang.org/x/tour/pic"
func Pic(dx, dy int) [][]uint8 {
s_out := make ([][]uint8, dy)
for index1 := range s_out {
s_in := make ([]uint8, dx)
for index2 := range s_in {
s_in[index2] = uint8 (index1 ^ index2)
@zonggen
zonggen / wordcount.go
Last active June 17, 2018 22:15
A Tour of Go - Maps Exercise Answer
package main
import (
"golang.org/x/tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
m := make (map[string]int)
words := strings.Fields(s)
@zonggen
zonggen / fibonacci.go
Created June 18, 2018 00:36
A Tour of Go - Fibonacci Closure
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
now := 0
next := 1
return func() int {
@zonggen
zonggen / nat.rkt
Last active October 26, 2018 00:38
Represent natural number as a stream using lazy evaluation property
#lang racket
;; natural number representation as a stream using lazy evaluation property
(define natural-number
(letrec
([nat-stream
(lambda (i)
(cons (thunk i) (thunk (nat-stream (+ i 1)))))])
(nat-stream 0)))
@zonggen
zonggen / Dockerfile
Last active September 25, 2019 16:52
Dockerfile for testing FCOS pinger locally
FROM rust:1.36.0
WORKDIR /fedora-coreos-pinger
COPY . .
RUN ./setup.sh
RUN cargo build
COPY ./dist/config.d/10-default-enable.toml /etc/fedora-coreos-pinger/config.d/10-default-enable.toml
@zonggen
zonggen / autocosa_fcos
Last active November 5, 2019 17:15
Script for testing `fcos`
#!/bin/bash
# FCOS_INSTALLER_DIR=/home/abai/git/coreos-installer
# LATEST_BUILD=${PWD}/builds/latest/x86_64
# export COREOS_ASSEMBLER_GIT=/home/abai/git/coreos-assembler
COREOS_PINGER=/home/abai/git/fedora-coreos-pinger
cecho(){
RED="\033[0;31m"
@zonggen
zonggen / mongodb_setup.sh
Created November 4, 2019 16:45
script to install mongodb and mongodb-compass
#!/bin/bash
set -exo pipefail
# first install mongodb
# https://tecadmin.net/install-mongodb-on-fedora/
cat > /etc/yum.repos.d/mongodb.repo <<EOF
[Mongodb]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/amazon/2/mongodb-org/4.2/x86_64/
gpgcheck=1
@zonggen
zonggen / autocosa_rhcos
Created November 5, 2019 17:16
Script for building and testing rhcos
#!/bin/bash
export COREOS_ASSEMBLER_PRIVILEGED=true
# export COREOS_ASSEMBLER_CONFIG_GIT="/srv/ootpa/src/config"
# export COREOS_ASSEMBLER_GIT="/root/coreos-assembler/coreos-assembler"
export COREOS_ASSEMBLER_CONTAINER_RUNTIME_ARGS="-v /etc/pki/ca-trust:/etc/pki/ca-trust:ro -v /etc/pki/tls:/etc/pki/tls:ro"
cecho(){
RED="\033[0;31m"
GREEN="\033[0;32m"
@zonggen
zonggen / quick-start.md
Last active November 19, 2019 20:27
Build and Test Fedora-Coreos-Pinger Locally by Overriding RPM in FCOS
$ git clone https://src.fedoraproject.org/rpms/rust-fedora-coreos-pinger.git
$ cd rust-fedora-coreos-pinger && mkdir output

Then cargo package from the pinger repo and grab the .crate file into /rust-fedora-coreos-pinger.

Modify the spec file with correct version (attached below).

Create a Dockerfile which has the following:

@zonggen
zonggen / note.md
Created November 19, 2019 20:12
Useful scripts when testing pinger
$ sudo systemctl status fedora-coreos-pinger.service
$ uid=$(id -u fedora-coreos-pinger)
$ sudo -H -u \#${uid} bash -c 'echo "I am $USER, with uid $UID"'