Showing posts with label Web. Show all posts
Showing posts with label Web. Show all posts

Tuesday, February 18, 2025

How I Avoid Doomscrolling/Doomsurfing

For those not familiar with term, doomscrolling, Wikipedia describes it as:

Doomscrolling or doomsurfing is the act of spending an excessive amount of time reading large quantities of news, particularly negative news, on the web and social media. (Wikipedia)

There are negative consequences of doomscrolling on people's mental and physical health such as increased stress, anxiety, depression, isolation, etc.  Suggestions on how to break the habit and combat its negative effects include limiting the amount of screen time and seek out more positive news.   In our current environment there are numerous powerful forces working to keep people doomscrolling such as corporations prioritizing engagement (keeping you hooked), publishers vying for your attention (often through negative news), and political leaders fueling fear.

Although I don't spend much time on social media, I do regularly read the news, follow current events and various feeds on topics I'm interested in.   To avoid doomscrolling some people are able to stop following the news altogether, but I find that to be difficult to achieve for myself.  Since publishers don't provide readers much control over what is shown, I built my own news aggregation site: news.lazyhacker.com.

Now, instead of seeing what publishers want me to see:



Or these set of headlines  from feeds (which also illustrate how much political news is pushed on to us:

- Judge Chutkan rejects call from Democratic AGs for temporary restraining order blocking DOGE’s access to federal data - CNN
- Russia and US agree to work toward ending Ukraine war in a remarkable diplomatic shift - The Associated Press
- Pope Francis, still hospitalized, has pneumonia in both lungs - The Washington Post
- Fact Sheet: President Donald J. Trump Expands Access to In Vitro Fertilization (IVF) - The White House
- National Science Foundation fires roughly 10% of its workforce - NPR
- 'Executive order' cited as reason for sudden closure of JFK Library in Boston - WCVB Boston
- Ensuring Accountability for All Agencies - The White House
- Native American Activist Leonard Peltier Released From Prison - The New York Times
- Donald Trump signals Ukraine should hold elections as part of Russia peace deal - Financial Times
- Senate GOP pushes ahead with budget bill that funds Trump's mass deportations and border wall - The Associated Press
- Brazil Charges Bolsonaro With Attempting a Coup - The New York Times

I see a variety of headlines based on my own preferences:

- Pope Francis, still hospitalized, has pneumonia in both lungs - The Washington Post
- National Science Foundation fires roughly 10% of its workforce - NPR
- 'Executive order' cited as reason for sudden closure of JFK Library in Boston - WCVB Boston
- Rare deep-sea ‘doomsday fish’ washes up on Canary Islands coast - The Independent
- Hamas to release 6 more hostages, bodies of 4 others - ABC News
- Dramatic video shows moment Delta plane flipped after landing in Toronto - ABC News
- Futures Rise After S&P 500 Hits High; Two Earnings Losers Late - Investor's Business Daily
- Nvidia’s 50-series cards drop support for PhysX, impacting older games - Ars Technica
- AMD Ryzen AI Max+ 395 Analysis - Strix Halo to rival Apple M4 Pro/Max with 16 Zen 5 cores and iGPU on par with RTX 4070 Laptop - Notebookcheck.net
- Nintendo is killing its Gold Points loyalty program - Engadget
iPhone 17 Air Leaks Look More Like Google Pixel - Forbes

The source of the headlines can come from different feeds from places like Google News, Reddit, and any source that offers a RSS feed.  The site takes the headlines from the feeds and run it through a set of rules that I defined in natural language (e.g. "Remove political headlines, headlines about political figures or those who are not politicians but politically active.") to strip out any headlines that I might not want to see.  I purposely don't show any images and only update the site every couple of hours.  The former reduces the chance of me wanting to read an article because of the image rather then the substance and the latter reduces my urge to constantly refresh because I know that there will be no new headlines for another 2 hours.

Now, instead of finding myself being lured into doomscrolling, I can go to my site and see something like this:


Saturday, February 15, 2025

WebAssembly (WASM) with Go (Golang) Basic Example

I first wrote about using Go for WebAssembly (WASM) 6 years ago right before the release of Go 1.11 which was the first time Go supported compiling to WASM.  Go's initial support for WASM had many limitations (some I listed in my initial article) which have since been addressed so I decided to revisit the topic with some updated example of using Go for WASM.

Being able to compile code to WASM now allow:

  • Go programs to run in the browser. 
  • Go functions to be called by JavaScript in the browser.
  • Go code to call JavaScript functions through syscall/js.
  • Go code access to the DOM.

Setup

Go's official Wiki now has an article on the basics of using Go for WASM including how to set the compile target and setup.  

A quick summary of the steps to the process:

Compile to WASM with the output file ending as wasm since it's likely that the mime type set in /etc/mime probably use the wasm extension.

> GOOS=js GOARCH=wasm go build -o <filename>.wasm

Copy the JavaScript support file to your working directory (wherever your http server will serve it from).  It's necessary to use the matching wasm_exec.js for the version of the Go being used so maybe put this as part of the build script.

> cp "$(go env GOROOT)/lib/wasm/wasm_exec.js" .

Then add the following to the html file to load the WASM binary: 

<script src="wasm_exec.js"></script>
<script>
    const go = new Go();
    WebAssembly.instantiateStreaming(fetch("main.wasm"), go.importObject).then((result) => {
                go.run(result.instance);
    });
</script>

Keeping It Running

It is a good starting point but the Go code example is too simplistic.  It only demonstrates that the WASM binary that is created by Go can be loaded by having write a line to the browser's console.  The Go program basically gets loaded by the browser, prints a line and exits.   Most of the time, it's probably desirable to have the WASM binary get loaded and stay running.  This can be achieved by either having having a channel that keeps waiting:

c := make(chan struct{}, 0)
<- c

or even easier:

select {}

Have either of these at the end of main() will keep the program alive after it gets loaded into the browser.

In Place of JavaScript

Being able to access the DOM excites me the most because it allows me to avoid writing JavaScript followed by being able to run Go programs in the browsers.  While I think the inter-op between Go and JavaScript is probably the most practical application, it's not something I've had to do much since I'm not a front-end developing doing optimizations or trying to reuse Go code between the front-end and back-end.

I don't mind using HTML for UI development or even CSS, I'm just personally not a fan of JavaScript.  This isn't to say that it is bad, just I prefer other languages just like some people prefer C++, Java, Python, etc.  I don't have fun writing JavaScript like I do with with Go if though I know JavaScript.

Take a basic example of a web app (index.html) with a button to illustrate:

<!DOCTYPE html>                                                                 
  <html lang="en">                                                                  
  <head>                                                                          
      <meta charset="UTF-8">                                                        
      <meta name="viewport" content="width=device-width, initial-scale=1.0">        
      <title>Example</title>                                         
  </head>                                                                           
  <body>                                                                          
                                                                                  
      <button id="myButton">Click Me</button>                                                                                                     
                                                                                  
  </body>
  </html>

JavaScript is used to attach an event to it so that when the button is clicked, an alert message pops up:

    // Select the button element                                            
    const button = document.getElementById('myButton');                     
                                                                                  
    // Attach an event listener to the button                               
    button.addEventListener('click', function() {                           
       alert('Button clicked!');                                           
    }); 

With WASM, the JavaScript can be replaced with Go code:

 package main                                                                       
                                                                                     
  import (                                                                                                                                                   
                                                                                     
      "honnef.co/go/js/dom/v2"                                                       
  )                                                                                  
                                                                                  
  func main() {                                                                   
                                                                                  
      document := dom.GetWindow().Document()                                      
           
      // Select the button element                                                                       
      button := document.GetElementByID("myButton")                               
                                                                                  
      // Attach an event listener to the button
      button.AddEventListener("click", false, func(dom.Event) {                   
          dom.GetWindow().Alert("Button clicked!")                                
      })                                                                          
                                                                                  
      select {}
  }

In this case, the Go code looks extremely similar to the JavaScript code because I'm using the honnef.co/go/js/dom/v2 package.  It is a Go binding to the JavaScript DOM APIs and I find that it makes it more convenient than using syscall/js directly.

Why do I prefer this over writing JavaScript especially when they look so similar?   The main reason is that most code is not just calling an API.  There's other logic that are implemented and for those, I can use Go and Go's libraries along with the benefits of a compiled and type safe language. 

There are still things that needs to be considered before just using Go and WASM for general consumer production web app.  The binary size can be large so it needs to be considered for your audience, but if I'm doing my own hobby project for myself or corporate apps where I know the user have fast connections, or if app performance and functionality outweighs the initial download and memory usage, I'd try to use it.

Monday, February 10, 2025

Using AI/LLM to Implement a News Headline Filter

There are news topics that I'd rather avoid being bombarded with, but options for filtering headlines on the news sites are generally very limited.  You can tell Google News to block certain sources and there's an "fewer like this" option which doesn't seem to do anything, but neither will block topics (e.g."politics", "reality TV shows", etc. ) so you still end up getting bombarded with things you don't want to see even in your "personalized" views.  Fortunately, sites like Google News provide RSS feeds that makes it easier to get the list of headlines, links and descriptions and avoid trying to scrape websites which can be brittle as the sites can change their layout at any time.

I decided to write my own filter take out things that I'm not interested in and publish the result to a site that I can access from any browser.  The simplest way (and one that doesn't even need site to host the result) is to have a list of blocked words and drop any headlines with those words.  As long as the app can access the RSS feed even a mobile app can easily handle this kind of filtering, but creating and maintaining an effective block list becomes a challenge.  A political news article isn't going to be "Political Article on City Council Votes On Artificial Turf at Parks.  This is a good use case for using a language model to categorize a headline instead of using a keyword filter.

