I have a string that contains an escaped URL:
http%3A%2F%2Fexample.com%3Ffoo%3Dbar+baz
I'm trying to decode it to the following:
http://example.com?foo=bar+baz
However, I can't find any suitable function exported by Drakma. I can encode like so:
* url-string
"http://example.com?foo=bar+baz"
* (drakma:url-encode url-string :utf-8)
"http%3A%2F%2Fexample.com%3Ffoo%3Dbar%2Bbaz"
... so I figure I'm on the right track. If anyone could supply a nudge in the right direction I'd appreciate it :-) I'm using SBCL 1.0.54, built from source on 64-bit Linux Mint 13.
If it helps clarify what I'm trying to do, in Ruby, I'd do the following:
> uri_string = "http%3A%2F%2Fexample.com%3Ffoo%3Dbar+baz"
=> "http%3A%2F%2Fexample.com%3Ffoo%3Dbar+baz"
> URI.decode uri_string
=> "http://example.com?foo=bar+baz"
A quick SLIME session.
CL-USER> (ql-dist:system-apropos "url")
#<SYSTEM curly / curly-20120407-git / quicklisp 2012-05-20>
#<SYSTEM curly.test / curly-20120407-git / quicklisp 2012-05-20>
#<SYSTEM do-urlencode / do-urlencode-20120407-git / quicklisp 2012-05-20>
#<SYSTEM url-rewrite / url-rewrite-0.1.1 / quicklisp 2012-05-20>
CL-USER> (ql:quickload :do-urlencode)
C-cC-dpdo-urlencodeRET
DO-URLENCODE:URLDECODE
Function: (not documented)
DO-URLENCODE:URLENCODE
Function: (not documented)
DO-URLENCODE:URLENCODE-MALFORMED-STRING
Type: (not documented)
DO-URLENCODE:URLENCODE-MALFORMED-STRING-STRING
Generic Function: (not documented)
CL-USER> (do-urlencode:urldecode "http%3A%2F%2Fexample.com%3Ffoo%3Dbar%2Bbaz")
"http://example.com?foo=bar+baz"
Found another solution, with Quri, a uri handling library with encoding and decoding utilities (for uri and parameters):
(url-decode "http%3A%2F%2Fexample.com%3Ffoo%3Dbar%2Bbaz")
;; "http://example.com?foo=bar+baz"
To install with (ql:quickload :quri) and then optionaly (use-package :quri).
(my sources: lisp-lang.org's recommend libraries and awesone-cl).
Related
I am looking for the "best" way in the Julia Programming Language to join parts of a URL into a single URL similar to joinurl in Python.
The full functionality of Python's joinurl is not needed. I'd like to achieve that extra frontslashes are added but also excess frontslashes are remove if needed, i.e.
julia_joinurl("http://localhost/","/index.html") == "http://localhost/index.html"
and
julia_joinurl("http://localhost","index.html") == "http://localhost/index.html".
Is there a Julia package that implements such a high-level function? Or how would I implement this otherwise?
I can't find a joinurl function in Python, so I'm guessing you're referring to urllib.parse.urljoin in the Python standard library. There is a function similar to that in the HTTP.jl package. It creates a URI from the components of the URI:
julia> HTTP.URI(scheme="http", host="example.com", path="/index.html")
HTTP.URI("http://example.com/index.html")
However, it's not as forgiving as the Python urljoin function. You have to start the path argument with a / and you cannot end the host argument with a /:
julia> HTTP.URI(scheme="http", host="example.com", path="index.html")
ERROR: ArgumentError: merge(::HTTP.URIs.URI; scheme::String, userinfo::SubString{String},
host::String, port::SubString{String}, path::String, query::SubString{String},
fragment::SubString{String}) requires !(scheme in ["http", "https"]) ||
(isempty(path) || path[1] == '/')
julia> HTTP.URI(scheme="http", host="example.com/", path="/index.html")
ERROR: ArgumentError: merge(::HTTP.URIs.URI; scheme::String, userinfo::SubString{String},
host::String, port::SubString{String}, path::String, query::SubString{String},
fragment::SubString{String}) requires isempty(host) || host[end] != '/'
I can upgrade php 5.2 in my server. I have to make this server work today (the vacation I have planned tomorrow is under question because of this error) with new testlink. I am stuck with following error i.e Paamayim nekudotayims.
What changes I should do to resolve it?
This link contains the file with the bug.
The Scope Resolution Operator (also called Paamayim Nekudotayim) or in simpler terms, the double colon, is a token that allows access to static, constant, and overridden properties or methods of a class.
SO may be in your codes you try to call static method or properties with wrong operator.
From Wikipedia:
In PHP, the scope resolution operator is also called Paamayim
Nekudotayim (Hebrew: פעמיים נקודתיים), which means “double colon” in
Hebrew.
The name "Paamayim Nekudotayim" was introduced in the
Israeli-developed Zend Engine 0.5 used in PHP 3. Although it has been
confusing to many developers who do not speak Hebrew, it is still
being used in PHP 5, as in this sample error message:
$ php -r :: Parse error: syntax error, unexpected
T_PAAMAYIM_NEKUDOTAYIM
As of PHP 5.4, error messages concerning the scope resolution operator
still include this name, but have clarified its meaning somewhat:
$ php -r :: Parse error: syntax error, unexpected '::'
(T_PAAMAYIM_NEKUDOTAYIM)
I am getting compiler issue when trying to compile a simple test program on erlang. I have tried both on mac os x (lion) and windows 7 (64)
~module(tut).
~export([double/1]).
double (N) ->
N*2.
I have checked that the file is named correctly and the correct modules seem to be installed I am using the otp_win64_R16B on my windows machine. I get the following error on both platforms
16> c(tut).
tut.erl:1: syntax error before: '~'
tut.erl:2: syntax error before: '~'
tut.erl:4: no module definition
tut.erl:4: Warning: function double/1 is unused
Can anyone help?
Well, it should be: -module and -export, with the - not with ~.
You should replace ~ with -. Please take a try.
I am using a REXML Ruby parser to parse an XML file. But on a 64 bit AIX box with 64 bit Ruby, I am getting the following error:
REXML::ParseException: #<REXML::ParseException: #<RegexpError: Stack overflow in
regexp matcher:
/^<((?>(?:[\w:][\-\w\d.]*:)?[\w:][\-\w\d.]*))\s*((?>\s+(?:[\w:][\-\w\d.]*:)?[\w:][\-\w\d.]*\s*=\s*(["']).*?\3)*)\s*(\/)?>/mu>
The call for the same is something like this:
REXML::Document.new(File.open(actual_file_name, "r"))
Does anyone have an idea regarding how to solve this issue?
I've had several issues for REXML, it doesn't seem to be the most mature library. Usually I use Nokogiri for Ruby XML parsing stuff, it should be faster and more stable than REXML. After installing it with sudo gem install nokogiri, you can use something like this to get a DOM instance:
doc = Nokogiri.XML(File.open(actual_file_name, 'rb'))
# => #<Nokogiri::XML::Document:0xf1de34 name="document" [...] >
The documentation on the official webpage is also much better than that of REXML, IMHO.
I almost immediately found the answer.
The first thing I did was to search in the ruby source code for the error being thrown.
I found that regex.h was responsible for this.
In regex.h, the code flow is something like this:
/* Maximum number of duplicates an interval can allow. */
#ifndef RE_DUP_MAX
#define RE_DUP_MAX ((1 << 15) - 1)
#endif
Now the problem here is RE_DUP_MAX. On AIX box, the same constant has been defined somewhere in /usr/include.
I searched for it and found in
/usr/include/NLregexp.h
/usr/include/sys/limits.h
/usr/include/unistd.h
I am not sure which of the three is being used(most probably NLregexp.h).
In these headers, the value of RE_DUP_MAX has been set to 255! So there is a cap placed on the number of repetitions of a regex!
In short, the reason is the compilation taking the system defined value than that we define in regex.h!
This also answers my question which i had asked recently:
Regex limit in ruby 64 bit aix compilation
I was not able to answer it immediately as i need to have min of 100 reputation :D :D
Cheers!
Some time ago I was fiddling with SWI-Prolog editor, trying to get something to work, and I change some configuration settings. It didn't work so I changed it back. Now SWI-Prolog editor is not working correctly. I will load files but when I click 'consult' it will just throw this error:
consult('C:/Users/Cubearth/Documents/Prolog/'filename.pl').
and I am not able to perform queries, on the knowledge base... it just does nothing. I know that it should return:
% library(win_menu) compiled into win_menu 0.00 sec, 20,952 bytes
% library(swi_hooks) compiled into pce_swi_hooks ......... (etc, etc)
For help, use ?- help(Topic). or ?- apropos(Word).
but I am not even getting that. I tried uninstalling both prolog and the editor, but still no luck.
Any ideas on how to fix this?
In order to help, I have included the configuration dump of prolog:
Installation
C:\Program Files (x86)\SWIPrologEditor\SWIMachine.ini
C:\Users\Cubearth\AppData\Roaming\SWIPrologEditor\SWIUser.ini
C:\Users\Cubearth\AppData\Roaming\SWIPrologEditor\SWIColor.ini
[SWI]
PortableApplication=0
Verzeichnis=C:\Program Files\pl
Manual=C:\Program Files\pl\bin\doc\Manual\Contents.html
XPCE=C:\Program Files\pl\bin\doc\UserGuide\Contents.html
[Program]
InterpreterParameter=-L32M
FileExtension=.pl
[Editor]
TabWidth=2
Indent=2
Indenthelp=1
AutomaticIndent=1
FileTab=1
Linenumbering=1
BracketPair=0
CursorBehindLine=1
Author=
Encoding=0
Structure=0
[Code]
Code-Completion=1
Parameter-Hints=1
Delay=100
[Options]
ColoredConsole=1
IntegratedWindow=1
ReturnToContinue=1
TraceStopsDebugToo=1
BAKFiles=1
RemoveWriteProtection=1
FileTabsMultiline=1
Language=C:\Program Files (x86)\SWIPrologEditor\english.ini
[Browser]
UseIEinternForDocuments=1
OnlyOneBrowserWindow=0
Browser=C:\Users\Cubearth\AppData\Local\Google\Chrome\Application\chrome.exe
Title=unknown
AltKeysBrowser=
ProxyEnabled=0
ProxyIP=
ProxyPort=0
[Printer]
Left=20
Top=20
Right=20
Bottom=20
Header=#%PATH%#
Footer=##- %PAGENUM% -
Linenumbers=0
LinenumbersInMargin=1
Let me enlighten the poor lost soul that is cubearth. You should double check to see which version of swi-prolog you installed (32-bit or 64-bit), because swi-prolog editor only works with the 32-bit version. If you tried using the editor with the 64-bit version, you'll get the error described above. ^^ .
p.s. You are welcome.
Enable trace, run cmd --
?- trace. consult('C:/Users/Cubearth/Documents/Prolog/'filename.pl').