Monthly Archives: November 2018

Top 10 Most Subscribed Youtube Channel Visualization[2013-2018]

- - JavaScript, Tutorials, Web

Motion Visualization is intriguing and explains a lot in itself. I have put together an example visualization of the Top 10 Youtubers(by subscribers) from November 2013 to November 2018.
I am not very informed of whether or not flash based visualizations are still relevant, but I found Google Motion Chart to have explained very well the data set I’ve taken into consideration. As always the codes remain public so people can take ideas from it and produce an even better visualizations for themselves.

It is especially interesting to produce a motion chart for data points where entities have varying rates of growth overtime. I had difficulties being able to view the visualizations on some versions of chrome although I had flash installed. Make sure you have installed adobe flash in-order to view the visualizations. Here is a link to the visualization.

I’ve also prepared a video from the visualization for the ones having trouble viewing the viz. You should watch it anyways, it’s fun.

The code below contains only a few portion of the dataset to make it much readable.

Subscribe to my blog for more interesting contents

Basic File Operations – Golang

- - Golang, Tutorials

One of the most basic task when working on a server is the ability to effectively operate with the files and file system. Like many languages, Golang has convenient methods to work with files. The intentions of this post is to host a minimalist set of examples on working with files using Golang.

Creating an empty file
package main

import (
  "log"
  "os"
)

func createFile(){
  newFile, err := os.Create("testfile.txt")
  if err != nil{
     log.Fatal(err)
  }
  defer newFile.Close()

  log.Println(newFile)
  // operations on file follows
}


func main(){
  createFile()
}
Reading a File
func readFile(){
  fileReader, err := os.Open("test.txt")
  if err != nil{
     log.Fatal(err)
  }
   defer fileReader.Close()
  content, err := ioutil.ReadAll(fileReader)
  if err != nil{
     log.Fatal(err)
  }
  fmt.Println("Number of bytes read", len(content))
  fmt.Printf("Data as string : %s", content)


}
Writing to a file
func writeToFile(){
  err := ioutil.WriteFile("testwrite.txt", []byte("Dumping bytes to a file\n"), 0666)
  if err != nil{
     log.Fatal(err)
  }
}
Truncate File
func TruncateFile(){
  err := os.Truncate("test.txt", 100)
  if err != nil{
     log.Fatal(err)
  }else{
     fmt.Print("File Truncated")
  }

}
File Information
func FileInformation(){
  fileInfo, err := os.Stat("test.txt")
  if err != nil {
     log.Fatal(err)
  }
  fmt.Println("File name:", fileInfo.Name())
  fmt.Println("Size in bytes:", fileInfo.Size())
  fmt.Println("Permissions:", fileInfo.Mode())
}
Check if file exists or not
package main

import (
    "os"
    "fmt"
)

func main(){
    if _, err := os.Stat("test.txt"); os.IsNotExist(err){
        fmt.Println("The file does not exist")
    return
    }
    fmt.Println("The file exists!")
    //perform operations on the file/file contents
}
Move/Rename File
package main
 
import (
    "log"
    "os"
)
 
func main() {
    currentFileLocation := "/home/bhishan-1504/golangfilehandling/test.txt"
    toMoveLocation := "/home/bhishan-1504/golangrestapi/test.txt"
    err := os.Rename(currentFileLocation, toMoveLocation)
    if err != nil {
        log.Fatal(err)
    }
}
Copy File
package main

import (
  "io"
  "log"
  "os"
  "fmt"
)

func main(){
  source, err := os.Open("test.txt")
  if err != nil{
    log.Fatal(err)
  }
  defer source.Close()

  sourceCopied, err := os.OpenFile("copiedtest.txt", os.O_RDWR|os.O_CREATE, 0666)
  //sourceCopied, err := os.Create("copiedtest.txt")
  if err != nil{
    log.Fatal(err)
  }
  defer sourceCopied.Close()

  _, err = io.Copy(sourceCopied, source)
  if err != nil{
    log.Fatal(err)
  }

 
  fmt.Println("Copied!")
}