Posts

Showing posts from 2023

Understanding Java ClassPath

 Java class path ``` java -cp <path_to_jar>:<path_to_current_class> Main.class -> for linux java -cp <path_to_jar>:<path_to_current_class> Main.class -> for windows ``` java -cp ..:. Main .. indicates the previous directory ; | : separator for linux or windows . indicates the current working directory  loading classes from jar to create jar jar cvf <jar_file_name.jar> class1.class class2.class java -cp ..:. /path/to/jar:. Main compiling Java file where dependent classes not in the same directory, javac -cp <path-to-deps.java>:<path_to-current_class> <className> via jar javac -cp <path_to_jar>:<path_to_current_class> <class_name>

How to see logs with out Esc and other gibberish stuff in logs ?

 So when you are trying to read logs, sometimes they look like this, using vim is okay at-least some readability, but less will show awful results.  ESC[34m2023-04-15 04:33:57ESC[0m ESC[33m  TRACEESC[0m [ESC[36mApplicationESC[0m] ESC[37mpid: 562425ESC[0m ESC[34m2023-04-15 04:33:57ESC[0m ESC[35m  DEBUGESC[0m [ESC[36mApplicationESC[0m] ESC[37minteractive: falseESC[0m ESC[34m2023-04-15 04:33:57ESC[0m ESC[35m  DEBUGESC[0m [ESC[36mFileResolverESC[0m] ESC[37mSearching: /server/files ESC[0m if you want to read logs clearly, then you can still use less command with -R flag. less -R <log_file_name> Hope it helps. Thanks. Raja

VIM: Binding a shortcut

 All this time, I do not know how to create my own VIM Bindings. And yes, trying yourself is the only way you learn anything. I want to explain what I have learnt on creating a vim shortcut, so you might get a good headstart. The command I am going to explain is as below map <C-b> :w\|!ruby spec/example_spec.rb <cr> so map: is like you are mapping <custome_key> <series of actions> <C-b>: this stands for CTRL+b  If you want to use Shift, Alt, Cmd(Mac), yes VIM have options for all of that. ``` S-...> shift-key * shift * * <S- * <C-...> control-key * control * * ctrl * * <C- * <M-...> alt-key or meta-key * meta * * alt * * <M- * <A-...> same as <M-...> * <A- * <D-...> command-key (Macintosh only) * <D- * ``` Vim documentation: intro (sourceforge.net) Then :w\|!ruby spec/example_spec.rb<cr> :w is save \|: is like you are joining this command with with another action. !ruby spec/example_spe

Javascript: call vs bind vs apply

 Hello Everyone,  I came across a snippet where code have .call() method. Thought its been a while since I went through their understanding, via this article I am explaining with examples what call, bind and apply does in javascript. Please read comments for understanding. Hope it helps. var obj = { name : "Raja" , sayHello : function ( args ) { console . log ( `Hello ${this . name } , How are you doing ` ); }, }; // call : Changing the context::this scope to the argument we are passing. // normal obj . sayHello () // Hello Raja, How are you doing ? obj . sayHello . call ({ name : "Rajasekhar" }); // Hello Rajasekhar, How are you doing ? var obj = { name : "Raja" , sayHello : function ( args ) { console . log ( `Hello ${this . name } , How are you doing ? ${ args } ` ); }, }; // apply: same as call, we can also pass arguments as 2nd argument obj . sayHello . apply ({ name : "Rajasekhar" }, [ &

GoLang: Quick gist on Difference between Marshal, Unmarshal, Encoder and Decoder

Summary&colon; Marshal&comma; Unmarshal and Encode&comma; Decode Summary: Marshal, Unmarshal and Encode, Decode Marshal: Convert struct/map interface data into JSON. Unmarshal: Convert JSON data into struct/map If reading from a file involved, then you read it in []byte format. To read from a file using os.Open open the file. then read all the data using io.ReadAll method. Encoder and Decoder kind of do reading/writing internally. More like a simplified version of Marshal and Unmarshal. Encoder converts the struct/map into JSON and automatically writes into io.Writer Decoder reads from io.Writer and convert the JSON data into struct/map interface. If there is a byte slice to work with, use Marshal and Unmarshal. If there is an io.Writer or an io.Reader, use Encode and Decode. Ref: https://blog.devgenius.io/to-unmarshal-or-to-decode-json-processing-in-go-expl

GoLang: How to render a web template using Gin framework and render data from map ?

 I have struggled lot of time, to break this into working modal. So below code, is working example where you can have your data in a slice of URLs and render that data using Go Templates.  I am giving a skeleton HTML template, not adding any thing extra.  I believe the code itself is self explanatory, if any questions, please dont hesitate to ask. main.go package main import ( "log" "net/http" "github.com/gin-gonic/gin" ) type URL struct { Name string Url string } var URLs = []URL{ {Name: "google" , Url: "google.com" }, {Name: "yahoo" , Url: "yahoo.com" }, {Name: "gmail" , Url: "gmail.com" }, } func main () { router := gin. Default () router. LoadHTMLGlob ( "templates/*" ) router. GET ( "/" , bookmarks) router. GET ( "/hello" , func (c *gin.Context) { c. HTML (http.StatusOK, "index.tmpl" , gin