I want to create 100 tables in batches and preallocate enough underlying memory for them. In addition to using the for loop to dynamically add elements, is there any way more convenient?
//initialize tables list_tables
list_tables=[table(150000:0, `trade_day`secu_code`factor_value, `INT`INT`DOUBLE),
table(150000:0, `trade_day`secu_code`factor_value, `INT`INT`DOUBLE),
table(150000:0, `trade_day`secu_code`factor_value, `INT`INT`DOUBLE),
table(150000:0, `trade_day`secu_code`factor_value, `INT`INT`DOUBLE),
table(150000:0, `trade_day`secu_code`factor_value, `INT`INT`DOUBLE)]
You can use function each and lambda to create multiple tables.
list_tables=each(x->table(150000:0, `trade_day`secu_code`factor_value, `INT`INT`DOUBLE),1..100)
>list_tables[0];
trade_day secu_code factor_value
--------- --------- ------------
Related
I am having trouble with creating a function that includes a filter() function.
I keep getting an error (shown below) with this function:
plot <- function(df, group, varx, vary) {
df %>%
filter(PC == group) %>%
ggplot(aes(x = reorder(get(varx), get(vary)), y = get(vary))) +
geom_col()
}
Error in UseMethod("filter") :
no applicable method for 'filter' applied to an object of class "character"
Anyone have an explanation/solution? Thanks!
I am trying to fill out a form using Internet Explorer. The webpage contains no id's nor class names. So currently I move the mouse to a relative position based on the size of the screen. But this screen resolution dependency is undesired.
Given the webpage's (internal website) lack of classes/ids, how to target its HTML form inputs, text areas, combo boxes, drop downs, date pickers, and buttons other than by screen location?
You could iterate all input elements to identify the ones you need :
#include <IE.au3>
$oIE = _IECreate("http://www.google.com")
$oAs = _IETagnameGetCollection($oIE, "input")
$i = 1
For $oA In $oAs
_IEPropertySet($oA, "innertext", $i)
$i = $i + 1
Next
Next you could use the $i variable to set the right values. In this example the Google search field is the fourth input element so you could fill it out this way:
#include <IE.au3>
$oIE = _IECreate("http://www.google.com")
$oAs = _IETagnameGetCollection($oIE, "input")
$i = 1
For $oA In $oAs
If $i = 4 Then _IEPropertySet($oA, "innertext", "MyValue")
$i = $i + 1
Next
Is there a compiler switch I'm not seeing that would allow me to omit the assembler keyword from assembler functions?
How I do it now, using example from FPC docs:
function geteipasebx : pointer;assembler;
asm
movl (%esp),%ebx
ret
end;
How I would like to do it:
function geteipasebx : pointer;
asm
movl (%esp),%ebx
ret
end;
Can this be done?
EDIT:
compiler source file PSUB.PAS line 170:
{ do we have an assembler block without the po_assembler?
we should allow this for Delphi compatibility (PFV) }
if (token=_ASM) and (m_delphi in current_settings.modeswitches) then
include(current_procinfo.procdef.procoptions,po_assembler);
{ Handle assembler block different }
if (po_assembler in current_procinfo.procdef.procoptions) then ...
I believe this part of the source code of free pascal means that this can only be done in {$MODE DELPHI}.
Yes this can be done. You have to set the compiler compatibility mode to DELPHI and to redefine the asm syntax to ATT, since the mode DELPHI will override it to INTEL.
more concretly, the program:
program Project1;
{$MODE DELPHI}
{$ASMMODE ATT}
function geteipasebx : pointer;
asm
movl (%esp),%ebx
ret
end;
var
p: pointer;
begin
p := geteipasebx;
end.
compiles and run fine.
In our code I have the following, for now please ignore the //* bits;
if (data["someKey"] != null)//*
{
CONSOLE_OUT.info("Print some stuff.");
TARGET::myTarget
{
var someString:String = data["someKey"] as String;//*
someController.setSoemthing(someString.indexOf("soemthing") > -1 ? true : false);//*
}
}
I have set up my FlashCS4 to have the TARGET::myTarget compiler constant set to false, meaning that the code within the compiler constant shouldn't be compiled. At the point of execution data["someKey"] evaluates to null meaning the if statement should NOT execute.
When I debug the following code, the lines with //* on them execute, which is strange behaviour. It skips the initial line after the if statement and goes straight to executing the code that shouldn't have been compiled, bearing in mind that it shouldn't enter the if statement anyway. Its almost as if the presence of the compiler constant is causing the if statement to appear to be a single line, and then still executing the code within the wrong scope.
However, if I add an else statement on the end, the code executes fine;
if (data["someKey"] != null)//*
{
CONSOLE_OUT.info("Print some stuff.");
TARGET::myTarget
{
var someString:String = data["someKey"] as String;
someController.setSoemthing(someString.indexOf("soemthing") > -1 ? true : false);
}
}
else
{
CONSOLE_OUT.info("Print some other stuff.");
}
It should also be noted that in the instance where data["someKey"] evaluates to something other than null, the above version will correctly skip (or not compile) the code within the constant.
I just want to find out if this is a bug, or if I am not using the correct syntax for the compiler constant. If you need any more information then please let me know. I've double check my compiler constants, I am using Flash CS4 to compile and targeting Flash Player 10 if that makes a difference.
Its not bug, compiler will strip any if(false) statement so your conditional constant must be wrapped in condition evaluation.
if (data["someKey"] != null)//*
{
CONSOLE_OUT.info("Print some stuff.");
if(TARGET::myTarget) // it should be conditional statement
{
var someString:String = data["someKey"] as String;//*
someController.setSoemthing(someString.indexOf("soemthing") > -1 ? true : false);//*
}
}
If you look at flex sample, they have applied symbol outside method declaration, so when you write conditional compilation symbol outside member body, member body is included/excluded, but in case of inline statement, flex has no way to determine what to exclude, so it should be used in condition within if.
See answers and links here,
Flash/Flex conditional compilation "else"
I am not sure what you are doing with the TARGET static class.
I have never seen anything like that and without know what TARGET is I wouldn't know how to correct it.
In any case in your if statement you are testing if someKey has a value, however if someKey has not been defined then it wouldn't be null it would be undefined.
With that being said you need to test for it and the proper way to test for it would be like so.
if( data.hasOwnProperty("someKey"){
CONSOLE_OUT.info("Print some stuff.");
TARGET::myTarget <<<<<<< WTH is this????????
{
var someString:String = data["someKey"] as String;
someController.setSoemthing(someString.indexOf("soemthing") > -1 ? true : false);
} }
Also Note that the characters "/*" denote the start of a comment block and all code after that will be commented out.
For example
/* this would be commented
this would be commented
*/
this line would not be commented
[EDIT]
Notice how the first "i.e" is showing the property as undefined.
trace(null == undefined); //Outputs true
trace(null === undefined); //Outputs false
var i:Object;
trace(i); //Outputs null
i = {};
trace(i); //Outputs [object Object]
var i:Object = {a:"b", c:"d"};
trace(i.e); //Outputs undefined
i.e = "f";
trace(i.e); //Outputs f
reference
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
How can i detect the visitors IP Address using HTML for my website?
I have a contactform.html and a formsent.html.
And when formsent.html sends the contact info to my email i also want to see their IP Address!
You can't do it through HTML. However, you can find the IP address of a visitor through PHP.
$ip=$_SERVER['REMOTE_ADDR'];
The following script may be useful to you. You can copy it and save it as {whateveryouwant}.php
<?php
echo "Your IP is";
echo $_SERVER["REMOTE_ADDR"];
function get_ip_address() {
// check for shared internet/ISP IP
if (!empty($_SERVER['HTTP_CLIENT_IP']) && $this->validate_ip($_SERVER['HTTP_CLIENT_IP']))
return $_SERVER['HTTP_CLIENT_IP'];
// check for IPs passing through proxies
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
// check if multiple ips exist in var
$iplist = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
foreach ($iplist as $ip) {
if ($this->validate_ip($ip))
return $ip;
}
}
if (!empty($_SERVER['HTTP_X_FORWARDED']) && $this->validate_ip($_SERVER['HTTP_X_FORWARDED']))
return $_SERVER['HTTP_X_FORWARDED'];
if (!empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && $this->validate_ip($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']))
return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
if (!empty($_SERVER['HTTP_FORWARDED_FOR']) && $this->validate_ip($_SERVER['HTTP_FORWARDED_FOR']))
return $_SERVER['HTTP_FORWARDED_FOR'];
if (!empty($_SERVER['HTTP_FORWARDED']) && $this->validate_ip($_SERVER['HTTP_FORWARDED']))
return $_SERVER['HTTP_FORWARDED'];
// return unreliable ip since all else failed
return $_SERVER['REMOTE_ADDR'];
}
function validate_ip($ip) {
if (filter_var($ip, FILTER_VALIDATE_IP,
FILTER_FLAG_IPV4 |
FILTER_FLAG_IPV6 |
FILTER_FLAG_NO_PRIV_RANGE |
FILTER_FLAG_NO_RES_RANGE) === false)
return false;
self::$ip = $ip;
return true;
}
?>
You can't.
HTML is a markup language, not a programming language. it doesn't "do" anything - it just structures content.
You need to use a programming language, such as PHP, ASP, etc.
You can't, not through HTML alone.
You need to use scripting that has the HTTP headers available to it.
See this SO answer using JSONP.
For PHP you would use $_SERVER['REMOTE_HOST'].
HTML is a markup language, so it doesn't have any variables.
If you want to get it using PHP, you'll need to make use of the $_SERVER superglobal variable. A solution could be:
echo $_SERVER["REMOTE_ADDR"];
This actually gets the host ip, which would be your server.
echo $_SERVER["REMOTE_ADDR"];
This is the most basic however, and fails if the user is behind a proxy, as well as allowing them to trivially change it. A much much better method is to using something like:
function get_ip_address() {
// check for shared internet/ISP IP
if (!empty($_SERVER['HTTP_CLIENT_IP']) && $this->validate_ip($_SERVER['HTTP_CLIENT_IP']))
return $_SERVER['HTTP_CLIENT_IP'];
// check for IPs passing through proxies
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
// check if multiple ips exist in var
$iplist = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
foreach ($iplist as $ip) {
if ($this->validate_ip($ip))
return $ip;
}
}
if (!empty($_SERVER['HTTP_X_FORWARDED']) && $this->validate_ip($_SERVER['HTTP_X_FORWARDED']))
return $_SERVER['HTTP_X_FORWARDED'];
if (!empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && $this->validate_ip($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']))
return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
if (!empty($_SERVER['HTTP_FORWARDED_FOR']) && $this->validate_ip($_SERVER['HTTP_FORWARDED_FOR']))
return $_SERVER['HTTP_FORWARDED_FOR'];
if (!empty($_SERVER['HTTP_FORWARDED']) && $this->validate_ip($_SERVER['HTTP_FORWARDED']))
return $_SERVER['HTTP_FORWARDED'];
// return unreliable ip since all else failed
return $_SERVER['REMOTE_ADDR'];
}
function validate_ip($ip) {
if (filter_var($ip, FILTER_VALIDATE_IP,
FILTER_FLAG_IPV4 |
FILTER_FLAG_IPV6 |
FILTER_FLAG_NO_PRIV_RANGE |
FILTER_FLAG_NO_RES_RANGE) === false)
return false;
self::$ip = $ip;
return true;
}
(http://stackoverflow.com/questions/1634782/what-is-the-most-accurate-way-to-retrieve-a-users-correct-ip-address-in-php)
This correctly parses the HTTP_X_FORWARDED_FOR field as well as validating the IP to make sure it's of the right format, and not in a private block.
$ip=$_SERVER['REMOTE_ADDR'];
this command shows server ip address not user local ip address because this is php command is complies the code in server because of that reason this command show server ip address
If you can use JQuery but have no access to PHP, Ipify might by useful. It is free and there is no limit to the number of requests
<script type="application/javascript">
function getIP(json) {
document.write("My public IP address is: ", json.ip);
}
</script>
<script type="application/javascript" src="https://api.ipify.org?format=jsonp&callback=getIP"></script>