Fat free framework Missing argument 1 for {closure}() - fat-free-framework

while following this bit of code
$f3=require('lib/base.php');
$f3->route('GET /brew/#count',
function($f3) {
echo $f3->get('PARAMS.count').' bottles of beer on the wall.';
}
);
$f3->run();
from Fat-Free Framework examples at https://github.com/bcosca/fatfree#routing-engine I get this error in my browser:
Internal Server Error
Missing argument 1 for {closure}()
* /var/www/f3/index.php:36 Base->{closure}
* /var/www/f3/lib/base.php:972
* Base->call(Closure::__set_state(),NULL,'beforeroute,afterroute')
* /var/www/f3/index.php:40 Base->run()
I know the problem is that $f3 is not passed to function as parameter but i don't understand why. Can anybody help me?

I just the same situation! I was using version 3.0.1 from SourceForge. I tried the following, which worked, but created other issues:
$f3=require('lib/base.php');
$f3->route('GET /brew/#count',
function() use ($f3) {
echo $f3->get('PARAMS.count').' bottles of beer on the wall.';
}
);
$f3->run();
The use clause (which isn't very well documented in php) allows you to use variables from the parent scope from an anonymous function. Read more here: Closure vs Anonymous function (difference?)
Try upgrading the F3 core to the latest release. One of the developers recommended to upgrade to the 3.0.2 release from here: https://github.com/bcosca/fatfree. It was a very quick fix!

Related

Awesome WM 4 run_or_raise function

I start to use Awesome 4.0 afters many years on awesome 3.5.
I used aweror lib (you can see it here: https://github.com/lkonga/awesomewm-config) for have a "run or raise" functionality, but I don't find how can I have it with the version 4.0.
Anybody knows how have it?
It seems to be available via the awful.client.run_or_raise function:
https://awesomewm.org/apidoc/classes/client.html#awful.client.run_or_raise
Usage from the documentation:
-- run or raise urxvt (perhaps, with tabs) on modkey + semicolon
awful.key({ modkey, }, 'semicolon', function ()
local matcher = function (c)
return awful.rules.match(c, {class = 'URxvt'})
end
awful.client.run_or_raise('urxvt', matcher)
end);

Arduino and STL

I know this has been posted all over the place but I can not find what I need. I have a Arduino project that I must have vector or another way of allocating a dynamic array safely. I am trying to get the "StandardCplusplus" library to compile but I am getting an error
'Starting combiner'
"C:\Eclipse\eclipse\arduinoPlugin\tools\arduino\avr-gcc\4.8.1-arduino5/bin/avr-gcc" -Os -Wl,--gc-sections,--relax -mmcu=atmega2560 -o "D:/Development/MegaTesting/Release/MegaTesting.elf" ./.ino.cpp.o ./libraries/StandardCplusplus/algorithm.cpp.o ./libraries/StandardCplusplus/associative_base.cpp.o ./libraries/StandardCplusplus/bitset.cpp.o ./libraries/StandardCplusplus/char_traits.cpp.o ./libraries/StandardCplusplus/complex.cpp.o ./libraries/StandardCplusplus/del_op.cpp.o ./libraries/StandardCplusplus/del_opnt.cpp.o ./libraries/StandardCplusplus/del_opv.cpp.o ./libraries/StandardCplusplus/del_opvnt.cpp.o ./libraries/StandardCplusplus/deque.cpp.o ./libraries/StandardCplusplus/eh_alloc.cpp.o ./libraries/StandardCplusplus/eh_globals.cpp.o ./libraries/StandardCplusplus/exception.cpp.o ./libraries/StandardCplusplus/fstream.cpp.o ./libraries/StandardCplusplus/func_exception.cpp.o ./libraries/StandardCplusplus/iomanip.cpp.o ./libraries/StandardCplusplus/ios.cpp.o ./libraries/StandardCplusplus/iostream.cpp.o ./libraries/StandardCplusplus/istream.cpp.o ./libraries/StandardCplusplus/iterator.cpp.o ./libraries/StandardCplusplus/limits.cpp.o ./libraries/StandardCplusplus/list.cpp.o ./libraries/StandardCplusplus/locale.cpp.o ./libraries/StandardCplusplus/map.cpp.o ./libraries/StandardCplusplus/new_handler.cpp.o ./libraries/StandardCplusplus/new_op.cpp.o ./libraries/StandardCplusplus/new_opnt.cpp.o ./libraries/StandardCplusplus/new_opv.cpp.o ./libraries/StandardCplusplus/new_opvnt.cpp.o ./libraries/StandardCplusplus/numeric.cpp.o ./libraries/StandardCplusplus/ostream.cpp.o ./libraries/StandardCplusplus/queue.cpp.o ./libraries/StandardCplusplus/set.cpp.o ./libraries/StandardCplusplus/sstream.cpp.o ./libraries/StandardCplusplus/stack.cpp.o ./libraries/StandardCplusplus/stdexcept.cpp.o ./libraries/StandardCplusplus/streambuf.cpp.o ./libraries/StandardCplusplus/string.cpp.o ./libraries/StandardCplusplus/support.cpp.o ./libraries/StandardCplusplus/typeinfo.cpp.o ./libraries/StandardCplusplus/utility.cpp.o ./libraries/StandardCplusplus/valarray.cpp.o ./libraries/StandardCplusplus/vector.cpp.o arduino.ar "-LD:/Development/MegaTesting/Release" -lm
arduino.ar(new.cpp.o): In function `operator new[](unsigned int)':
C:/Eclipse/eclipse/arduinoPlugin/packages/arduino/hardware/avr/1.6.10/cores/arduino/new.cpp:26: multiple definition of `operator new[](unsigned int)'
./libraries/StandardCplusplus/new_opv.cpp.o:C:/Eclipse/eclipse/arduinoPlugin/packages/arduino/hardware/avr/1.6.10/libraries/StandardCplusplus/new_opv.cpp:24: first defined here
c:/eclipse/eclipse/arduinoplugin/tools/arduino/avr-gcc/4.8.1-arduino5/bin/../lib/gcc/avr/4.8.1/../../../../avr/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions
arduino.ar(new.cpp.o): In function `operator new(unsigned int)':
C:/Eclipse/eclipse/arduinoPlugin/packages/arduino/hardware/avr/1.6.10/cores/arduino/new.cpp:22: multiple definition of `operator delete[](void*)'
makefile:83: recipe for target 'MegaTesting.elf' failed
./libraries/StandardCplusplus/del_opv.cpp.o:C:/Eclipse/eclipse/arduinoPlugin/packages/arduino/hardware/avr/1.6.10/libraries/StandardCplusplus/del_opv.cpp:25: first defined here
collect2.exe: error: ld returned 1 exit status
make: *** [MegaTesting.elf] Error 1
06:23:57 Build Finished (took 21s.666ms)
I have searched here and online and there seems to be a bunch of fixes but none of them work. There was some mention of including a pnew.cpp in one of your files but this file is not in the library anywhere.
All my code contains that I am trying to compile is
#include "StandardCplusplus.h"
#include "Arduino.h"
void setup(void) {
Serial.begin(57600);
}
void loop(void) {
}
There are a couple of versions of this library out there and I have tried the two main forks that I can find and both of them generate this error.
Also I am using Eclipse with the Arduino AVR plugin to compile.
Edit
I thought that commenting out the lines did work until I tried to use a vector. Once I did the StandardCplusplus library got really mad saying that the function new was not defined.
I think that there needs to be something done to the StandardCplusplus library like in new/new_opv delete/delete_opv files? Or is there a better way?
Edit - 2
Alright so I went into the files:
StandardCplusplus/new_opv.h
StandardCplusplus/del_opv.h
And commented out the bodies for the functions and everything seems to be happy. I did a simple test and everything looks like it is working but now I am concerned that I might of removed something that something else in the library might need, can anyone tell me if my changes will hurt anything?
Edit - 3
Well the last fix didn't work so I tried going to another library all together and I am allot closer. I Downloaded this STL-AVR library and had to make a minor edit to vector.h now I am having problems with the pnew.cpp file. Looks like the template is calling a "new" function that is now defined in arduino but if I try to comment out this body I get that it is not defined. I am sure this is some sort of order of the includes or missing one can anyone help?
Those STL like libary versions you have were put together before operator new was added to the Arduino core. Now they are in the core you are getting a multiple definition error.
You can go into your core and comment out the bits causing the multiple definition error.
You can probably just get away with commenting out the function definitions in the .cpp:
C:/Eclipse/eclipse/arduinoPlugin/packages/arduino/hardware/avr/1.6.10/cores/arduino/new.cpp
If you still get the errors, also comment out the function declarations in new.h, but you shouldn't need to as multiple declarations are allowed, only definitions must be unique.

How can I configure call depth in PowerShell?

I was just trying things in PowerShell and got an error about call depth being set to 1000 in some test recursive function. I looked on the Internet for some information and found that this is due to error handling in PowerShell (if I got it right):
The recursion depth limit is fixed in version 1. Deep recursion was causing problems in 64-bit mode because of the way exceptions were being processed. It was causing cascading out-of-memory errors. The net result was that we hard-limited the recursion depth on all platforms to help ensure that scripts would be portable to all platforms.
- Bruce Payette, co-designer of PowerShell
I found it here.
Also I found this exception page on MSDN that states this limit is configurable (but I didn't find anything about how to do this) - see remarks section here.
How can this limit be set?
In PowerShell V1 the maximum call depth is 100:
Using .NET Reflector, we can see in this snippet from the System.Management.ExecutionContext class code,
internal int IncrementScopeDepth()
{
using (IDisposable disposable = tracer.TraceMethod("{0}", new object[] { this.scopeDepth }))
{
if (this.CurrentPipelineStopping)
{
throw new PipelineStoppedException();
}
this.scopeDepth++;
if (this.scopeDepth > 100)
{
ScriptCallDepthException exceptionRecord = new
ScriptCallDepthException(this.scopeDepth, 100);
tracer.TraceException(exceptionRecord);
throw exceptionRecord;
}
return this.scopeDepth;
}
}
that it is not possible to modify the hardcoded 100.
In PowerShell V2 the maximum call depth is 1000
Again when looking at the code, there doesn't seem to be a way around the default maximum call depth.
In PowerShell V3 (CTP) there doesn't seem to be a maximum call depth (unless you run out of resources of course). This behaviour has been described as a bug on connect, so it might change in the final version.

How to Replace content inside custom tag in MediaWiki before saving to database?

First of all, I have both MW 1.16 and 1.17 set up with PHP 5.3.5, MySQL 5.5.8 and Apache 2.2.17.
I've wrote a simple $wgExtensionFunction which right now does nothing.
$wgExtensionFunctions[] = "wfTestExtension";
function wfTestExtension() { global $wgParser;
$wgParser->setHook("myTag", "renderTest");
}
function renderTest($input) {
return $input;
}
What I want to do is, if I type <myTag>Blah blah blah</myTag> in the add or edit form, I want to be able to change the contents inside myTag BEFORE saving it to the database. What mechanism should I use for this? I'm assuming hooks? For example, with the ArticleSave hook, the $text var already has the <myTag> stripped out, so there's no way of trying to parse the string and figuring out what it is that was originally inside the <myTag>
I've spent hours trying to find something on Google, but I've almost given up. Any advice at all would be highly appreciated.
Cheers.
Maybe http://www.mediawiki.org/wiki/Manual:Hooks/ParserBeforeStrip would work:
"Used to process the raw wiki code before any internal processing is applied"
This is another "maybe" but you could try using a combination of a template and the {{subst:}} command (see transclusion).
(See also Wikis and Wikipedia)

IronPython Memory Leak When Calling Function With More Than 13 Parameters

I'm using IronPython 2.6.2 for .NET 4.0 as a scripting platform within a C#/WPF application. Scripts can include their own function definitions, class definitions, etc. I'm not restricting what can be written.
A memory leak appeared in the scripting piece recently after a script change. After commenting out more and more code, we determined that defining and calling a function with more than 13 parameters causes a memory leak. So if you call a function with 14 parameters IronPython will leak.
Here is some sample code on a timer running every 100ms:
_Timer.Enabled = false;
try
{
var engine = Python.CreateEngine();
engine.Execute("def SomeFunc(paramI, paramII, paramIII, paramIV, paramV, paramVI, paramVII, paramVIII, paramIX, paramX, paramXI, paramXII, paramXIII, paramXIV):\r\n\tpass\r\nSomeFunc(1,2,3,4,5,6,7,8,9,10,11,12,13,14)");
//engine.Execute("def SomeFunc(paramI, paramII, paramIII, paramIV, paramV, paramVI, paramVII, paramVIII, paramIX, paramX, paramXI, paramXII, paramXIII):\r\n\tpass\r\nSomeFunc(1,2,3,4,5,6,7,8,9,10,11,12,13)");
// With and without the following line makes no difference
engine.Runtime.Shutdown();
this.Dispatcher.Invoke((Action)delegate()
{
this.Title = DateTime.Now.ToString();
});
}
catch (Exception)
{
}
_Timer.Enabled = true;
Note that I have a 14-parameter version of the script and below it is a commented-out 13-parameter version. The Python script is basically this:
def SomeFunc(paramI, paramII, paramIII, paramIV, paramV, paramVI, paramVII, paramVIII, paramIX, paramX, paramXI, paramXII, paramXIII, paramXIV):
pass
SomeFunc(1,2,3,4,5,6,7,8,9,10,11,12,13,14)
I've tried with and without engine.Runtime.Shutdown() but it makes no difference. The 14-parameter version's memory will climb rapidly and the 13-parameter version's memory will climb slightly and then stabilize.
Any thoughts?
Thanks
- Shaun
There's a magic number of parameters in IronPython - less than that is a different (faster) code path than more. It sounds like there are still some bugs in the fallback code. Can you please open an issue with a self-contained test case?
Looking at the latest code I would think the boundary would be at 15. Can you try again on 2.7 Beta 2 and see if the results are the same?