Sublime Text: select the object containing the insertion point? - sublimetext2

I'd like to select an object around the insertion point/cursor in Sublime Text,
eg, given:
{
'foo':'bar',
'baz':{
'zoo|':'zam' <- Note insertion point here
}
}
I'd like to be able to highlight the object around the insertion point, in this case:
The string 'zoo'
The hashmap containing that string
The parent hashmap
Depending on how many times I repeat the key combo / mouse action.
Is there a way to do this, either built into sublime or with an extension?

Check out the Selection menu. Specifically, the Expand to Scope option. I know there us a key command for it (ctrl+shift+space in Windows/Linux, Shift+Command+Space in OS X)

Related

Can I tell PhpStorm what the return type of a function is going to be?

So if I have a function and in the PHPDoc I specify it'll return a SqsProcessResult object, then I call a function to create a new one of those objects but that function's PHPDoc say return type of Object (as it's a generic factory function) PhpStorm throws up an orange warning.
Can I annotate or otherwise tell PhpStorm the return type will be SqsProcessResult?
Yes, you can .. but due to the nature of the issue it may not be cleanest/elegant solution (at least that's what others may say).
Few options:
#1. Just suppress this inspection for that line.
Place caret in the highlighted area and press Alt + Enter (or get the same menu via "light bulb" icon)
Find the most suitable entry .. and press Arrow Right key (or mouse click on the tiny triangle icon) to expand submenu
Once there -- choose Suppress for statement option -- a new inline PHPDoc comment will be added just above tat line that instructs PhpStorm to ignore that specific Inspection in the next line.
Will be something like this:
/** #noinspection PhpIncompatibleReturnTypeInspection */
return \Yii::createObject(...);
Pros: no warning from IDE side
Cons: extra PHPDoc comment to satisfy IDE (which is needed considering the circumstances)
#2. Use some intermediate variable that you can type hint in place.
Add something like this instead of that existing single line:
/** #var SqsProcessResult $res */
$res = \Yii::createObject(...);
return $res;
Pros: no suppression comment
Cons: extra variable (and still extra PHPDoc comment) for basically no reason
This one mainly can be used in longer methods where such variable (generic Object) will be created in the beginning/middle of the function body and then used later.
#3. Play with .metadata functionality and provide resolution logic for actual \Yii::createObject() (so IDE chooses the right class based on input parameter).
https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Advanced+Metadata
This is how quite a few tools working: IDE helper for Laravel, Symfony helpers, DI Container helpers etc

Quartz composer - output specific number

I'm trying to achieve something quite simple in Quartz Composer. I'm not sure which patches to use. I'm used to Max/MSP, and I can't find an equivalent for doing something simple: send a number out of an output with a bang or toggle. In Max you just use the a float or integer object, set the number and then send it with bang. I cannot find a simple number patch, or the equivalent of a bang. Is there such a thing?
Any help would be much appreciated.
Quartz Composer isn't event-based. You'll have to manage yourself the way you want to output things.
If I understand well : you want to output a number on an event (keyboard or else, I guess) and keep it until the next event.
If you already know your values, I suggest you connect to a Number Multiplexer, for example :
keyboard -> counter -> multiplexer -> image with string -> sprite
If you don't know them :
keyboard -> sample & hold (sample input)
dynamic number -> sample & hold (value input) -> image with string -> sprite
Keyboard is there to generate your 'event'. The values won't move until the next event your throw (managed by the Counter patch Increment/Decrement inputs in the first example, by the Sample input in the second).

MSFT HTML Help: How to reach second level of keyword?

I am trying to use MSFT HTML Help to provide Help System for one of our applications.
I encounter a problem and couldn't find any clue in any documentation. I believe it's a simple problem with easy solution, just need to know it:).
HTML Help keyword file allow users to create multiple level of keywords. After opening the Help Window and enter the "Index" tab, there is a "Type in the keyword to find:" area where user can input keywords, all available keywords are also showed below. While typing, the correct hit keyword will be scrolled into the window and highlighted.
The problem is second level keyword is not scrolled and high lighted correctly. After typing the first level keyword and finding the keyword, then next no matter pressing what key the second level keyword cannot be highlighted correctly. As an result, the topic relating to the second key cannot be displayed correctly.
Anyone know what is the separator key between the different level of keywords to use to continue to search in next level of keyword? This problem also happens using HTML Help API, where an F1 key should find the second level keyword but actually could not.
For example, I have the following keywords:
key1
key2
x_subkey_of_key2
y_subkey_of_key2
z_subkey_of_key2
key3
key4
After typing key2 and hilights key2, then no matter which key I press, it cannot highlight y_subkey_of_key2. Many key will high lights z_subkey_of_key2 which is the last subkey of key2.
Any ideas?
Thanks a lot.
Ahaa!!! After one hours' typing and trying, I figured out that TWO SPACES are needed between the first level keyword and second level keyword, and an Enter key is needed at last to show the topic linked from the second keyword!!!!
Remember, exactly two spaces! one or three does not work. The trick is, while typing the second space and second keyword, some other keyword get highlighted in the list of keywords, which can make you think you have already made a mistake and would not continue to finish typing the second keyword! Is this a hoax by Microsoft engineer?
However, although manually it works, seems the software API does not work immediately with the TWO spaces. If I call the following API in C# upon F1 key pressed:
System.Windows.Forms.Help.ShowHelp(this, "file:///C:/apps/MyHelpContentNew/QACT.chm",
System.Windows.Forms.HelpNavigator.KeywordIndex, "key2 x_subkey_of_key2");
it does not show the topic linked from x_subkey_of_key2. But it's almost there, the Help Window shows up with correct two levels' keywords put in the search TextBox, only missing a "Car-Return"!
Then I tried to add the car-return like this:
System.Windows.Forms.Help.ShowHelp(this, "file:///C:/apps/MyHelpContentNew/QACT.chm",
System.Windows.Forms.HelpNavigator.KeywordIndex, "key2 x_subkey_of_key2\n");
It doesn't work either. So I guess I need send a car-return key to the Help Window programmingly. Will post if I once I implement it.
Now I made it work also in the program in handling F1 key. Upon handling F1 key, I called this API to launch the Help Window and populate the keyword textbox with two levels keywords separated with two spaces:
{
System.Windows.Forms.Help.ShowHelp(this, "file:///C:/apps/MyHelpContentNew/QACT.chm",
System.Windows.Forms.HelpNavigator.KeywordIndex, "key2 x_subkey_of_key2");
}
Then, I need send a "ENTER" key to that Help Window. I read some MSDN doc and figured out the following ways to send the "ENTER" key to that window:
First we need call Win32 function EnumChildWindows() to lookup all open windows. The Win32 function will callback to C# for processing of each open window. So when calling the Win32 function, we need pass a C# function as callback. This C# function is defined as a Delegate and inside it we can filter out the HTML Help Window and send "ENTER" key to it. The HTML Help Window is usually called Your-App-Name+Help. For example, if you application is named "XYZ", then the HTML Help window launched by ShowHelp() is called "XYZ Help". Here is the code:
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
class YourClass {
[DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
// declare the delegate
public delegate bool WindowEnumDelegate(IntPtr hwnd,
int lParam);
// declare the API function to enumerate child windows
[DllImport("user32.dll")]
public static extern int EnumChildWindows(IntPtr hwnd,
WindowEnumDelegate del,
int lParam);
// declare the GetWindowText API function
[DllImport("user32.dll")]
public static extern int GetWindowText(IntPtr hwnd,
StringBuilder bld, int size);
//define your callback function:
public static bool WindowEnumProc(IntPtr hwnd, int lParam)
{
// get the text from the window
StringBuilder bld = new StringBuilder(256);
GetWindowText(hwnd, bld, 256);
string text = bld.ToString();
if (text.Length > 0 )
{
if (text == "XYZ Help")
{
//IntPtr h = p.MainWindowHandle;
SetForegroundWindow(hwnd);
SendKeys.Send("{ENTER}");
}
}
return true;
}
//In your F1 key handler, after launch the Help Window by calling ShowHelp(), instantiate the //callback function delegate and invoke the EnumChildWindows():
private void GenericTreeView_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F1)
{
System.Windows.Forms.Help.ShowHelp(this, "file:///C:/apps/MyHelpContentNew/QACT.chm",
System.Windows.Forms.HelpNavigator.KeywordIndex, "key2 x_subkey_of_key2");
// instantiate the delegate
WindowEnumDelegate del
= new WindowEnumDelegate(WindowEnumProc);
// call the win32 function
EnumChildWindows(IntPtr.Zero, del, 0);
}
}
}
Voila!
You will see that upon pressing F1 key, the Help Window nicely opens the correct HTML file and slides to the anchor that is pointed to by the two level keywords!
BTW, I found putting the index inside the HTML file does not help (even if I enable the option of using keyword inside HTML file). I have to put the keyword in the keyword file explicitly.
Enjoy!

how do i decode/encode the url parameters for the new google maps?

Im trying to figure out how to extract the lat/long of the start/end in a google maps directions link that looks like this:
https://www.google.com/maps/preview#!data=!1m4!1m3!1d189334!2d-96.03687!3d36.1250439!4m21!3m20!1m4!3m2!3d36.0748342!4d-95.8040972!6e2!1m5!1s1331-1399+E+14th+St%2C+Tulsa%2C+OK+74120!2s0x87b6ec9a1679f9e5%3A0x6e70df70feebbb5e!3m2!3d36.1424613!4d-95.9736986!3m8!1m3!1d189334!2d-96.03687!3d36.1250439!3m2!1i1366!2i705!4f13.1&fid=0
Im guessing the "!" is a separator between variables followed by XY where x is a number and y is a lower case letter, but can not quite figure out how to reliably extract the coordinates as the number/order of variables changes as well as their XY prefixes.
ideas?
thanks
Well, this is old, but hey. I've been working on this a bit myself, so here's what I've figured out:
The data is an encoded javascript array, so the trick when trying to generate your own data string is to ensure that your formatting keeps the structure of the array intact. To do this, let's look at what each step represents.
As you're correctly figured out, each exclamation point defines the start of a value definition. The first character, an int value, is an inner count, and (I believe) acts as an identifier, although I'm not 100% certain on this. It seems to be pretty flexible in terms of what you can have here, as long as it's an int. The second character, however, is much more important. It defines the data type of the value. I don't know if I've found all the data types yet, but the ones I have figured out are:
m: matrix
f: float
d: double
i: integer
b: boolean
e: enum (as integer)
s: string
u: unsigned int
x: hexdecimal value?
the remaining characters actually hold the value itself, so a string will just hold the string, a boolean will be '1' or '0', and so on. However, there's an important gotcha: the matrix data type.
The value of the matrix will be an integer. This is the length of the matrix, measured in the number of values. That is, for a matrix !1mx, the next x value definitions will belong to the matrix. This includes nested matrix definitions, so a matrix of form [[1,2]] would look like !1m3!1m2!1i1!2i2 (outer matrix has three children, inner matrix has 2). this also means that, in order to remove a value from the list, you must also check it for matrix ancestors and, if they exist, update their values to reflect the now missing member.
The x data type is another anomaly. I'm going to guess it's hexdecimal encoded for most purposes, but in my particular situation (making a call for attribution info), they appear to also use the x data type to store lat/long information, and this is NOT encoded in hex, but is an unsigned long with the value set as
value = coordinate<0 ? (430+coordinate)*1e7 : coordinate*1e7
An example (pulled directly from google maps) of the x data type being used in this way:
https://www.google.com/maps/vt?pb=!1m8!4m7!2u7!5m2!1x405712614!2x3250870890!6m2!1x485303036!2x3461808386!2m1!1e0!2m20!1e2!2spsm!4m2!1sgid!2sznfCVopRY49wPV6IT72Cvw!4m2!1ssp!2s1!8m11!13m9!2sa!15b1!18m5!2b1!3b0!4b1!5b0!6b0!19b1!19u12!3m1!5e1105!4e5!18m1!1b1
For the context of the question asked, it's important to note that there are no reliable identifiers in the structure. Google reads the values in a specific order, so always keep in mind when building your own encoded data that order matters; you'll need to do some research/testing to determine that order. As for reading, your best hope is to rebuild the matrix structure, then scan it for something that looks like lat/long values (i.e. a matrix containing exactly two children of type double (or x?))
Looks like the developer tools from current browsers (I am using Chrome for that) can give you a lot of info.
Try the following:
Go to Google Maps with Chrome (or adapt the instructions for other browser);
Open Developer Tools (Ctrl + Shift + I);
Go to Network tab. Clear the current displayed values;
Drag the map until some url with encoded data appears;
Click on that url, and then go to the Preview sub-tab;
Try this.
function URLtoLatLng(url) {
this.lat = url.replace(/^.+!3d(.+)!4d.+$/, '$1');
this.lng = url.replace(/^.+!4d(.+)!6e.+$/, '$1');
return this;
}
var url = new URLtoLatLng('https://www.google.com/maps/preview#!data=!1m4!1m3!1d189334!2d-96.03687!3d36.1250439!4m21!3m20!1m4!3m2!3d36.0748342!4d-95.8040972!6e2!1m5!1s1331-1399+E+14th+St%2C+Tulsa%2C+OK+74120!2s0x87b6ec9a1679f9e5%3A0x6e70df70feebbb5e!3m2!3d36.1424613!4d-95.9736986!3m8!1m3!1d189334!2d-96.03687!3d36.1250439!3m2!1i1366!2i705!4f13.1&fid=0');
console.log(url.lat + ' ' + url.lng);

How to find out what character the user pressed in a WinRT app if the character not is included in the Virtual key enums?

In short:
How can I in a world-wide Windows Store app correctly validate on a page if a user pressed one of the keys not included in the VirtualKey Enum list? (http://msdn.microsoft.com/en-us/library/windows/apps/windows.system.virtualkey.aspx) In my case it is the “,” and “´” characters I need to handle.
Detailed:
I am stucked on how to validate keyboard input from different keyboard layouts correctly in my Windows Store app. There are many posts here about it but noone seems to have an answer.
My app accepts keyboard input on a page (without any textboxes) to validate key sequences.
I have hooked up on Window.Current.Dispatcher.AcceleratorKeyActivated event to handle all inputs (see: How to detect ALT (Menu) button keydown on global page level in a WinRT app). As you can see in the code example below I use the AcceleratorKeyEventArgs to find out what VirtualKey is pressed.
And it works brilliant well on my Swedish keyboard and from my understanding it will also work as good for all users around the world because the virtualkeys is the same no matter keybord layout or language settings.
Now my problem:
The Windows.System.VirtualKey enum just have 165 buttons defined and two of the keys I need to validate is not included: "," and "´".
When I use a Eng/Swe keyboard setting pressing "´" key the AcceleratorKeyEventArgs.VirtualKey gives me "219"
And when i use a Eng/US keybord setting pressing the "´" key (i checked in notepad what key will generate a "´", the AcceleratorKeyEventArgs.VirtualKey gives me "188".
Same problem is described here I think:
http://social.msdn.microsoft.com/Forums/windowsapps/en-US/c3099f93-6365-4254-abba-d512b05f2edd/winrt-equivalent-for-mapvirtualkey
I tested to extend the VirtualKey enum with more characters by using this tecnique:
http://useranswer.com/answer/how-to-convert-a-virtualkey-to-a-char-for-non-us-keyboard-layouts-in-winrt/
But the Windows App Certification Kit failed with "API MapVirtualKeyA in user32.dll is not supported for this application type"
Example code:
public PractisePage()
{
this.InitializeComponent();
Window.Current.Dispatcher.AcceleratorKeyActivated +=Dispatcher_AcceleratorKeyActivated;
_vm = (PractisePageVm)DataContext;
}
private void Dispatcher_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs args)
{
switch (args.EventType)
{
case CoreAcceleratorKeyEventType.SystemKeyUp:
case CoreAcceleratorKeyEventType.KeyUp:
_vm.HandleKeyUp(args.VirtualKey);
break;
case CoreAcceleratorKeyEventType.SystemKeyDown:
case CoreAcceleratorKeyEventType.KeyDown:
if (args.KeyStatus.WasKeyDown == false)
{
_vm.HandleKeyDown(args.VirtualKey);
}
break;
}
args.Handled = true;
}
This is just not how virtual keys work. They represent a specific key on a keyboard and have a code that's independent of the keyboard layout and the user's language. What character they produce however greatly depends on the active keyboard layout, the state of the modifier keys (Alt, Ctrl, Shift) and whether any dead keys were pressed earlier. Trying to figure this out by yourself will lead to tears, not in the least because some characters are just not available on a keyboard layout in a far-flung country. The virtual key is however always present.
For accelerator keys, you never care about that character. You only care about the virtual key code and the modifier key state. So if you define, say, Alt+A as an accelerator then everybody in the whole world will press the key located to the right of the capslock key. Do note that you will have a documentation problem, that key isn't labeled "A" everywhere. But that's just part of the normal localization effort.