Wednesday, March 23, 2022

Vim popular shortcuts


    In this article I will walk you through some of the popular commands that you can use to get up fast and start using the Vim editor. Vim was written by Brian Moolenar as a charity ware, meaning all of its donations goes to the non - profit in Uganda I think.

Why one should learn vim?

    Vim is a popular visual editor from almost the beginning of computers whose predecessor was vi. It has been used widely by mainly Open source developers since the development of *nix systems.

    Today's popular editor's like Visual Studio Code has vim support through its extensions.

    Vim has three main modes Edit, Visual and Command, Enter Edit by typing i, Visual by typing v and Command by typing :

We will go through the commands for each of the modes below.

Edit mode

Editing of text is done in this mode and hence have no shortcuts.


i - insert or start typing or to enter edit mode
A - go to end of line and edit
o - creates new next line and you can start editing

Visual  Mode

Read only mode mainly for navigation, searching, register operations.

v - begin visual mode
Ctrl+v - visual block
gg - go to top of file
GG - go to end of file
y - yank ( copy ) selection
yy - yank line
p - paste after cursor
P - paste before cursor
3p - paste three times after cursor
/word - search for word in forward (top to down) direction
?word - search for word in reverse (bottom to up) direction
w - jump word
e - jump to end of word
b - jump word backwards
2w or 2e - jump two words or jump to end of two words
r - replace letter
x - delete letter
cw - change word
ce - change to end of word
c2w or c2e - change to two words or end of two words

Searching -
n - search for next position of word
N - search for previous position of word/ back search
* - find next word
# - find previous word

Navigation -
`" - go to last cursor position after opening a file
`. - go to last edit position after opening a file
0 - go to start of line
$ - go to end of line
A - go to end of line and edit
G - go to beginning of file
% - go to end or start of braces {} or [] or () .....
[{ - go to opening of braces
]} - go to ending of braces



Ctrl + I - go previous cursor positions even other files
Ctrl + O - go after cursor positions even other files
Ctrl + ] - on tag link goes to link
Ctrl + t - goes back to link

h - nav left
l - nav right
k - nav up
j - nav down

Command  Mode

Mainly to perform file operations of the file and run shell commands as well.

:w - write to disk
:wq - write to disk and close editor
:q! - close editor but not write any changes
:tabedit filename - creates new tab opening filename in it
:gt - go to next tab
:gT - go to previous tab
!ls - execute shell commands, in this case ls
:sort - after selecting say a list of words or numbers in visual. Typing this sorts them in alphabetical or numerical ascending order

:colorscheme solarized - switching themes found in $vimruntime/colors. Others include `morning` , `evening`, `peachpuff`, `industry`, `murphy`, `blue`, `darkblue`, `desert` and all
:set background=light - or `dark` depend on time of day for a specific theme.

:%s/word/new/gc - replace word with new in the whole file with confirmation each time. Regex patterns is supported here.

FAQ

How to copy text to command mode?
After yanking the text and pressing : Do Ctrl+R and "

How to paste the previously yanked ( copied ) text?
"0p - pastes the second last copied
:reg shows the paste registers. Use "6p to paste the 6th register


Tuesday, February 8, 2022

Bhagawadgita about food

 In Bhagawadgita, Lord Krishna says that the food we prepare must be consumed within first three hours after its preparation. A person who consumes food within the first three hours happens to be a Good person. A person who consumes the food from three hours to as long as it is good to eat seems to be a person with passion. A person who consumes food after it has gone bad has problems in his life and can be after something.

  In Bhagawadgita, human beings are classified as three types, the Good, the average and the passionate.

Thursday, February 3, 2022

Karma in real life action

 In this post I like to expose the truth of karma's existence with a live example. Lets say you are a principled person living with a set of rules or principles which may be personal or adhere to a specific religion.


X was worked in a company that doesn't hire its ex-employees back. At one stage it so happened that almost everyone in one city had worked for X before. Should I say unfortunately or obviously X reached a point of stepping on its own leg for its policy. Now X's competitor lets say Y which did not have such policy could hire X's ex employees as well in that city. In a way X paved the way for Y and isn't this the law of Karma.


