I'm learning vi, as I appreciate the vast possibilities of the editor, and have to use a plain-text editor for my current project. In many tutorials I have read that it is recommended to use the keys "h", "j", "k" and "l" instead of the arrow keys, for the sake of speed.
However, as a touch typist, my fingers are normally in the default position of a, s, d, f (left hand) and j, k, l and รถ (right hand [german keyboard]). Navigating in vi requires effectively to place the right hand in the default position of h, j, k and l. This makes writing text correctly hard, as I notice constantly that I start to type text, when my right hand is in the "vi right hand position" instead of the "touch-typing right hand position".
As a touch typist, have you adapted your hand memory so that you have switch the position depending on the vi mode, or have you found some other solution? I would appreciate experiences and tips from experienced touch typists using vi.
I still keep my fingers on the home keys for touch typing, and just reach for the keys I want. My index finger is used for both h and j. I'm not often switching between h and j anyway, so it doesn't slow me down.
I find I use w, b, 0, f and / to navigate though, not so much with h, j, k and l.
BTW. I found it really hard to write this message into the browser text box. When typing about vi keys, my fingers naturally wanted to use them. Please excuse any extraneous characters :-)
Related
I am trying to make a new tool for the tabletop simulator community based on my "pack up bag". The Packup Bag is a tool that remembers world position and rotation of objects you place inside it, so you can then place them back in the same positions and rotations they came from when "unpacking the bag".
I have been trying to modify this so it spits things out in a relative position and rotation to the bag, instead of using hardcoded world coordinates. The idea here is that players can sit at any location at the table, pick the faction bag they wish to play.. drop it on a known spot marked for them and press the place and it will populate contents of the bag relative to its location.
Now I have gotten some of this worked out... I am able to get the bag to place relative in some ways .. but I am finding it beyond my maths skills to work out the modifications of the transforms.
Basically I have this part working..
The mod understands relative position to the bag
The mod understands relative rotation to the bag
BUT.. the mod dose not understand relative position AND rotation at the same time.... I need someway to modify the position data relative to the rotational data... but can not work out how.
See this video....
https://screencast-o-matic.com/watch/cFiOeYFsyi
As you can see as I move the bag around the object is placed relative to it.... but if I rotate the bag, the object has the correct rotation but I need math to work out the correct position IF it is rotated. You can see it is just getting placed in the same position it was as if there was no rotation... as I haven't worked out how to code it to do this.
Now I have heard of something called "matrix math" but I couldn't understand it. I'm a self taught programmer of only a few months after I started modding TTS.
You can kinda understand what I mean I hope.. In the video example, when I rotate the bag, the object should be placed with the correct rotation but the world position needs to be changed.
See this Example to see relative rotation ....
https://screencast-o-matic.com/watch/cFiOeZFsyq
My code dose this by remembering the self.getPostion() of the bag and the obj.Position() of the object getting packed up.. it then dose a self - obj and stores that value for the X and Y position. It also remembers if it is negative or position and then when placing it uses the self.postion() and adds or subtracts the adjustment value. Same for rotation.
Still I do not know what ot go from here.. I have been kinda hurting my head on this and thought maybe some of you math guys might have a better idea on how to do this.
: TL;DR :
So I have
bag.getPosition() and obj.getRotation()
bag.getRotation(0 and obj.getRotation()
These return (x,y,z}
What math can I use to find the relative position and rotation of the objects to the bag so if I rotate the bag. The objects come out of it in a relative way...
Preferably in LUA.. thank you!
I'd hope you've found the answer by now, but for anyone else finding this page:
The problem is much simpler than what you're suggesting - it's basic right triangle trigonometry.
Refer to this diagram. You have a right triangle with points A, B, and C, where C is the right angle. (For brevity, I'll use abbreviations opp, adj, and hyp.) The bag is at point A, you want the object at point B. You have the angle and distance (angle A and the length of the hyp, respectively), but you need the x,y coordinates of point B relative to point A.
The x coord is the length of adj, and y coord is the length of opp. As shown, the formulas to calculate these are:
cos(angle A) = adj/hyp
sin(angle A) = opp/hyp
solving for the unknowns:
adj = hyp * cos(angle A)
opp = hyp * sin(angle A)
For your specific use, and taking into account the shift in coordinate system x,y,z => x,z,y:
obj_x_offset = distance * math.cos(bag.getRotation().y)
obj_z_offset = distance * math.sin(bag.getRotation().y)
obj_x_position = bag.getPosition().x + obj_x_offset
obj_z_position = bag.getPosition().z + obj_z_offset
Diagram source:
https://www.khanacademy.org/math/geometry/hs-geo-trig/hs-geo-modeling-with-right-triangles/a/right-triangle-trigonometry-review
I'm having a little curious sense of art in programming at the moment. And I want to script my Autotouch App on my iOS to generate Pixel Art inside of another app.
I was doing this previously by typing in code to tap at the screen at one coordinate, I did this 2000+ times and it got the job done. But there should be a better, smarter way to get it done.
My test image is going to be very symetrical to make things easy.
There is a code in the Lua app that I'm using to simply tap on the screen,
tap(x, y)
But I want to set this up like:
tap({xTable}, y)
But I'm not sure if that will "tap" at each x coordinate that I've listed for the y variable.
I want to paint a pixel at one very specific coordinate, and then step 5 pixels away and paint the next one, and repeat that until the end of the line.
Is this at all possible or am I reaching beyond the language capabilities?
Edit: for some reason my phone is not blocking code when I'm asking a question, if someone sees this and wants to edit, I would be grateful.
Is this at all possible or am I reaching beyond the language capabilities?
Not even close. I recommend you read Programming in Lua.
tap({xTable}, y)
But I'm not sure if that will "tap" at each x coordinate that I've listed for the y variable.
Why are you not sure? Did you not write it? If not, you can trivially write it yourself given tap:
function tapxs(xs, y)
for i,x in ipairs(xs) do
tap(x,y)
end
end
...
tapxs({10,20,30,40}, 10) -- tap at 10,10; 20,10; 30,10; etc.
I want to paint a pixel at one very specific coordinate, and then step 5 pixels away and paint the next one, and repeat that until the end of the line.
What is "the line"? Is it purely horizontal? You could write:
function tapHorizontally(startX, maxX, y, increment)
for x=startX,maxX,increment do
tap(x,y)
end
end
...
tapHorizontally(10,100,20,5) -- tap from 10,20 to 100,20 in 5 pixel increments
Of course, that's a bizarrely specific function. You'd typically write something that takes a starting x,y and ending x,y and draws between them, so you can support horizontal, vertical, diagonal lines all with the same function, but that requires more math.
The bottom line is: Lua is a full blown, powerful, high level programming language. It could be used to write the very app you're tapping on, or the app you're using to generate taps, so the limits are going to be your knowledge of programming/algorithms/math/etc.
I have a series with many null values all over the place on the line. I need the gap between those values to be represented with a dotted-line or whatever (another color).
Any help will be very welcome :)
thanks!
Before starting, let me confess that its an interesting problem but very much solvable using Highcharts. Though this will need a bit of work.
This is how I would implement this:
Algo:
For every series S, create an another auxiliary series S'. S' job is to fill the gaps. S' can be a dotted line of same color. For every gap, consecutive nulls, in S, let say gap starts at point L(x1,y1) and ends at point R(x2,y2). Points L and R needs to be there on S'. Lets say points L and R are m units away from each other where m>=2. We need to insert m-1 points between L and R. We can do this by linear interpolation. We will call these points as P1, P2 .. Pm-1 where Pi = { x2-x1 + i, y1 + (y2 -y1)/m }
Usability:
If lets say you have series T, Q, R ans S in your original chart. After application of above algorithm, you will have 4 more series named T', Q', R' ans S'. In legend, 8 series will be visible. But we want only 4 - the original ones. You can accomplish this by using 'linkedTo' property of series. So T' will be linked to T, S' will be linked to S and so on. As a result, legend of S' will not be shown and when you toggle S by clicking legend, S' will automatically toggle.
linkedTo : http://api.highcharts.com/highstock#plotOptions.series.linkedTo
Location of code:
As mentioned in algo, you need to read existing series and insert auxiliary series. You can do this in the load() callback function which is called when the chart has finished loading and all the series are available to access.
Load Callback : http://api.highcharts.com/highstock#chart.events.load
Adding a series : http://api.highcharts.com/highstock#Chart.addSeries()
Cheers!
On page 29 it says "The leaves of a parse tree read from left to right form the yield of the tree, which is the string generated or derived from the nonterminal at the root of the parse tree. In Fig. 2.2 the generated string is 9-5*2. In that figure, all the leaves are shown at the bottom level. Henceforth, we shall not necessarily line up the leaves in this way." why not?
It also says "Any tree imparts a natural left-to-right order to its leaves, based on the idea that if a and b are two children with the same parent, and a is to the left of b, then all descendants of a are to the left of descendants of b." what does it mean?
P.S It's the second edition of the book
So first of all, for anyone else wanting to comment on this, the page numbers above refer to the first edition. In the second edition, the page number is 46, and the diagram referred to is figure 2.5.
EDIT: The author, when referring to extending the leaves down to the bottom, is talking about moving all leaves of the tree to be aligned vertically with each other, whether or not they are at the same level in the tree. Figure 2.2 has them extended to the bottom, such that every leaf is at the bottom of the diagram, aligned together vertically from left to right. If you look at some of the other diagrams later in the book, this is not done, and leaves are shown vertically aligned with other nodes at the same level, whether or not those other nodes are leaves. This latter way is the normal way of drawing trees, and is the most space efficient.
As for your first question, I believe the reason they do not do that is to save room. If you look at the right hand side of figure 2.4, if the author was to extend the leaves down to the bottom, then the subtree with letter as its root would have to be moved to the right, taking up more room than what is actually needed. While this is a minimal case and doesn't make a huge difference, one could imagine a larger tree (which I'm sure is in the book, although I didn't go looking) which would need more room.
For the second question, it is essentially saying that if you had a*b + c*d, and you considered the multiplications as siblings (as they would be to keep order of operations valid), then the leaves a and b would be to the left of c and d in the tree, just as they are to the left of c and d in the equation. Essentially its just saying what it already said in the first part, which is that the tree's leaves should be able to be read left to right in order to reproduce the original syntax exactly, not switching the ordering of any portions (i.e. if the tree read left to right c*d + a*b, that might still be valid, but would not be a tree we are considering).
I'm in an ergonomic sort of mood, and realizing that I waste many precious milliseconds by lifting my hands up from the letter keys over to the arrow keys in order to move my cursor. Is there a handy alterate way to move the cursor I can access in Textmate?
Generally, I'm looking for ways to keep my head up more while programming. I'd like to, for example, be able to copy an entire line into the clipboard without lifting my fingers. Can textmate take me where I want to go, or should I start thinking about making a move to Vim or some such?
ctrl+f moves cursor one character forward
ctrl+b .. and backward
(hold alt/option to skip by word)
ctrl+a beginning of line
ctrl+e .. and end of line
ctrl+n move to next line
ctrl+p .. and to previous