Posts

HTTP Server on Google Sheets in GAS

Image
Overview This post describes how to build an HTTP server on Google Sheet using Google Apps Script (GAS). HTTP GET 1. Google Sheets > Extensions > Apps Script 2. Add doGet(e) function, like: function doGet ( e ) { var str = 'Hello, ' + e . parameter . name ; var resp = { greeting : str }; return ContentService . createTextOutput ( JSON . stringify ( resp )). setMimeType ( ContentService . MimeType . JSON ); } 3. Deploy > New deployment 4. Select type > Web app > Access = Anyone > Deploy 5. Test % curl -L https://script.google.com/macros/s/xxxxxxx/exec?name=World {"greeting":"Hello, World"} "-L" option is needed to follow the redirected page, otherwise the result will show "Moved Temporarily".  HTTP POST Just like HTTP GET, add doPost(e) function, then deploy the project. The following example takes the name parameter and write it on the sheet. function doPost ( e ) { var name = e . parameter . name ; c

Ansistrano (Ansible + Capistrano): Quick Start

In this post, I am going to try Ansistrano to deploy a file on a web server. (See this post  this post  for detail about Ansible) what is Ansistrano? " ansistrano.deploy and ansistrano.rollback are Ansible roles to easily manage the deployment process for scripting applications such as PHP, Python and Ruby. It's an Ansible port for Capistrano." ( https://github.com/ansistrano/deploy ) install %  ansible-galaxy install ansistrano.deploy ansistrano.rollback create test file % mkdir -p public_html  % echo 'hello' > public_html/index.html  deploy % vim playbook.yml --- - name: deploy code hosts: webservers become: true vars: ansistrano_deploy_from: "{{ playbook_dir }}/public_html/" ansistrano_deploy_to: "/var/www/my-app" ansistrano_keep_releases: 3 ansistrano_deploy_via: "rsync" roles: - ansistrano.deploy See  https://github.com/ansistrano/deploy for the vars to customize as needed. Run the playbook.

Spring Sample on Docker (for M1 Chip)

In this post, I am going to run a sample Spring application, which was created at:  REST with Spring: Quick Start  . Assuming that you have the jar file at: ./build/libs/rest-service-0.0.1-SNAPSHOT.jar Prepare Docker Files % vim Dockerfile FROM arm64v8/openjdk ADD ./build/libs/rest-service-0.0.1-SNAPSHOT.jar greeting.jar CMD java -jar greeting.jar Note: arm64v8/openjdk is for M1 Chip. This solved the following build error: "The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8)" % vim docker-compose.yml version: "3.9" services: web: build: . ports: - "80:8080" Build & Run % docker-compose up --build % curl http://localhost/greeting {"id":1,"content":"Hello, World!"}

Kubernetes: Declarative vs Imperative (Nginx Example on Minikube)

Image
In this post, I am going to run a Nginx example on Minikube in two ways: 1. declarative: kubectl apply -f [yaml] 2. imperative: kubectl create & expose declarative: kubectl apply -f [yaml] With a declarative way, you can define the resources as yamls and apply them. This is preferable in a long run, but could be tedious if you just want to run it as a test. % cat deploy.yaml apiVersion: apps/v1 kind: Deployment metadata:   labels:     app: nginx   name: nginx spec:   replicas: 1   selector:     matchLabels:       app: nginx   template:     metadata:       labels:         app: nginx     spec:       containers:       - image: nginx         name: nginx % cat service.yaml apiVersion: v1 kind: Service metadata:   labels:     app: nginx   name: nginx spec:   ports:   - port: 80     protocol: TCP     targetPort: 80   selector:     app: nginx   type: NodePort % kubectl apply -f deploy.yaml % kubectl apply -f service.yaml open nginx % minikube service nginx ... | default   | nginx |       

kubectx & kubens: Quick Start

This post shows examples of kubectx & kubens. install % brew install kubectx This will install both kubectx and kubens. kubectx kubectx help manage k8s contexts. % kubectx -h USAGE:   kubectx                       : list the contexts   kubectx <NAME>                : switch to context <NAME>   kubectx -                     : switch to the previous context   ... Listing the contexts is as simple as follows: % kubectl config get-contexts CURRENT   NAME        CLUSTER     AUTHINFO    NAMESPACE *         kind-kind   kind-kind   kind-kind              minikube    minikube    minikube    default % kubectx kind-kind minikube Change the context: % kubectx minikube Switched to context "minikube". % kubectx          kind-kind minikube % kubectx - Switched to context "kind-kind". % kubectx   kind-kind minikube kubens kubens help manage k8s namaepaces (ns). % kubens -h      USAGE:   kubens                    : list the namespaces in the current context   kubens

Minikube Installation for M1 Mac

Image
In this post, I am going to try Minikube on Mac with M1 Chip. what is minikube Minikube is k8s tool running on a local machine. See also kind  for multi cluster implementation for local k8s. install % curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-darwin-arm64 % install minikube-darwin-arm64 /usr/local/bin/minikube % minikube version  minikube version: v1.20.0  Note: Installing with brew fails due to a different binary as of 2021-05-24. % brew install minikube % minikube version ❌  Exiting due to MK_WRONG_BINARY_M1: You are trying to run amd64 binary on M1 system. Please use darwin/arm64 binary instead (Download at https://github.com/kubernetes/minikube/releases/download/v1.20.0/minikube-darwin-amd64.) % brew uninstall minikube start The default driver 'virtualbox' is not supported on M1, but you can use 'docker' driver:  https://minikube.sigs.k8s.io/docs/drivers/docker/  . Make sure docker is running, and then specify the driver when starting

Java Data Structure Cheat Sheet - Hash Table

HashMap is the hash table implementation in Java. Check  this post  for time complexity. https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html The methods include: V put(K key, V value) boolean containsKey(Object key) V get(Object key) V remove(Object key) Set<K> keySet() etc Example import java.util.HashMap; import java.util.Map; public class HashMapExample {   public static void main(String[] args ) {     Map<String, Integer> map = new HashMap<String, Integer>();     map .put( "a" , 1);     map .put( "b" , 2);     map .put( "c" , 3);     System. out .println( map .get( "a" )); // 1     System. out .println( map .get( "z" )); // null     if ( map .containsKey( "b" )) {       System. out .println( map .get( "b" )); // 2     }     for (String key : map .keySet()) {       int val = map .get( key );       System. out .println( val ); // 1, 2, 3 (in undefined order)