This is similar in one's life as well. When one doesn't agree with the policies of a Company, he may not have to work for it. If all have the same disagreement, such a company will have very less or no chances of having any resources at all. Such is the power of human principles or religion in mankind.

Sunday, December 17, 2017

Rails vs Padrino or others

Starting writing in Ruby after touching all other languages is like finding manna as the life saver. Talking about Ruby, the one web framework that comes to mind is Rails. I will not talk about Padrino or others until a while. Let me try to put the reasons on why you should use rails

1. Large community base - building or adding features and bug fixes continuously gives it capability to have the latest web technologies be it like front end technology like sass, bootstrap and all.

2. ‎Automatated generators - almost every MVC part generation is automated, be it creating controllers, adding or updating models, creating views with ERB (try haml too) adding tests, rake tasks and much more, all from the command line. I recommend using Linux ( Manjaro ) with rbenv to manage ruby environments and of course VIM editor with tmux for ide like multitasking. I prefer solarized light theme for them 😀

3. ‎Rails console - gives the easy shell to check your variables, url params, perform database CRUD operation methods, session values, "string".classname to get inherited classes or modules and all

4. Github and Heroku deploy - Using one branch for each task and merging them to master once done is the way to go. Lastly the deployment is as easy as single command 'git push heroku' which pushes the master branch to Heroku. Heroku generates an url for your application. Also it supports postgres for now, so watch out for it when starting to build your app.

That's it, this is what it should take for you to get going with your loved programming language on the best automated web framework.

Roughly you would be adding the routes in the config/routes file. It's controller will be an ApplicationController class in app/controllers/name with methods or actions like index, create, show, delete or similar. Finally the render for views is in app/views/name as .ERB file for each controller (class) created. These can be further broken down using partials using underscores like _footer.erb or _ header.erb . One can further use HAML instead of ERB for minimal writing. Of course you can use SASS or SCSS and coffee script for JS.

I recommend reading or referring Michael Hartl's Rails book, it's a pretty good book for a first time web developer. The recommend chapters are static pages ....

If you read till now, I am pretty sure you will stick to rails for a while. Now let me talk about its competition. One I think of is Padrino which is built on top of Sinatra mini web framework.

Sinatra doesn't have a routes but instead have their routes defined in the controller class itself. Padrino has a lot of work in progress parts but shows off the light weight benefits.

Padrino imports lot of rails generator concepts for creating controllers, tests, models, views and all. The blog tutorial on its site uses sequel which I didn't want to start learning as I just learnt Activerecord which uses such easy methods like User.find_by_name("Ragavendra") to retrieve say user records and say .save , . create and .delete to fulfill CRUD.

 I assume Activerecord was created by the Rails team. There are a tonne more libraries contributed by the rails team to the Ruby community as gems or even to its core. Rails is what more or less made Ruby popular. Lot other modern web frameworks have inherited Ruby gem concepts as well for easier web development.

Spree is an ecommerce built on top of rails. Hanami seems easier and imports a lot of rails like commands, it has a lot of nitty gritty which feels like working on HTML for some reason. I am pretty sure you will want to fall back to rails like me if you walk through all the other web frameworks. The best part is the sane eco system it has to offer.

The tests part is one which I wouldn't recommend and DHH thinks the same too, it takes to much time and stresses real bad. Better to have a separate team write integration tests than those painful TDD or unit tests.

Wednesday, July 12, 2017

Are you technically apt - Software developer