I created a prompt in natural language explaining what I don't want to see along with some additional details to add to common definitions and then sent my instructions with the list of headlines to the language model and have it return a filtered list:
Remove all political headlines.  Headlines that includes political figures, and celebrities who are active in politics such as Elon Musk should also be removed.
Being able to use natural language to handle categorization makes it so much easier to build the app.  The categorization would've been the most challenging part of the project, but the LLM allowed me to get good results very quickly (took just a few minutes to get the first results but some more time to tweak the prompt).  Another benefit with the large language models such as Gemini is that it understand multiple languages so while I gave my instructions in English, it can filter headlines in French, Chinese, Japanese, etc.

Using an language model does mean giving up some control such as relying on what the model interprets "political" to mean.  Prompts can help refine the model's interpretation but sometimes a headline makes it through the filter and it is not as easy to determine compared to being able to see the algorithm and determine the reasoning.

I encountered a problem where the LLM's response stopped midway.  This was because  LLMs have limits on input and output tokens (how much info you can send out and the size of the response it will send back).  The input token limit is so high that I'm not likely to have enough headlines to even remotely approach it's limit (Gemini is 1 million tokens for the free tier and 2 million tokens for the paid tier and I'll be using around 20,000).  The output limit is much smaller (~8k) so if I wanted it to send back the complete details of the filtered headlines (title and link) it won't be able to.  To address this problem, I send the LLM the headlines with an index and have it return just the index.  If it was a 100 headlines then size of the output is less than 200 tokens.

