Thursday, November 20, 2014

Using VIM

Getting some time for myself, I decided to improve my professional skills by adding a new powerful tool: vi.
Having some trouble changing inside a quoted string with ci" (after some time i figure it out: it should be ci" and a space right after(for quotes)), I found this gem:

The operators that can be used are:
 ~ switch case     |v_~|
 d delete      |v_d|
 c change (4)     |v_c|
 y yank      |v_y|
 > shift right (4)     |v_>|
 < shift left (4)     |v_<|
 ! filter through external command (1)  |v_!|
 = filter through 'equalprg' option command (1) |v_=|
 gq format lines to 'textwidth' length (1)  |v_gq|

The objects that can be used are:
 aw a word (with white space)   |v_aw|
 iw inner word     |v_iw|
 aW a WORD (with white space)   |v_aW|
 iW inner WORD     |v_iW|
 as a sentence (with white space)   |v_as|
 is inner sentence     |v_is|
 ap a paragraph (with white space)   |v_ap|
 ip inner paragraph     |v_ip|
 ab a () block (with parenthesis)   |v_ab|
 ib inner () block     |v_ib|
 aB a {} block (with braces)   |v_aB|
 iB inner {} block     |v_iB|
 at a block (with tags)                  |v_at|
 it inner block                   |v_it|
 a< a <> block (with <>)    |v_a<|
 i< inner <> block     |v_i<|
 a[ a [] block (with [])    |v_a[|
 i[ inner [] block     |v_i[|
 a" a double quoted string (with quotes)  |v_aquote|
 i" inner double quoted string   |v_iquote|
 a' a single quoted string (with quotes)  |v_a'|
 i' inner simple quoted string   |v_i'|
 a` a string in backticks (with backticks)  |v_a`|
 i` inner string in backticks   |v_i`|
Additionally the following commands can be used:
 : start Ex command for highlighted lines (1) |v_:|
 r change (4)     |v_r|
 s change      |v_s|
 C change (2)(4)     |v_C|
 S change (2)     |v_S|
 R change (2)     |v_R|
 x delete      |v_x|
 D delete (3)     |v_D|
 X delete (2)     |v_X|
 Y yank (2)     |v_Y|
 p put      |v_p|
 J join (1)     |v_J|
 U make uppercase     |v_U|
 u make lowercase     |v_u|
 ^] find tag     |v_CTRL-]|
 I block insert     |v_b_I|
 A block append     |v_b_A|
Here is a list taken from stackoverflow lost somewhere in my browser history (thanks to the post author and to that great site build for knowledge):
select                                   v                                     
select row(s)                            SHIFT + v                             
select blocks (columns)                  CTRL  + v                             
indent selected text                     >                                     
unindent selected text                   <                                     
list buffers                             :ls                                   
open buffer                              :bN (N = buffer number)               
print                                    :hardcopy                             
open a file                              :e /path/to/file.txt                  
                                         :e C:\Path\To\File.txt                
sort selected rows                       :sort                                 
search for word under cursor             *                                     
open file under cursor                   gf                                    
  (absolute path or relative)                                                  
format selected code                     =                                     
select contents of entire file           ggVG                                  
convert selected text to uppercase       U                                     
convert selected text to lowercase       u                                     
invert case of selected text             ~                                     
convert tabs to spaces                   :retab                                
start recording a macro                  qX (X = key to assign macro to)       
stop recording a macro                   q                                       
playback macro                           @X (X = key macro was assigned to)    
replay previously played macro *         @@                                    
auto-complete a word you are typing **   CTRL + n                              
bookmark current place in file           mX (X = key to assign bookmark to)    
jump to bookmark                         `X (X = key bookmark was assigned to  
                                             ` = back tick/tilde key)          
show all bookmarks                       :marks                                
delete a bookmark                        :delm X (X = key bookmark to delete)   
delete all bookmarks                     :delm!                                 
split screen horizontally                :split                                
split screen vertically                  :vsplit                               
navigating split screens                 CTRL + w + j = move down a screen     
                                         CTRL + w + k = move up a screen       
                                         CTRL + w + h = move left a screen     
                                         CTRL + w + l = move right a screen    
close all other split screens            :only                                 

*  - As with other commands in vi, you can playback a macro any number of times.
     The following command would playback the macro assigned to the key `w' 100
     times: 100@w

** - Vim uses words that exist in your current buffer and any other buffer you 
     may have open for auto-complete suggestions.

Monday, February 10, 2014

Microcontroller Timer Frequency Calculator

Recently I needed to compute an appropriate frequency for a timer to proper modulate 38kHz with an ATTiny 13 . Made the computation and discover that the exact frequency cannot be reached with just the microcontroller without tampering with the OSCCAL and CLKPCE .
I needed to find the closest frequency to the target 38kHz (planned to use CTC on 2*38kHz = 76kHz, where CTC means: Clear Timer on Compare) that can be reached by using the timer (in hardware mode). Also I wanted to learn the basics for AngularJS . Below in this page is the resulted tool:

Usage Note: After you enter the base microcontroller clock source and the desired frequencies press the Compute Posibilities button. Look in the tables below for the resulted timer period, counter threshold and suggested prescalers configuration.

Note: Any feedback would be GREATLY appreciated. If you have suggestions how to improve this tool let me know. If you want to use this work in your site, please post a visible link to this blog page on your site page. Thank you!

UC Prescalers Timer

16 bit Timer

  • {{'1/'+Math.pow(2, sc.Scale)}}
  • {{'1/'+Math.pow(2, sc.Scale)}}
UC Base Frequency: Hz
Desired Frequencies:
  • Hz
Use this if not 0: ms
Least Common Multiple: Hz
Greatest Common Divisor: Hz

Sorting predicate = {{ResultsSort}}
Frequency (Hz) Timer Interval Timer Count UC Prescaler Timer Prescaler
{{result.FrequencyInHz}} {{result.TimerInterval}} {{result.TimerCount}} {{'1/'+Math.pow(2, result.UCPrescaler)}} {{'1/'+Math.pow(2, result.TimerPrescaler)}}
Frequency (Hz) Closest Frequency Error Timer Interval Timer Count UC Prescaler Timer Prescaler
{{result.FrequencyInHz}} {{result.FrequencyInHz + result.Error}} {{result.Error}} {{result.TimerInterval}} {{result.TimerCount}} {{'1/'+Math.pow(2, result.UCPrescaler)}} {{'1/'+Math.pow(2, result.TimerPrescaler)}}

Sunday, January 5, 2014

Tool for learning notes on guitar

Finally doing something that I always dreamed off: To play on guitar.

I made a tool that helped me A LOT to have an easy start: Learn Notes For Guitar executable (Windows with .Net Framework 4.5)

Below is a capture:

The user can select the correct answer by clicking on the proper button. After each 20 questions the program will switch the notation from the solfège to the letter and back.

The purpose of this application is to help the user to quickly learn:

  • the correspondence between the Solfège notation and the letter notation.
  • the position of notes on the first 12 frets of a guitar.

The application have the GNU General Public License, so everyone is permitted to use, copy and distribute verbatim copies of this application, but changing it is not allowed.

Any feedback is greatly appreciated.