You don't have to be technically apt to be able to achieve business needs or requirements. Often in interviews people try to test your coding knowledge to the point of knowing the perfect syntax. What would happen if you actually made coding mistakes when coding on a machine, you would actually see some interpreter or compiler warnings or errors. Now can't you fix this code now. Do interviewers question this? Actually Google is just a click away to precisely help to fix issues if in case we did not understand how to fix it. Are interviewers thinking that you are a compiler or an interpreter 😀 . A knowledgeable coder is one who can pick the best method or approach for a problem rather than one who knows everything like a poem and is not good in knowing the best solution. I often find that interviewers are trying to find the later ones for their teams. Did you just read poem, yes that's correct. I was one of the worst in memorizing poems in my class and that's why I moved to  Science. I always think Science is learning based on understanding. So should the other IT people be too, if not I am afraid of its future. I am ready to take a bet on it. Having almost learnt so many programming languages I have to admit that most was possible because the boss gave me an opportunity to do it rather than question me before giving it. Yes I had some very good considerate bosses in my career. In turn I did what was expected and won accolades too like the best performer award in the government project. I always never want to work for anyone who can't praise your success or even understand it and so should anyone. Eventually people will judge you based on rumors and it has never worked in your favor.


Saturday, November 19, 2016

Orange PI Plus 2 with Arch Linux Minimal



ArchLinux_Minimal.img                            Arch Linux basic image (without Desktop GUI)

Download ArchLinux_Minimal.img from https://drive.google.com/drive/folders/0B1hyW7T0dqn6fndnZTRhRm5BaW4zVDVyTGlGMWJES3Z1eXVDQzI5R1lnV21oRHFsWnVwSEU


Installation on SD Card


  • Download any of the available images (xz archive) from Mega or GoogleDrive
  • Download scriptbin_kernel.tar.gz, it contains the latest kernel (uImage) and script.bin
  • Unpack the archive.
  • Write the xxx.img file (disk image) to your SD Card
  • on Linux use dd command ( sudo dd if=image_name.img of=/dev/sdX bs=1M oflag=direct )
  • on Windows use disk image writing software such as Win32 Disk Imager
  • After writing the image, mount SD Card FAT partition (BOOT)
  • Copy uImage_OPI-2 or uImage_OPI-PLUS (depending on your board type) to uImage (for OPI-PC use uImage_OPI-2)
  • Copy one of the script.bin.OPI-XXXX (depending on your board type and desired monitor resolution) to script.bin
  • use uImage_OPI-XX and script.bin.OPI-XXXX from scriptbin_kernel.tar.gz if it is newer (probably it is).
  • Boot your Orange PI board from SD Card


Installation on internal EMMC


  • Install the image on SD Card as described above
  • Boot your Orange PI board from SD Card
  • Run:
    1. sudo install_to_emmc
    Copy the Code

  • Power off the board.
  • Remove SD Card
  • Power on, the board will boot from EMMC

1) First connect to internet via the LAN cable
2) try `sudo pacman -Syu` to fetch the updated installation urls. Hit NO when asked to install update packages.
3) Now do `sudo pacman -S parted dosfstools` to install the partitioning pr the disk packages
4) Now you can do `sudo install_to_emmc` .... have fun ....


Setting up WiFi


wifi-menu -o

# netctl start profile 
then it can be enabled using:
# netctl enable profile
This will create and enable a systemd service that will start when the computer boots. Changes to the profile file will not propagate to the service file automatically. After such changes, it is necessary to reenable the profile:
# netctl reenable profile


If you see network profile aleady up, do
ip link wlan0 down

then do
netctl start wireless-wpa

Wednesday, August 17, 2016

Innovations in demand or needed badly

1) Flood survival kit - Like below, need a kit to help survive floods

2) Building/ apartment on fire escape kit -- http://www.dailymail.co.uk/sciencetech/article-3192161/SkySaver-backpack-lets-ABSEIL-multi-storey-buildings-escape-fires.html#v-4410962511001

Todo - Shortly need to create a post on change.org to pledge governments to provide these/ similar kits to the residents as it can come handy during the disaster.

3) Tornado survival kit - Like above, need a kit to help survive tornado

4) Tsunami survival kit - Like above, need a kit to help survive tsunamis

5) Earthquake survival kit - Like above, need a kit to help survive earthquakes

6) Frost bite survival kit - Like above, need a kit to help survive frost bites

7) War survival kit - Like above, need a kit to help survive wars

Browser background color or monitor brightness

Have you been in a situation where you are almost sitting the whole day in front of your browser and going through a document and find that ...