Use the tree-view in Atom editor init script - coffeescript

I'm trying to write a init script for the Atom editor to add a custom command to be able to reveal the currently opened editor file in the tree-view with one key combination, instead of two.
Here is an example code (which makes something different) to make clear how it generally has to look like.
atom.commands.add 'atom-editor', 'custom:cut-line', ->
editor = atom.workspace.getActiveEditor()
editor.selectLine()
editor.cutSelectedText()
The two commands I need should not be sent to the editor, but to the tree-view. Here are the two commands:
tree-view:toggle-focus
tree-view:reveal-active-file
I assume I have to do something similar as above, like getActiveTreeView or something like that. I tried to google it but it doesn't seem to be obvious. Does someone know how to do this?
It could look something like this:
atom.commands.add 'atom-editor', 'custom:show-active-file', ->
tree-view.toggle-focus()
tree-view.reveal-active-file()

You can use the atom.commands.dispatch() method to send a command when getting a hold of the object to send the commands to is hard. In your case, you can use:
atom.commands.add 'atom-editor', 'custom:show-active-file', ->
atom.commands.dispatch(atom.workspaceView.element, 'tree-view:toggle-focus')
atom.commands.dispatch(atom.workspaceView.element, 'tree-view:reveal-active-file')

Sadly, Lee's answer is not correct anymore. Within changes in the API the changed the naming of atom.workspaceView to atom.workspace.
So, if anyone gets here (sure questions and answer is a "bit" old), here's the current working script.
atom.commands.add 'atom-editor', 'custom:show-active-file', ->
atom.commands.dispatch(atom.workspace.element, 'tree-view:toggle-focus')
atom.commands.dispatch(atom.workspace.element, 'tree-view:reveal-active-file')
#Source
https://discuss.atom.io/t/workspaceview-events/14595/4

Related

Charles Proxy Rewrite & MapLocal - how to match exact query

I only want to return certain response specifically for /path/embed=profile&prefetch=true&couples_only=false and NOT embed=profile&prefetch=true&couples_only=false&ANYTHINGELSE
But Charles seems to be treating the 2 queries the same
What I've tried
/path/embed=profile&prefetch=true&couples_only=false? - hoping the ? will match 1 character or nothing, ruling out the wanted longer queries
embed=profile&prefetch=true&couples_only=false(?!&) - standard regex, tested in regexr.com
What else can I do?
From what I remember, it's a bug and it hasn't fixed ever since.
You might try Proxyman, which is similar to Charles and it will solve your problem.
Here is the step:
Setup the certificate on your macOS (Certificate -> Install on macOS)
Make a request
Right-click to show a menu context -> Tool -> Map Local or Breakpoint
Create a rule with default value -> It will match exactly the query as you wish.
For the Map Local, you can modify the local file in the Editor.
For the Scripting (It's the same with ReWrite, but write by Javascript)
Disclaimer: I create this app. Hope that it can help you for daily works.

How to debug long scripts in Chrome?

I have a page which has a script tag. The script inside that tag is very long, but I would like to debug it. Unfortunately, I cannot scroll to the relevant place in the Console, because after a certain length the script is simply not displayed, see the attachment:
As you can see, it ends with
return !filt...
The actual function looks like this:
this.validate = function(filters) {
for (var filter in filters) {
if (!innerValidation(filters[filter].filterType, filters[filter].evaluatedValue, data[filters[filter].key])) {
return filters[filter].isOr;
}
}
return !filters[filter].isOr;
};
Question: Why does Chrome truncate my script and how could that be changed?
Note, that I know I could load it from an external file, but I am actually interested to know the cause of this behavior.
The display of the script is truncated but it still parses and runs the code correctly. You should be able to view the full code in the Sources tab under the relevant host and put breakpoints in there.
If you have a long script, it is best to make that into its own file instead. This will provide you with the best debugging experience.
The Elements panel truncates large scripts to help keep things fast and there is no way to undo this. Therefore, you would need to use some external debugging tools to try and get at this, but even then most of them work best with external script files as well.
Inline scripts should be very short if ever used. For any decent sized chunks of scripting, allocate that into its own file.

How to store and call a simple mongodb procedure

I often call the same commands in MongoDb command shell, for example :
db.user().find().pretty();
How would you store and call back this command ?
Ideally converting it to something like this :
db.findp( 'user' );
I believe this is NOT what your looking for, now that I read your question again: http://docs.mongodb.org/manual/applications/server-side-javascript/
Instead you are looking to modify the console in such a manner to make your life easier.
I should note, right now, that there is actually an extension which can do this sort of auto-formatting for you made by 10gen: https://github.com/TylerBrock/mongo-hacker
However if you wish to modify the files behind MongoDBs console a little more then you will need to do some manual labour.
There is a rc script in your home directory called .mongorc.js. In this file you can place any custom code you like (as #Asya mentioned) and it will actually become a command within the console.
In you rc file you could place a function like:
DB.prototype.pfind = function(col){
return this[col].find().pretty();
};
Or you could write:
DBCollection.prototype.pfind = function(){
return this.find().pretty();
};
Then you should be able to do:
db.pfind('users');
Or with the second command:
db.users.pfind();
Of course this method is for Linux, I am unsure about Windows, however, Windows should have an rc type script somewhere I believe.

cfscript Code Assist in CFBuilder

I'm increasingly using cfscript, and like it where appropriately used.
One problem is that there doesn't appear to be any code assist for cfscript in CF Builder, so I find myself writing the tag of a function to leverage the code Assist, then converting to cfscript (which is silly).
For example:
addParam() is the cfscript equivalent of <cfqueryparam >. I get code assist when writing the the tag version, but not the script equivalent.
Does anyone know if there is a code assist library available for cfscript in cfBuilder? Or is this just a downside of working with cfscript?
Many Thanks in advance!
Jason
Your example is not using native CFScript, it's using the hack-solution Adobe provided for some shortcomings of CFScript's coverage of CF tags, which are implemented as a bunch of CFCs in the custom tags dir of your install. This stuff is not representative of CFML & its CFScript support as a whole.
I find that CFB gives hinting for most native functionality... is this not the case for you? What if you try listAppend() for example? Do you get code-assist for that?
UPDATE
I wonder if you get a warning in CFB on your line equivalent to this:
o = new Query();
? I do, by default. I have to make a link to the CustomTags/com dir, and then use this syntax:
o = new com.adobe.Query();
Then I don't get a warning, and indeed I get the code assist you're expecting. I cannot get it to give me hinting on just the non-qualified path to Query.cfc though.
Not ideal. Or maybe I'm missing something, too.

How could I embedded socket in Lua internally, just like oslib, debuglib?

I want to implement the function like embedding the socket function in my Lua build.
So I don't need to copy socket.core.dll any more (just for fun).
I search the maillist, and see some guys discuss the topic,
http://lua-users.org/lists/lua-l/2005-10/msg00269.html
But I have question for the details steps, who could give me a detailed steps for changing the lua and luasocket code to make them work together (not with dll method).
I tried these steps in windows xp with VC2008:
1) copy luasocket code to Lua project.
2) add some code
static const luaL_Reg lualibs[] = {
{"", luaopen_base},
{LUA_LOADLIBNAME, luaopen_package},
{LUA_TABLIBNAME, luaopen_table},
{LUA_IOLIBNAME, luaopen_io},
{LUA_OSLIBNAME, luaopen_os},
{LUA_STRLIBNAME, luaopen_string},
{LUA_MATHLIBNAME, luaopen_math},
{LUA_DBLIBNAME, luaopen_debug},
{LUA_SOCKETLIBNAME, luaopen_socket_core}, // add this line
{LUA_MIMELIBNAME, luaopen_socket_core}, // add this line
{NULL, NULL}
};
3) build the project, and run it.
When I type print(socket._VERSION), it shows luasocket 2.0.2, it is correct.
When I type print(socket.dns.toip("localhost")), it shows 127.0.0.1 table: 00480AD0, it is correct too.
But when I try to use other features, for example bind, it can't work.
Who could tell me the reason?
you need put luasocket stuff into the package.preload table, in this way:
lua_getfield(L, LUA_GLOBALSINDEX, "package");
lua_getfield(L, -1, "preload");
lua_pushcfunction(L, luaopen_socket_core);
lua_setfield(L, -2, "socket.core");
// add mime.core yourself...
luasocket is a mixed C/lua module, you need to bundle both versions into your application if you want it to work without any extra files.
socket.lua loads socket.core (from socket/core.dll)
mime.lua loads mime.core (from mime/core.dll)
So in order for your application to work you will need to build all the .dll files and the .lua files into your application and manually load them (or set them up to be loaded correctly via custom package loaders).
The email you quoted is tweaking the package.preload table (in a way that appears a tad odd now but might work anyway) to get the built-in C code to be loaded correctly when require is called.
Try running
for k, v in pairs(socket) do print(k, v) end
and maybe we'll be able to help.