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.
Related
Writing my first generator. Struggling to figure out how to control the indentation.
I found a few methods here and here but it wasn't really clear to me how or if I can apply these.
The generator itself works as expected, it is just annoying that the indentation is wonky and I have to either ignore it or go into the file and fix it (which defeats the purpose of automating the generation of the file content).
Not really sure what relevant code would help, this is how I generate the additional code (one basic example).
def add_site_wide
inject_into_file './app/controllers/application_controller.rb',
after: "class ApplicationController < ActionController::Base\n" do <<-'RUBY'
default_form_builder MdbFormBuilder
RUBY
end
end
Probably pretty easy to see what is going on, the only issue is the line being written default_form_builder MdbFormBuilder indented quite a bit, I can move it around and it does get placed correctly, but then the file generating it looks wonky and becomes hard to read with more content.
Is there a way to apply a method to this, or something else, that would allow me to also pass how many spaces to indent the text?
It really seems like something that should be doable, but I cannot find anything on how to achieve this.
Using the <<- will preserve whitespace on the string.
You could use << but it would required you to put the end of string mark without any indentation aswell.
To keep things pretty, the String class has a method for what you need and it is String#strip_heredoc. This will the indentation on every line.
<<-EOS
i
have
indentation
EOS
will result into
"
i
have
indentation
"
using
<<-EOS.strip_heredoc
i
have
no
indentation
EOS
will result into
"
i
have
no
indentation
"
You could use #engineersmnky sugestion with it to add indentation as needed
<<-EOS.strip_heredoc.indent(2)
i
have
two
indentations
EOS
will result into
"
i
have
two
indentations
"
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.
After googling a bit it seems there is no multi-line comment support in Erlang, is this really the case?
And if so, why?
I know some editors support commenting out regions (adding % first on every line of the region) but i don't really want to pick editor based on this.
It's simple. Use preprocessor:
-ifdef(comment).
Something to comment
You can add text or
function(Declaration) ->
...
Which will removed from file
-endif.
There are no multi-line comments in Erlang.
In general, I haven't found this to be a big deal: I use templates for gen_server and supervisor and a general template for other modules, and all of these include the boilerplate top doc blocks. I get some template support from my editor (Emacs) but you could be editor-agnostic and just write some templates and copy them to any new modules you want.
The biggest use of multi-line comments other than documentation is to comment-out a big chunk of code. Since your Erlang code should generally be small functions, you can just comment out the function call, which is a one-line comment.
I've got MMM-mode set up to edit .html.erb files, but indentation does not work in the ruby sections, and all the different electric behaviours of ruby-mode do the wrong thing. I've changed this sub-mode from ruby-moode to fundamental-mode, and it works much better.
I want to still use ruby-mode's font-locking though, is this possible/easy? Any hints on where to start.
Elisp is comfortable to me, but I don't have too much time right now to dig too deeply myself. Hopefully someone will have a snippet?
I see you haven't yet found an answer. Dunno whether it will be better for this, but you might consider using MuMaMo instead of MMM.
To answer the question, you would define a major mode deriving from fundamental-mode, and in its body just copy the font-lock-related lines from the ruby-mode definition body, the ones setting font-lock- variables and also syntax-propertize-function. Naturally , you need to (require 'ruby-mode) somewhere.
But for .html.erb files I can now recommend using mmm-erb, which was not available when this question was asked.
I've been learning Ruby/Rails with vim. Tim Pope's rails.vim seems like a really good tool to traverse files with, but I keep getting these pesky "E345 can't find file in path" errors. I'm not vim expert yet, so the solution isn't obvious. Additionally, I've tried this and it doesn't apply to my problem.
As an example of the problem. I have a method format_name defined in app/helpers/application_helper.rb and it is used in app/helpers/messages_helper.rb. Within the latter file I put my cursor over the usage of format_name and then hit gf and I get that error. Similar disfunction with commands like ]f and [f
However, it works sometimes. I was able to gf from user to the app/models/user.rb
Ideas?
I think that is a limitation of rails.vim. It does not support “finding” bare methods. Supporting something like that would require one of the following:
an exhaustive search of all the source files for each “find” request
(which could be expensive with large projects),
“dumb” indexing of method names
(e.g. Exuberant Ctags and gControl-]; see :help g_CTRL-]), or
smart enough parsing of the code to make a good guess where the method might be defined
(which is hard to do properly).
If you know where the method is, you can extend many of the navigation commands with a method name:
:Rhelper application#format_name
But, you do not have to type all of that in. Assuming the cursor is on format_name you can probably just type:RhTabspaceappTab#Control-R Control-W (see :help c_CTRL-R_CTRL-W).