the-gpl

command module
v0.0.0-...-979f466 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

README

the-gpl

Build Status

The Go Programming Language is a seminal programming language authored by Avengers: Alan A. A. Donovan and Brian W. Kernighan. This git repo is an attempt to share my learning from this book to showcase problems posed in the book and then some. The source-code by authors is on GitHub at gopl.io.

You can experience the deployed artifacts on the web as:

  1. GPC Cloud Run the-gpl-book service.
  2. As docker container image.
  3. Curls eg: curl https://the-gpl.com/who

Running from Web

You can start a webserver and see simple web-server examples. The command is:

$ the-gpl server -port=8080 # start a web server at port 8080.

Running from CLI

Assuming, the program is installed locally as the-gpl you can access several methods using a CLI. To use autocompletion source the-gpl-autocomplete.sh. Some examples are:

Google API examples

To use the Google Dialogflow Agent and Speech-to-text set up:

  1. GOOGLE_APPLICATION_CREDENTIALS shell variable
  2. Enable APIs

Here are commands to communicate with the Dialogflow Agent.

$ the-gpl # Prints the help of all modules
$ the-gpl bot -project=gcp-project-id # Will do a short conversation with an agent. 
$ the-gpl bot -project=gcp-project-id -chat=true # Can send messages from stdin
$ the-gpl bot -chat=true -project=gcp-project-id -lang=en-US # Chat with an agent in en-US

To run live-caption speech to text first start a microphone stream on RTP port, and then use the-gpl to listen and apply STT.

$ ffmpeg -f avfoundation -i ":1" -acodec pcm_s16le -ar 48000 -f s16le udp://localhost:9999 # macOS Start microphone streaming
$ the-gpl stt -port=9999 # Will listen to RTP stream on port 9999 for 2 minutes and transcribe in real time
Simple Examples from book

Use these commands to run utilities:

  1. bits: That counts number of 1 bits in a Hex input
  2. Array examples using mas i.e., maps, arrays and string utilities.
  3. Temperature conversions among °F, °K and °C.
  4. Measure disk usage in a directory using command du
  5. Saving Lissajous gif to a file.
$ the-gpl bits -n=0xBAD0FACE # will count 1 bits in n
$ the-gpl mas -fn=array # Tests array
$ the-gpl mas -fn=comp -n1=123 -n2=345 # Compare n1 and n2

# Temperature utilities
$ the-gpl temp -c=12 -f=12 -k=12 # Converts 12°C to °C/°F/°K
$ the-gpl degrees -c=12°F -f=12°K -k=12°C # Converts 12°C to °C/°F/°K

# du: Disk Usage calculates size of all files in a directory recursively, using go-routines
$ the-gpl du -dir=$HOME/gocode

# Output a Lissajous graph to -file of size 1024 pixels 20 frames and 10 cycles
$ the-gpl lissajous -file ~/Downloads/lis.gif -size=1024 -frames=20 -cycles=10
Crawling Examples

These commands fetch a website and does various operations on it.

# Parse various HTML content of sites URL
$ the-gpl parse -type=outline -site=https://www.airbnb.com # Creates a summary outline of a page
$ the-gpl parse -type=links -site=https://images.google.com #  Prints all links on a webpage
$ the-gpl parse -type=images -site=https://www.yahoo.com # Fetches image URLs in a site
$ the-gpl parse -type=pretty -site=https://www.google.com
$ the-gpl parse -type=crawl -site=https://www.google.com  -dir=/Users/guest/Downloads # Crawl pages to /Users/guest/Downloads/www.google.com 
Simple Servers and Clients
# Server-client 
$ the-gpl service -sp="clock:9999"  # -sp servicePort start clock  service on port 9999
$ the-gpl client  -cp="clock:9999"  # -cp clientPort  start clock  client  on port 9999
$ nc localhost 9999                 # use Mac netcat 'nc' client on port 9999
$ the-gpl service -sp="reverb:9998" # -sp servicePort start reverb service on port 9998
$ the-gpl client  -cp="reverb:9998" # -cp clientPort  start reverb client  on port 9998
$ the-gpl service -sp="chat:9997"   # starts a chat service. Join using:
$ nc localhost 9997                 # Joins chat session as a client

Building from Local Machine

The GPL application can be built using:

  1. The plain old go install
  2. GCP Cloud run container.
  3. As a docker image on docker.com.

See The GPL Docker wiki for docker steps,

Mandelbrot

Here are some sample Mandelbrot fractals created.

Color

Documentation

Overview

Package main is the-gpl entry point for all chapters.

Directories

Path Synopsis
Package chapter1, Tutorial, comprises miscellaneous examples.
Package chapter1, Tutorial, comprises miscellaneous examples.
bot
channels
Package channels provides basic examples of channels for functions that can be called as goroutine.
Package channels provides basic examples of channels for functions that can be called as goroutine.
dup
Package dup is a placeholder for example that prints duplicate lines.
Package dup is a placeholder for example that prints duplicate lines.
lissajous
Package lissajous outputs a .png image to a writer.
Package lissajous outputs a .png image to a writer.
livecaption
Package livecaption implements Google speech-to-text API.
Package livecaption implements Google speech-to-text API.
mas
Package mas is Example of Maps Arrays and Slices
Package mas is Example of Maps Arrays and Slices
structs
Package structs provide example of a struct and its receiver or pointer receiver methods.
Package structs provide example of a struct and its receiver or pointer receiver methods.
Package chapter2, Program Structure, features bit-counting and temperature conversion utilities.
Package chapter2, Program Structure, features bit-counting and temperature conversion utilities.
bitsCount
Package bitsCount counts bits in a integer
Package bitsCount counts bits in a integer
tempConv
Package tempConv provides conversion among Celsius, Kelvin and Fahrenheit using methods.
Package tempConv provides conversion among Celsius, Kelvin and Fahrenheit using methods.
Package chapter3 provides utilities for mandelbrot and surface plots.
Package chapter3 provides utilities for mandelbrot and surface plots.
Package chapter4 provides examples for http.Get, slices and composite literals.
Package chapter4 provides examples for http.Get, slices and composite literals.
Package chapter5 is Functions, covers examples and exercises in the chapter.
Package chapter5 is Functions, covers examples and exercises in the chapter.
Package chapter6, Methods, defines a IntSet utility.
Package chapter6, Methods, defines a IntSet utility.
Package chapter7, Interfaces, defines bytes, words and line counter writer interfaces that can be used as part of fmt methods.
Package chapter7, Interfaces, defines bytes, words and line counter writer interfaces that can be used as part of fmt methods.
Package chapter8, Goroutines and Channels, provides examples of sharing by communicating.
Package chapter8, Goroutines and Channels, provides examples of sharing by communicating.
search
Package search composes a search request with user IP and user query.
Package search composes a search request with user IP and user query.
search/google
Package google implements a Search using a deprecated API.
Package google implements a Search using a deprecated API.
search/userip
Package userip is similar to golang.org/x/blog/content/context/userip
Package userip is similar to golang.org/x/blog/content/context/userip
df
Package df Package bot establishes a client session with a Dialog Flow agent or bot associated with GCP project.
Package df Package bot establishes a client session with a Dialog Flow agent or bot associated with GCP project.
Package logger defines a uniform logger for http handler functions.
Package logger defines a uniform logger for http handler functions.
mocks
df
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
serve
shell
Package shell provides interface for displaying help and executing
Package shell provides interface for displaying help and executing
web
Package web serves a sample web server that hosts URLS to
Package web serves a sample web server that hosts URLS to

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL