How do I write Regex for a SublimeText2 snippet that does both a replace and a slice? - code-snippets

I've been looking at making more snippets for Sublimetext2. I've been looking at http://sublimetext.info/docs/en/extensibility/snippets.html and other questions here and I was able to write this snippet to get the name of the file as a function name:
<content><![CDATA[function ${1:${TM_FILENAME/(.+)\..+|.*/$1/:name}$SELECTION()
{
}]]></content>
But now I am trying to write one that takes TM_FILEPATH does a replace and slices of the filename and the beginning of the path. For example I want to turn this:
"/Library/WebServer/Documents/projects/CGI/source/com/test/play/Bla.js"
into this:
"com.test.play"
I am stumped by the regex syntax and what I should do with "${var_name/regex/format_string/options}". Can anyone explain to me how to write such a regex, and how to use these four items to rewrite the TM_FILEPATH variable?

Related

How to deobfuscate this?

I obfuscated this script using some site
But i'm wondering how to deobfuscate it? can someone help me?
i tried using most decompilers and a lot of ways but none has worked
local howtoDEOBFUSCATEthis_Illll='2d2d341be85c64062f4287f90df25edffd08ec003b5d9491e1db542a356f64a488a1015c2a6b6d4596f2fa74fd602d30b0ecb05f4d768cd9b54d8463b39729eb1fe84630c0f8983f1a0087681fe4f2b322450ce07b
something like that for an example.
the whole script: https://pastebin.com/raw/fDGKYrH7
First reformat into a sane layout. a newline before every local and end will do a lot. Then indenting the functions that become visible is pretty easy.
After that use search replace to inline constants. For example: local howtoDEOBFUSCATEthis_IlIlIIlIlIlI=8480; means you can replace every howtoDEOBFUSCATEthis_IlIlIIlIlIlI with 8480. Though be careful about assignments to it. If there are any then it's better to rename the variable something sensible.
If an identifier has no match you can delete the statement.
Eventually you get to functions that are actually used.
Looking at the code it seems to be an interpreter implementation. I believe it's a lua interpreter
Which means that you'll need to verify that and decompile what the interpreter executes.

Is it possible to use compiler directives in quotations?

Let's say I have this code
ShowMessage( {$I test.inc} );
If I create the file test.inc with content 'hello' and I execute the code I get a message saying hello and it's OK. But I don't want to write quotations in the included file and do something like this:
ShowMessage('{$I test.inc}');
and then write a simple hello in test.inc. That means that I'm looking to write compiler directives in the midst of string. Is it possible?
One dirty way to do this would be:
ShowMessage({$I Quote.inc}{$I test.inc}{$I Quote.inc});
I hope others have better solutions.

getting a substring from a text file for later use

I have a text file that contains version information. There are multiple lines, but the specific line i need looks like this:
#define SW_VERSION "3.4.3.1 R3 08-06-12"
I specifically need the 3.4.3.1 R3 from the text file.
My first thought was to do execute a short script that would grab this data out and use a set for later use, though i am having quite a bit of trouble getting it to work.
I ran this: Find /I "#define SW_VERSION" C:\SW\bin\SW_Version.txt
and it showed me the line in the file that i expected, but i couldn't figure out how to parse it afterwards. Help?
You can write a custom task for Ant.
Your custom task would parse the version line and extract the information you need.

Tokenize .htaccess files

Bet you didn't see this coming? ;)
So, a project of mine requires that I specifically read and make sense out of .htaccess files.
Sadly, searching on Google only yields the infinite woes of people trying to get their own .htaccess to work (sorry, couldn't resist the comment).
Anyway, I'm a bit scared of trying to get this thing out of open-source projects that use it. See, in the past few weeks, I ended up wasting a lot of time trying to fix my issues with this strategy, only to find out that I did better to read RFCs & specs and build the thing my way.
So, if you know about a library, or any (hopefully clean!) code that does this, please do share. In the mean time, if you know about any articles about .htaccess file format, I'm sure they'll be very handy. Thanks.
NB: I'm pretty much multilingual and could make use of any codebase, even though the end code will be Delphi. I know I'm asking too much, but I'd love to see less of C++. Just think of my mental health before sharing C++ code. :)
Edit: Well, I think I'm just going to do this manually myself. The file structure seems to be:
directive arg1 arg2 argN
<begin directive section>
</end directive section>
# single line comment
.htaccess grammar is actually the exact same as the Apache configuration itself, and example parsers do exist for it.
If you're looking to write your own, you are mostly correct on the format. Remember, section tags can be nested and can have parameters (like <Location />)
English method of parsing:
For each line in the file:
Strip whitespace from beginning and end of line.
If the line starts with a '#':
Parse it as a comment (or skip it)
Else, If the line starts with a '<':
If the next character is a '/', the line is a closing tag:
Seek to the next '>' to get the tag name, and pop it from the tag stack.
Else, the line is an opening tag:
Seek to the next '>' for the tag name.
If the tag, trimmed, contains whitespace:
Split on the first whitespace. The right side is params, left is the tag.
(IfModule, Location, etc use this)
Push the tag name to the tag stack.
Else, the line is a directive:
Split the line on whitespace. This is the directive and params.
Just add quote handling and you're set.

How to prevent LaTeX from hyphenating words containing a dash?

I would like to globally prevent LaTeX from hyphenating 'Objective-C'. I am aware of the \hyphenation command, but I don't see how I can make use of it. If I pass 'Objective-C' to this command, the dash will be treated as a hint to hyphenate the word there.
One solution I found is wrapping Objective-C into an mbox each time I use it. However, the document I am writing contains this name a lot, and wrapping it into an mbox each time is ugly (as is defining a command and using this over and over again in the source code).
Why is defining a new command ugly? It's how \LaTeX\ defines itself.
\def\ObjectiveC{\mbox{Objective-C}}
Use \nobreakdash. That's what LyX produces when I insert a nonbreakingdash and convert it to tex.
As suggested here, you could define a command like this:
\newcommand\dash{\nobreakdash-\hspace{0pt}}
and use it like this
Consider the $n$\dash dimensional manifold ...
Also, you could use the babel package and use "~ as a protected hyphen. I'm not sure if using babel is advisable when writing in english, though.

Resources