A cron job will execute the program and write the result as JSON to the server where the web page will load the JSON  and display the headlines:


The code is on Github and you can see it is very simple program.

Monday, January 16, 2023

Goodbye OnHub!

 On January 11, 2023  Google shutdown support for the 7 years old OnHub WIFI router.  Technically, Google shutdown the Google Home App support of the OnHub because OnHub devices were technically made and sold by other companies (either ASUS or TP-Link) depending on which OnHub you had.  However, since the software was all handled by Google, if the software doesn't work then you can't do anything with it.  It will still "run" but no configuration changes can be made nor can you see any info about the device.  The only thing you can still do is to factory reset and delete the whole network.  It's unfortunate that once Google decided to stop supporting the device that they are essentially dead.

I found the OnHub to have been a great WIFI router that was powerful and easy to manage.  It had enough customization for my uses and didn't require me to be an IT admin for it. Even though there were probably a few features that I wished it added, it was balanced enough that I was willing to sacrifice those features.  I wished that before its end-of-life, Google provided a way to download its setting and load it to a new network.  Even though I replaced the OnHub with a Google Wifi (not the Nest Wifi), I had to manually put in all the setting information including tracking down all the devices that connects to it so that I can give each a recognizable name.  Other settings like groups, schedules, reserved IPs, IP range, etc. all had to be manually entered.  Most of it is pretty quick but the device naming is a pain.

Over on the OpenWRT forum there are developers trying to give the hardware additional life by replacing the software on it so it is not reliant on Google and Google's cloud.  That would be great as it saves devices from going to landfills and honestly the hardware is still perfectly fine even to this day.

Monday, November 1, 2021

Unable to access the internet when using PiHole?

PiHole added rate-limiting for DNS queries to a very low 1000 queries per minute and enabled it by default even when updating an existing installation.  To change the rate limit (or turn it off), edit /etc/pihole/pihole-FTL.conf and add/edit the line: 

RATE_LIMIT=0/0

The format is [# of queries]/[seconds] so to set a limit of 1000 queries per hour would be 1000/3600.

Saturday, March 14, 2020

Google App Engine's Missed Opportunity

I've been a fan of Google's App Engine (GAE) since its initial release in 2008 but it has never quite taken off despite the growth of running applications in the cloud and the rise of open source software.  It's really a missed opportunity for Google.

I have been running many small projects on GAE which is now part of Google Cloud's offerings.  GAE is friendlier to start with than other hosting options from Google in that it has a free tier which I suspect is sufficient for most users.  GAE auto-scales as traffic increases so there is a possibility that it could surpass the free quota but users can set a guidance on the max daily spend.  This has generally worked for me as I set the max to be $0.00 so that I don't go past the free quota.  Be aware that this is not a hard limit so there is a chance that it can go over the limit.  Recently, I got billed $0.01 requiring me to log in to Google Cloud and pay the amount due.  Since I had to log into the developer console, it gave me a chance to look at the projects that I've been running.  The majority were simple static websites which as simple as GAE is to use, it's easier to use something like Github pages.  Both offers SSL (HTTPS support) and custom domains so I decided to move my sites off of GAE.

This move got me thinking about the missed opportunity for Google with GAE.  It is not because GAE should be a static web hosting site since GAE is about running applications hosted in the cloud.  GAE offers a simple and complete solution that was perfect for users of open source projects. 

Just as Github Pages is a super simple solution to host static web pages, GAE started as a super simple solution for running cloud applications.  GAE is basically a server, database, memory cache, sign-in and storage solution all-in-one.  Users don't have to select and install each of these basic components themselves.  This meant that an open source project could be developed where the user can easily run it by putting it on GAE with the same simplicity of desktop projects (possibly even easier).  I imaged a world where someone can write a note taking app in App Engine and anyone who wants to use it get the source, put it on GAE and it's running and ready to use!   We see note taking programs all the time running on desktops and mobile because the author knows that if the user installs the binary they can start using the app, but for cloud apps it always involves a lot of infrastructure setup.  The reaction to this has been Docker containers which I find is still harder on the user and a lot more complex for the developer.

When GAE was first launched it confused developers who weren't used to this paradigm for web development and Google didn't do a very good job explaining or addressing some missing/problematic areas.  It seems like Google focused more on Enterprises to switch to this "Platform-As-A-Service" model when they have less need for such hand-holding.  I believe the missed opportunity is that they missed out that this was more ideal for the consumer market then the enterprise market.

Sunday, June 10, 2018

Go with WebAssembly Early Examples

Update:  I've since written an updated article about Go and WASM since a lot of have changed in the time since this article was posted.

WebAssembly (WASM) is the most exciting technology in web development in a long time from my perspective.  It represents the first true steps in breaking the monopoly of Javascript as the language for the browser even though the WASM folks emphasize that isn't the intention.  In my previous post, I mention that Go will support compiling to WebAssembly in version 1.11.  This post shares some of my experimentation with Go's WASM support and to see what might be possible.  Let me emphasize that the code is very hacky.  I wrote them quickly mainly so I can try out WASM. 


There are multiple ways to use WASM for web applications:

  1. Optimization for JavaScript-driven applications - This is the scenario most emphasized for the current level functionality provided by the initial (MVP) release of WASM.  Instead of writing everything in pre-compiled Javascript, optimized WASM modules are called by JavaScript.  These modules can be written in JavaScript or other languages that can compile to WASM.
  2. Porting existing code bases over to the browser - This is most often demonstrated with porting existing C/C++ code bases over to WASM through Emscripten and running what might previously been an exclusively desktop/native app (e.g. Autocad, games, etc.).
  3. Writing an web app completely in a non-Javascript language - This is what I'm most excited about!  Instead of having Javascript be the primary language, the application is completely written in another language such as Go.  At the time of this writing, this isn't completely possible since WASM doesn't support WASM modules from directly calling the browser APIs (e.g. DOM APIs, XHR, etc.).  This will be coming and is currently covered under the Host Binding proposal for WASM.  Until then, the Javascript can be abstracted away in a language-specific binding.
The current state of Go WASM doesn't fit the first scenario very well.  There doesn't seem to be a way to expose methods individually for Javascript to call directly.  The Javascript code can execute each Go program's main function and when main() is done the module is done running.  Given that each WASM module has the complete Go runtime including garbage collection, I'm not sure how practical it is to have a bunch of Go programs that are essentially meant to be single methods to the Javascript code.

Go WASM does provide the ability to define callback methods and attach callbacks to browser events.  This requires that the module is running because once it exists it's not longer available to the browser call call.  Because of this, Go WASM is currently most appropriate for scenarios 2 & 3.

The browser executes Javascript and WASM in a single threaded manner.  When the WASM module is running, the browser's front end will block until it is completed.  This will appear to the end user as if the browser is frozen: no way to type input, click button, etc.  With Go WASM, control is given back to the browser when using time.Sleep or when the Go code is blocked.  This has to be done manually by the developer so it's important to keep it in mind.  Unless the apps expect to have completely control of everything in the browser while it is running developers need to remember to periodically sleep itself to give some control back to the browser.   I hope this gets improved in the future because it makes the code ugly, error prone and honestly isn't something developers should need to do in a multi-tasking environment.

Example 1

Complete source is here. See it running here.  

This is a very basic example of writing a Go WASM module that defines a method that gets attached to a HTML button's click event, change some attributes of the document's elements, waits a few seconds then executes a Go routine that draws to the canvas in the browser.  The keepalive() function prevents the module from quitting until it gets a quit signal that happens when the Quit button is clicked and the cbQuit method is invoked because the button click event is triggered.  Also note that when the browser's Alert dialog is triggered, it blocks everything until it is dismissed whether it's called by JavaScript or by the Go code.

The keepalive() can also simply be
select {}
if the intention is just not let the module exit.

--- ---
The basics of having Go drive the web page (rather then it being Javascript) is all there.

Example 2

Complete source here.  Running example here.

This example was inspired by what was presented at GopherCon by Hana Kim when gomobile was first announced.


Instead of re-writing Rob Pike's Ivy Interpreter for Android/iOS/command-line the example showed that the existing Go library was reused.  Just like her example, this example shows that existing Go libraries can be used in WASM.

--- ---

The resulting WASM module is about 4MB but when compressed, the whole web app was only about 1 MB.

This example really doesn't show anything that the previous example didn't already show. I wanted to try against a larger code base and didn't want to write it myself.  It mainly just demonstrates an existing Go library being used with no changes needed to make it work.

The Ivy code is easy to port but if something is expecting to access a file system or make HTTP calls then the browser environment doesn't match.  There isn't any standard file system and outbound calls uses XHRHttpRequest rather then the current HTTP package.

Conclusions


It is possible to use Go to write web applications even though it currently still needs to rely on JavaScript to access the brower's APIs.  Things like Go routines work but developers have to handle sleeping themselves in order to not block the UI.  However, the possibility of ending JavaScript's monopoly for being the browser's language is definitely there!

Browsers themselves still need to do some optimizations.  Each WASM module's byte code still has to be compiled so there's always a delay before the module starts running.  It still starts faster then JavaScript but it'd be much better if the browsers caches the compiled WASM the first time.  My understanding that it'll likely come in the near future but not there yet.

I'm very excited to see this land in Go 1.11 and look forward to see what other developers use it for!

Sunday, May 20, 2018

WebAssembly (WASM) with Go

This is the first time that I've tried to compile the Go compiler so I figure that I'll document it here for others who might be wanting to try WASM with Go before the official Go release in August.

The next release of Go (1.11) is scheduled for Aug and it will be first time WebAssembly (WASM) will be supported.  WASM will be a build target much like how one builds a binary for other machine and operating systems except that in this case the machine is a "virtual" machine that runs inside the browser.

I've been very excited for WASM and I've been eagerly waiting for the time when I can use Go to write WASM.  The branch for the 1.11 release has is now locked for only bug fixes so I figured that it might be a good time to try writing a WASM code with Go.

Note that this first release for WASM isn't going to be "production" ready.  I don't think it'll be very optimized and WASM itself is only at its MVP release it doesn't allow WASM code direct access to the DOM or the browser APIs so all calls is still going through JavaScript.

Unfortunately, as of this writing, the code in the Go repo doesn't work for WASM.  The work on WASM for Go is primarily being done by Richard Musiol (neelance), the author of GopherJS, so I decided to get the version Go from this GitHub repo.

First, you will need a version of Go on your system to compile the source.  The easiest way is to download and install the binary distribution from the main Go website.

Until 1.11 is released to get WASM is to build from source.

git clone https://go.googlesource.com/go
cd go
Once you have the source, it's time to compile it.

cd src
./all.bash
If everything is built correctly then there will be a new "go" binary in ../bin.  Also, there are two files to help you get started with loading future WASM files in ../misc/wasm.

Create a test.go file:

package main

func main() {
    println("hello, wasm")
}
Compile to WASM with:

GOOS=js GOARCH=wasm go build -o test.wasm test.go
Make sure you're running the go command that you've just built and not the version that you installed originally.

In the same directory with your test.wasm file, copy over wasm_exec.html and wasm_exec.js from misc/wasm.

The browser will expect the test.wasm file to be served with a MIME of application/wasm so you'll need to add the following to your /etc/mime.types file:

application/wasm wasm
To run it in your browser, you'll need to have a web server.  Creating one with Go is easy, or you can also use Python with the following command.

python -m SimpleHTTPServer

Point your browser to your web server and load wasm_exec.html.  Click on the button and you should see "hello, wasm" appear in the browser's console.

I've been experimenting with WASM here.

Saturday, December 23, 2017

Youtube TV vs Hulu

Youtube TV and Hulu TV are two options for cord-cutters to get live TV.  After trying each for a few months, I decided to go with with Youtube TV because of its superior quality even though it had a smaller channel line-up.

Tuesday, July 25, 2017

Thoughts on Hugo

posted earlier about moving from Blogger to Hugo and it has been a couple of months so I thought that I share my thoughts on how Hugo has been working out.

Thursday, June 8, 2017

Moving from Blogger to Hugo

I really liked Blogger and I’ve hosted my blog on it since 2011. It was free (still is), but still had all the essentials features for a blog at the time and I like that it was integrated with Google.
My blogging needs haven’t changed since then but the world have evolved and Blogger no longer have all the essential features necessary for a blogging platform. Specifically, I’m talking about Blogger’s lack of support for SSL/TLS for custom domains. I could accept the dated editor controls, quirkiness in the WYSIWYG UI, and limited customization of themes, but there’s no excuse for not having https enabled on a web site anymore.
I’ve now moved Lazy Hacker Babble from Blogger to Hugo + Google App Engine. Hugo is a static site generator written in Go. It takes your markdown file and generates an entire web site consisting of static files so it doesn’t require databases runtimes, extra libraries, etc. Since it’s written in Go, Hugo comes as a stand-alone binary so there is no need to install a bunch of extra software in order to run it.

Monday, February 20, 2017

Yubikey, U2F and protecting your accounts.

Setting up 2-factor authentication is an important step to keeping your online accounts safe.  For many people, this comes in the form of having an additional code that must be entered in addition to their passwords such as those that is sent to their phones through SMS or using an app like Google Authenticator.

Admittedly, this additional security comes with an additional inconvenience of needing to have your phone nearby and looking up the code which probably turns off a lot people.  To simply the process, Google, Yubico and some partners developed Universal 2nd Factor (U2F) which is now handled by the FIDO Alliance.  This open standard uses an hardware key that you insert into the computer's USB slot (or using NFC) instead of typing a code.

Google, Facebook, Dropbox, Github and a host of other services now support this.  The keys can be purchased from Amazon and ranges from $18 to $50 depend on the features you want.  For primarily Fido/U2F support, only the $18 Yubikey is needed.



Thursday, July 21, 2016

Updating VIM for Go (Golang) Development

Since my last post, setting up Vim for Go development is not only easier but also makes developing with VIM much more powerful.  Just a single plugin, vim-go, is all that is needed for the Go-specific stuff and a host of new tools is now available to handle things like refactoring, linting, error checking, and more.

Go Tools

Make sure that you have Go installed and then get the various Go tools.

goimports

Go provides a lot of use packages that can be imported but it doesn't like it when you import a package and not use it.  Goimports will automatically insert the right imports for you by looking at your code and will remove unused imports from your source.  It's a great time saver!

go get golang.org/x/tools/cmd/goimports
godef

Godef lets you jump to the location where a symbol is defined.

go get -v code.google.com/p/rog-go/exp/cmd/godef
go install -v code.google.com/p/rog-go/exp/cmd/godef
golint

Golint will lint your source and warns you of potential issues.
go get github.com/golang/lint/golint
gorename

Gorename helps to refactor Go code.

go get golang.org/x/tools/cmd/gorename
errcheck

Errcheck checks your code for actual errors that isn't just lint issues.

go get github.com/kisielk/errcheck
gocode

Gocode provides autocomplete of your Go code.  When combined with vim-go and YouCompleteMe plugins, it allows autocomplete to appear as you're typing.


go get -u github.com/nsf/gocode (-u flag for "update")
It's a bit different for Windows so follow the instruction from the link for more details.

gotags

Gotags generate tags for Go code.  Combined with Tagbar, it will provide a pretty display of the tags in your code.

go get -u github.com/jstemmer/gotags
Guru

Guru is a tool that integrates with editors to help it understand Go code.

go get golang.org/x/tools/cmd/guru
go build golang.org/x/tools/cmd/guru

Oracle (Deprecated and replaced by Guru)

Oracle is a source analysis tool for Go program.


go get code.google.com/p/go.tools/cmd/oracle

Vim Plugins

It used to be that you would manually install a vim plugin for each of the various Go tools as well as using the the plugins that comes with Go itself.  Now, everything has been consolidated into a single Vim plugin, vim-go, and that's all you really need when it comes to Go-specific plugins.  A few other plug-ins such as Tagbar and YouCompleteMe are useful to complement your development environment, though.  I highly recommend that you use Vundle to manage your plugins.

vim-go

Vim-go brings together all the various plug-ins and feature for Go development in VIM including autocomplete, snippet support, improved syntax highlighting, go toolchain commands, etc. in a single package.

YouCompleteMe

YCM is a fast code completion engine for VIM that works as you type.  YCM requires VIM 7.3.584 or above and CMake (you'll need to compile the extension after it's downloaded).

Tagbar

A great way to view the tags in your code.  This requires that you have Exuberant Ctags and gotags installed.

Bufexplorer

My favorite plugin for navigating between VIM buffers.

.vimrc


" Go Specific Stuff
                                                             
au BufRead,BufNewFile *.go set filetype=go                                     
autocmd FileType go setlocal softtabstop=4
autocmd FileType go setlocal shiftwidth=4
autocmd FileType go setlocal tabstop=4

" go-def settings
let g:godef_split=2
let g:godef_same_file_in_same_window=1

" go-vim settings
let g:go_fmt_command = "goimports"
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_structs = 1

" tagbar settings                                                                  
let g:tagbar_type_go = {
    \ 'ctagstype' : 'go',
    \ 'kinds'     : [
        \ 'p:package',
        \ 'i:imports:1',
        \ 'c:constants',
        \ 'v:variables',
        \ 't:types',
        \ 'n:interfaces',
        \ 'w:fields',
        \ 'e:embedded',
        \ 'm:methods',
        \ 'r:constructor',
        \ 'f:functions'
    \ ],
    \ 'sro' : '.',
    \ 'kind2scope' : {
        \ 't' : 'ctype',
        \ 'n' : 'ntype'
    \ },
    \ 'scope2kind' : {
        \ 'ctype' : 't',
        \ 'ntype' : 'n'
    \ },
    \ 'ctagsbin'  : 'gotags',
    \ 'ctagsargs' : '-sort -silent'
\ } 

Sunday, January 10, 2016

Tools of the Trade

Here is what I have in my professional toolkit. These are things that I always try to have on my system. Everything here is free with many them being open source. I originally published this list about 15 years ago and this year I finally revisited it and cleaned things up. What I discovered was that the open source projects are the ones that most likely survived the test of time.
See my posts on recommended books

Programming Languages

  • Go Programming Language - Open source programming language that makes it easy to build simple, reliable and efficient software (Quoted from the Go site but is pretty accurate). This is my favorite language as it blends the compile nature of C with the practical aspects of a scripting language.
    • Check this post on setting up Vim for Go.
  • GNU GCC - Open source C/C++ compiler supported on so many platforms now that I can’t list them on. There’s even ports of it so that you can compile games to run on the GBA. C is the foundation language of enabled the growth of our profession and is a must learn of every software engineering.
  • Perl - One of the great scripting languages although admittedly I rarely use it now. In many instances, Python has taken the mantel of Perl, but Go might replace both.
  • Scheme - I don’t really do much with Scheme, but I believe it’s worthwhile for engineers to have exposure to this form of programming.

Programmer’s Editor

  • Vim - Although I started as an EMACs user, VIM is now my primary editor..
  • GNU EMACS - EMACS is more then an editor, it’s a way of life!
  • Notepad++ (Windows)

Web Browser

Databases

Multimedia

  • VideoLAN VLC - Open source media player that can play just about any format without the hassle of installing a bunch of codecs individually.
  • Handbrake - Allows conversion between different media formats.

Graphics

  • Blender - Open source 3D modler ala Maya.
  • IrfanView (Windows) Fast graphic view that’s small, fast, but loaded with features.
  • GIMP - Photoshop-like graphics program.
  • Inkscape - Vector graphics editor.

Source Control

Operating Systems

Cloud

Windows/DOS

Monday, May 4, 2015

Installing Waypoint Map Mods for Minecraft 1.8 for Windows, Linux and OSX (Yosemite)

Once you set up Minecraft for your family, you'll inevitably be asked to install mods to further enhance the game play.

Installing mods is both simple and annoying for a few reasons:

  • Mods aren't officially supported by Minecraft so there is no single way to install mods. 
  • This means that a mod built for version A might not work for version B.
  • Different mods might require different mod loaders and they might be in conflict with each other.
  • Just like apps on your mobile phone, some mods might not do what it claims to do and can be potentially harmful.
  • Many mods are served from sites that also tries to sneak in adware and malware on your machine when you try to download even if the mods themselves are okay.
  • Minecraft is built on Java and given the security issues a lot of OSs no longer comes with Java so you'll have to install it yourself.
  • If you install the official Java from Oracle (whether OSX or Windows), they try to sneak in adware on your machine as well!
I have been avoiding using mods but when the family demands it what can one do but to get it done?  So, after spending an afternoon learning about Minecraft mods, I thought I share with folks how I installed the VoxelMap mod for Minecraft version 1.8.x. on Linux, Windows and OSX.

VoxelMap is a mod that provides you with a map of your Minecraft world and also allows you to set way points so you can easily teleport to specific locations.  There are a number of mods that do similar things which I actually tried to get first but they either made it too painful to safely download (Xaero's Minimap) or wasn't available for 1.8.4 (Rei's Minimap and Zan's Minimap).  VoxelMap is a bit fancy but it's used by Youtubers that my kids watch so there's a degree of familiarity with it.

VoxelMap requires a mod loader called Liteloader to run.  Because mods are not officially supported by Minecraft, the community have come up with various loaders that provides simpler APIs that modders can use to write mods more easily.  However, because each of these API might be different there is a degree of fragmentation and conflicts between the mods that use different mod loaders.  It seems like Minecraft Forge is emerging as the leader (quantity of mods, support, books/tutorial that teaches using it), but a number of popular mods are also built on Liteloader.  Fortunately, Liteloader is compatible with Forge and in this guide I'm going to install both.

A final note before we dive in.  As of this writing, support for 1.8 is still somewhat "beta" for both Forge, Liteload, and VoxelMap (and pretty much any mod) and also I'm only going to install "client" mods since VoxelMap is just for the players and not a "server" mod which is that the clients connect to when playing multiplayers games.  For the server, it's going to be just the vanilla Minecraft 1.8.4 server that is officially released by Mojane.

Microsoft Windows


To install VoxelMap mod for Windows, you'll need:
  1. Java 1.6+ (to run the installers for Forge, Liteloader, etc).
  2. Minecraft 1.8.x client launcher
  3. Minecraft Forge for 1.8 (see below to avoid getting mislead by the download links)
  4. Liteloader for 1.8
  5. VoxelMap for 1.8

Java 1.6+


It's possible that you don't have Java installed on your system (Microsoft suggests that unless you really need Java, don't install it for security reasons.)  You can download Java from Oracle for free, but if you're not careful you'll get stuck with crappy adware (shame on a corporation like Oracle to use such underhanded tactics).  Fortunately, Microsoft now bundles Java with Minecraft launcher and you can use that version of Java to run the Forge and Liteloader installers.

The path to the Minecraft Java is something like this:  
C:\Program Files (x86)\Minecraft\runtime\jre-x64\<version>\bin\javaw.exe
You can find this by looking at the default Minecraft profile from the launcher and see what the executable path value it has.  Then from the command prompt (Run > cmd):
set JAVA_HOME="<path to java minus the javaw.exe>"
set PATH=%PATH%;%JAVA_HOME%

Minecraft 1.8.x Client Launcher


Simply download from https://minecraft.net/download and install it.

Minecraft Forge for 1.8 


When downloading Forge, avoid the obvious download buttons as they lead to the file hosting sites that tries to get you to download a lot of crapware, malware, adware, etc.  Instead, select "All Downloads" and click on the "i" next to the Installer link (we're NOT going to use the windows installer since it won't know where Java is) and select "Direct Download".

Liteloader for 1.8


As of this writing, only the developmental builds supports 1.8 so you'll need to download the latest snapshot.  Again, you just want to download the *.jar file rather then the windows .exe file.

VoxelMap for 1.8


You can find the download link from the VoxelMap page.  Make sure you grab the 1.8 version from the "Recent files" section and not from the "Download" button which grabs the 1.7.x version.

Installing Everything


Now that you've downloaded everything, the installation for Windows is fairly simple:

  1. Click on the Minecraft installer you downloaded from minecraft.net.  This will install Minecraft.
  2. Click on the launcher that it installed to start Minecraft.
  3. Click "Edit Profile" and change the version of Minecraft from "latest" to "1.8" (this is just a one time thing because Forge needs you to have run that version at least once).
  4. Click "Play"
  5. You can quit once the game menu comes up and change the profile back to latest at this point.
  6. Quit Minecraft completely.
  7. At the command prompt, install Forge with:  java -jar <path to .jar file>.  Select "Install client" then OK.  Start up the client again, pick the "Forge" profile and make sure everything works.
  8. Quit Minecraft.
  9. At the command prompt, install Liteloader with: java -jar <path to .jar file>.
  10. From the menu's "extend to" option, pick the drop down that says Forge... and then install.
  11. Start up the client once again, select the "Liteloader 1.8 with Forge..." profile and make sure everything still works.
  12. Quit Minecraft
  13. At the command prompt, copy the VoxelMap mod to the Forge mod directory:  copy <path to VoxelMap's *.liteload file> %APPDATA%/mods/1.8
  14. You're done!  You should now be able to play Minecraft with the minimap on your screen.

Linux


Installing on Linux is the same steps as for Windows except for the following:
  • Linux might already have Java installed, but if not then use the package manager to install openjdk and you shouldn't have to do anything else beyond that for Java.
  • The path to copy the VoxelMap mod (step 13 above) is ~/.minecraft/mods/1.8 (instead of %APPDATA%/minecraft/mods/1.8).

OSX

Updated:  Sept. 27, 2015 

OSX is more of a pain to set up because it only have Java 1.6 (and not even that unless you manually install it on Yosemite).

First, go through steps 1 to 6 as described in the Windows section (You might get prompted to install Java -- see below).

Just like Windows, the Minecraft launcher for OSX also comes with Java 1.8 so it isn't necessary to download Java separately.  OSX only have Java 1.6 so you should use the version that comes with Minecraft then the default OSX Java.

Java 1.6+


To install Java 1.6, you'll get a prompt the first time you try to start the launcher to install Java if it can't find it.  Simply click "More Info" and follow the instructions to installing Java.  This is fine for playing Minecraft, but doesn't work for Liteloader's installer as it requires 1.7+.

Minecraft Forge for 1.8


You should be able to install Forge just by clicking the installer file or you can do it from the terminal just like it is described step 7 above.
java -jar forge-1.8-*-installer.jar
Then selecting "Install client".

Once installed, start up the client and pick the "Forge" profile.

Liteloader for 1.8


Liteloader is a problem because Java 1.6, which is what Apple installs, doesn't work with the installer.  You can download Java from Oracle but just like the Windows version, you have to be careful or adware will get installed.

Instead, we'll let Forge install Liteloader for us so instead of running the Liteloader installer:
  1. Right click on the installer jar file and select "Open With > Archive Utility".  This should create a folder with all the files from the jar file.
  2. Using the Terminal, go to the folder and copy the Liteloader jar files to the mod directory: cp liteloader-*.jar ~/Library/Application\ Support/minecraft/mods
  3. Now start up Minecraft but continue to use the Forge profile.
  4. If everything starts up fine and it Forge is running then quit Minecraft
Liteloader somes with an installer which you can launch by using:
java -jar <liteloader jar file>
Or you can copy the file to the mods directory and have Forge load it since they are compatible.
cp liteloader-*.jar ~/Library/Application\ Support/minecraft/mods

VoxelMap for 1.8


Just like for Windows and Linux, you just need to copy the VoxelMap mod file to the Forge mod directory:
cp <voxelmap mod file>  ~/Library/Application\ Support/minecraft/mods/1.8

You can now start up Minecraft and see that the VoxelMap mod is loaded.

You're Done!


Now you should be able to use the VoxelMap mod whether in your single player game or if you connect to the 1.8.x server.