how to use foreach loop for clear the all textboxes?
public void clear()
{
lblage.Text = "";
lblclosingbirds.Text = "";
lbltypeoffeed.Text = "";
lbltypeoffeedf.Text = "";
lblstdfeed.Text = "";
lblstdfeedf.Text = "";
lblstdhd.Text = "";
lblstdhe.Text = "";
lblExpeggs.Text = "";
lblbirdsf.Text = "";
txtacteggs.Text = "";
txtactfeed.Text = "";
txtactfeedf.Text = "";
txtfemaleclosingstock50.Text = "";
txtfemaleclosingstock70.Text = "";
txtmale50kgcstock.Text = "";
txtmale70kgscstock.Text = "";
txtmort.Text = "";
txtmortf.Text = "";
txtuseeggs.Text = "";
ddlFemaleFeedtype.SelectedValue = "0";
ddlMaleFeedtype.SelectedValue = "0";
}
how to use foreach loop method for replace with clear()..please tell me..
any one... is it possible to write foreach loop...please tell me
Thursday, 3 October 2013
Wednesday, 2 October 2013
Batch script to remove parts of a filename
Batch script to remove parts of a filename
Help please!
I need to remove time stamp and file number off of the filename using a
windows batch script. Thank you! Thank you in advance!
OLD Filename= CAM168-NOTSET.2013.10.01.18.45.45.882.jpg
NEW Filename= CAM168-NOTSET.jpg
Help please!
I need to remove time stamp and file number off of the filename using a
windows batch script. Thank you! Thank you in advance!
OLD Filename= CAM168-NOTSET.2013.10.01.18.45.45.882.jpg
NEW Filename= CAM168-NOTSET.jpg
Connecting phonegap with Facebook
Connecting phonegap with Facebook
Please, any help/solutions for this: connecting and merging Facebook with
our phonegap application (version 3.0.9) so we may post on Facebook - from
the phonegap applicaton's behalf using the post dialog.
Basically, when an action is done on the application, it would post to
Facebook (such as when someone is listening to a song on Spotify and it
says on FB, or when someone likes something on Instagram and it posts on
FB, etc).
We are using phonegap version 3.0.9.
Please, any help/solutions for this: connecting and merging Facebook with
our phonegap application (version 3.0.9) so we may post on Facebook - from
the phonegap applicaton's behalf using the post dialog.
Basically, when an action is done on the application, it would post to
Facebook (such as when someone is listening to a song on Spotify and it
says on FB, or when someone likes something on Instagram and it posts on
FB, etc).
We are using phonegap version 3.0.9.
JSF 2.0 & PrimeFaces cannot be resolved as a member of
JSF 2.0 & PrimeFaces cannot be resolved as a member of
I have a bean:
package controller.types;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean
@SessionScoped
public class Test
{
static List<MainTableRow> rows;
public Test()
{
rows = new ArrayList<>();
}
public static List<MainTableRow> getRows()
{
return rows;
}
public static void setRows(List<MainTableRow> rows)
{
Test.rows = rows;
}
}
And my xhtml page is:
<h:form>
<p:fileUpload
fileUploadListener="#{fileUploadController.handleFileUpload}"
mode="advanced" dragDropSupport="false" update="messages"
sizeLimit="10000000" fileLimit="3"
allowTypes="/(\.|\/)(xls)$/" style="font-size: 14px"/>
<p:growl id="messages" showDetail="true" />
<p:dataTable id="dataTable" var="mainTableRow"
value="#{test.rows}" style="font-size: 14px">
<f:facet name="header">
Main Table
</f:facet>
<p:column sortBy="" headerText="Index">
<h:outputText value="#{mainTableRow.index}" />
</p:column>
<p:column sortBy="" headerText="Query">
<h:outputText value="#{mainTableRow.index}" />
</p:column>
<p:column sortBy="" headerText="S1">
<h:outputText value="#{mainTableRow.index}" />
</p:column>
<p:column sortBy="" headerText="S2">
<h:outputText value="#{mainTableRow.index}" />
</p:column>
<p:column sortBy="" headerText="S3">
<h:outputText value="#{mainTableRow.index}" />
</p:column>
<p:column sortBy="" headerText="S9">
<h:outputText value="#{mainTableRow.index}" />
</p:column>
<p:column sortBy="" headerText="Uygunluk">
<h:outputText value="#{mainTableRow.index}" />
</p:column>
<p:column sortBy="" headerText="Kural">
<h:outputText value="#{mainTableRow.index}" />
</p:column>
<p:column sortBy="" headerText="Kaynak">
<h:outputText value="#{mainTableRow.index}" />
</p:column>
<p:column sortBy="" headerText="Query Type">
<h:outputText value="#{mainTableRow.index}" />
</p:column>
<p:column sortBy="" headerText="User Intent">
<h:outputText value="#{mainTableRow.index}" />
</p:column>
</p:dataTable>
</h:form>
At line <p:dataTable id="dataTable" var="mainTableRow"
value="#{test.rows}" style="font-size: 14px"> it gives error:
rows cannot be resolved as a member of test
What is the reason?
I have a bean:
package controller.types;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean
@SessionScoped
public class Test
{
static List<MainTableRow> rows;
public Test()
{
rows = new ArrayList<>();
}
public static List<MainTableRow> getRows()
{
return rows;
}
public static void setRows(List<MainTableRow> rows)
{
Test.rows = rows;
}
}
And my xhtml page is:
<h:form>
<p:fileUpload
fileUploadListener="#{fileUploadController.handleFileUpload}"
mode="advanced" dragDropSupport="false" update="messages"
sizeLimit="10000000" fileLimit="3"
allowTypes="/(\.|\/)(xls)$/" style="font-size: 14px"/>
<p:growl id="messages" showDetail="true" />
<p:dataTable id="dataTable" var="mainTableRow"
value="#{test.rows}" style="font-size: 14px">
<f:facet name="header">
Main Table
</f:facet>
<p:column sortBy="" headerText="Index">
<h:outputText value="#{mainTableRow.index}" />
</p:column>
<p:column sortBy="" headerText="Query">
<h:outputText value="#{mainTableRow.index}" />
</p:column>
<p:column sortBy="" headerText="S1">
<h:outputText value="#{mainTableRow.index}" />
</p:column>
<p:column sortBy="" headerText="S2">
<h:outputText value="#{mainTableRow.index}" />
</p:column>
<p:column sortBy="" headerText="S3">
<h:outputText value="#{mainTableRow.index}" />
</p:column>
<p:column sortBy="" headerText="S9">
<h:outputText value="#{mainTableRow.index}" />
</p:column>
<p:column sortBy="" headerText="Uygunluk">
<h:outputText value="#{mainTableRow.index}" />
</p:column>
<p:column sortBy="" headerText="Kural">
<h:outputText value="#{mainTableRow.index}" />
</p:column>
<p:column sortBy="" headerText="Kaynak">
<h:outputText value="#{mainTableRow.index}" />
</p:column>
<p:column sortBy="" headerText="Query Type">
<h:outputText value="#{mainTableRow.index}" />
</p:column>
<p:column sortBy="" headerText="User Intent">
<h:outputText value="#{mainTableRow.index}" />
</p:column>
</p:dataTable>
</h:form>
At line <p:dataTable id="dataTable" var="mainTableRow"
value="#{test.rows}" style="font-size: 14px"> it gives error:
rows cannot be resolved as a member of test
What is the reason?
Best/your practices in Python for sharing global variables, shared functions and classes
Best/your practices in Python for sharing global variables, shared
functions and classes
Thanks for looking at this, I've been mulling over this for hours to no
avail. Essentially, I want to make my code more modular and share-able:
you can see how the following files made up a much larger one initially.
It's not working and I suspect it's because I'm trying to do things in
Python that I'm not supposed to:
app_config.py
app_name = "quick scraper"
mysql_db = ... # intended "global" variable that connects to database
main.py
from app_config import * # Getting shared variables
import app_library # See code app_library.py below
...
logger = logging.getLogger(app_name) # logger object to be shared later
...
app_library.dlAndSaveWebpage(url) # Module has key helper functions
...
app_library.py
import app_models_orm as app_models
def dlAndSaveWebpage(url)
# download and process url
...
app_models.Webpage(url=url, body=body)
app_models_orm.py
class MySQLModel(Model):
class Meta:
database = mysql_db
class Webpage(MySQLModel):
id = ...
...
Class MySQLModel of app_models_orm.py fails because variable mysql_db does
not exist in the file. I could do an import app_config, but I want to have
app_models_orm.py be used by multiple scripts within the same directory.
If I have to do an import of a file custom to a script, then I'd have to
make copies of the models file, which just seems bizarre and wrong.
Similarly, I want to use app_library.py by multiple scripts in the same
directory. It seems to make sense to call app_library from main.py, but if
app_library needs to reference variables directly from app_config.py, I'd
have to also make copies of app_library.py.
main.py contains a logger object that, when all of this code was put
together in one file, all the various methods could access/use. How can
(or should?) app_library.py functions access this instance of the logger
class?
Again, thanks for the help. Feel free to "teach me how to catch fish" in
this instance too: I saw many posts about using a global import file, but
that doesn't help the intention to share the latter two files without
adding in custom imports, nor does it help with the models file which,
when imported, hits an error because the class is seeking a variable that
isn't in the file. There's probably a right way to do all this, and I
imagine many of you would know how.
functions and classes
Thanks for looking at this, I've been mulling over this for hours to no
avail. Essentially, I want to make my code more modular and share-able:
you can see how the following files made up a much larger one initially.
It's not working and I suspect it's because I'm trying to do things in
Python that I'm not supposed to:
app_config.py
app_name = "quick scraper"
mysql_db = ... # intended "global" variable that connects to database
main.py
from app_config import * # Getting shared variables
import app_library # See code app_library.py below
...
logger = logging.getLogger(app_name) # logger object to be shared later
...
app_library.dlAndSaveWebpage(url) # Module has key helper functions
...
app_library.py
import app_models_orm as app_models
def dlAndSaveWebpage(url)
# download and process url
...
app_models.Webpage(url=url, body=body)
app_models_orm.py
class MySQLModel(Model):
class Meta:
database = mysql_db
class Webpage(MySQLModel):
id = ...
...
Class MySQLModel of app_models_orm.py fails because variable mysql_db does
not exist in the file. I could do an import app_config, but I want to have
app_models_orm.py be used by multiple scripts within the same directory.
If I have to do an import of a file custom to a script, then I'd have to
make copies of the models file, which just seems bizarre and wrong.
Similarly, I want to use app_library.py by multiple scripts in the same
directory. It seems to make sense to call app_library from main.py, but if
app_library needs to reference variables directly from app_config.py, I'd
have to also make copies of app_library.py.
main.py contains a logger object that, when all of this code was put
together in one file, all the various methods could access/use. How can
(or should?) app_library.py functions access this instance of the logger
class?
Again, thanks for the help. Feel free to "teach me how to catch fish" in
this instance too: I saw many posts about using a global import file, but
that doesn't help the intention to share the latter two files without
adding in custom imports, nor does it help with the models file which,
when imported, hits an error because the class is seeking a variable that
isn't in the file. There's probably a right way to do all this, and I
imagine many of you would know how.
Tuesday, 1 October 2013
CURSOR OR UNION ALL - UNION ALL IS SLOW
CURSOR OR UNION ALL - UNION ALL IS SLOW
Have a query that I run on the first of the month that goes against 6
databases.. Problem is that when run, it takes upward of 3 hours to run.
Thinking about this, I could do this with either a UNION ALL with PIVOT -
which is what is used today.. Or I could do a CURSOR from master do loop
through the databases on the server. But, I have to ask myself, how
efficient is this query?
SELECT *
FROM (
SELECT
'db1' AS DB
,YEAR(dateadd(hh,-5,ETIME)) as [YEAR]
,LEFT(DATENAME(MONTH, dateadd(hh,-5,ETIME)), 3) AS MONTH
,CASE WHEN ID IS NULL THEN 'NoTYPE' ELSE 'TYPE' END AS 'TYPE'
,ACT
,COUNT(ACT) AS Amount
FROM DB1.dbo.LOG (nolock) JOIN
DB1.dbo.TABL (nolock) ON DB1.dbo.LOG.ID = DB1.dbo.TABL.NAME COLLATE
SQL_Latin1_General_CP1_CI_AS
--WHERE dateadd(hh,-5,ETIME) >
dateadd(MM,-3,dateadd(day,datediff(day,0,getdate()),0))
GROUP BY YEAR(dateadd(hh,-5,ETIME))
, LEFT(DATENAME(MONTH, dateadd(hh,-5,ETIME)), 3)
, CASE WHEN ID IS NULL THEN 'NoTYPE' ELSE 'TYPE' END
, DB1.dbo.LOG.ACT
UNION ALL
-- next db.. AND 4 FOUR MORE..
) as s
PIVOT
(
SUM(Amount)
FOR [month] IN (JAN, FEB, MAR, APR,
MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC)
)
as PVT
Then we are doing the same thing by quarter..
SELECT *
FROM (
SELECT
'db1' AS DB
, YEAR(DATEADD(hh, - 5, DB1.dbo.LOG.ETIME)) AS YEAR
, DATEPART(q, DB1.dbo.LOG.ETIME) AS QUARTER
,CASE WHEN ID IS NULL THEN 'NoTYPE' ELSE 'TYPE' END AS 'TYPE'
,ACT
,COUNT(ACT) AS Amount
FROM DB1.dbo.LOG (nolock) JOIN
DB1.dbo.TABL (nolock) ON DB1.dbo.LOG.ID = DB1.dbo.TABL.NAME COLLATE
SQL_Latin1_General_CP1_CI_AS
GROUP BY YEAR(DB1.dbo.LOG.ETIME)
, DATEPART(q, DB1.dbo.LOG.ETIME)
, DB1.dbo.LOG.ACT
, YEAR(DATEADD(hh, - 5, DB1.dbo.ETIME))
UNION ALL
-- next db.. AND 4 FOUR MORE..
) as s
PIVOT
(
sum(Amount)
FOR [quarter] IN ([1], [2], [3], [4])
)
as PVT
Thanks,
Kent
Have a query that I run on the first of the month that goes against 6
databases.. Problem is that when run, it takes upward of 3 hours to run.
Thinking about this, I could do this with either a UNION ALL with PIVOT -
which is what is used today.. Or I could do a CURSOR from master do loop
through the databases on the server. But, I have to ask myself, how
efficient is this query?
SELECT *
FROM (
SELECT
'db1' AS DB
,YEAR(dateadd(hh,-5,ETIME)) as [YEAR]
,LEFT(DATENAME(MONTH, dateadd(hh,-5,ETIME)), 3) AS MONTH
,CASE WHEN ID IS NULL THEN 'NoTYPE' ELSE 'TYPE' END AS 'TYPE'
,ACT
,COUNT(ACT) AS Amount
FROM DB1.dbo.LOG (nolock) JOIN
DB1.dbo.TABL (nolock) ON DB1.dbo.LOG.ID = DB1.dbo.TABL.NAME COLLATE
SQL_Latin1_General_CP1_CI_AS
--WHERE dateadd(hh,-5,ETIME) >
dateadd(MM,-3,dateadd(day,datediff(day,0,getdate()),0))
GROUP BY YEAR(dateadd(hh,-5,ETIME))
, LEFT(DATENAME(MONTH, dateadd(hh,-5,ETIME)), 3)
, CASE WHEN ID IS NULL THEN 'NoTYPE' ELSE 'TYPE' END
, DB1.dbo.LOG.ACT
UNION ALL
-- next db.. AND 4 FOUR MORE..
) as s
PIVOT
(
SUM(Amount)
FOR [month] IN (JAN, FEB, MAR, APR,
MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC)
)
as PVT
Then we are doing the same thing by quarter..
SELECT *
FROM (
SELECT
'db1' AS DB
, YEAR(DATEADD(hh, - 5, DB1.dbo.LOG.ETIME)) AS YEAR
, DATEPART(q, DB1.dbo.LOG.ETIME) AS QUARTER
,CASE WHEN ID IS NULL THEN 'NoTYPE' ELSE 'TYPE' END AS 'TYPE'
,ACT
,COUNT(ACT) AS Amount
FROM DB1.dbo.LOG (nolock) JOIN
DB1.dbo.TABL (nolock) ON DB1.dbo.LOG.ID = DB1.dbo.TABL.NAME COLLATE
SQL_Latin1_General_CP1_CI_AS
GROUP BY YEAR(DB1.dbo.LOG.ETIME)
, DATEPART(q, DB1.dbo.LOG.ETIME)
, DB1.dbo.LOG.ACT
, YEAR(DATEADD(hh, - 5, DB1.dbo.ETIME))
UNION ALL
-- next db.. AND 4 FOUR MORE..
) as s
PIVOT
(
sum(Amount)
FOR [quarter] IN ([1], [2], [3], [4])
)
as PVT
Thanks,
Kent
Inheritance Using Button
Inheritance Using Button
I have an assignment where I have to JPanels and I need to be able to push
button1 in jpanel1 and get information to change on button2 of jpanel2.
I've been working on the problem for a few days and no matter what I try I
get stuck.
My idea is that I need a method to convert the button in jpanel2 to a
button in jpanel that changes once the button in jpanel1 is pushed. Thing
is that I can't figure out how to get a method to work with a button.
Here's what I have so far.
MyJPanel:
public class myJPanel extends JPanel {
public myJPanel()
{
super();
JButton j2 = new JButton("..");
setBackground(Color.gray);
setLayout(new BorderLayout());
myJPanel1 p1 = new myJPanel1(JButton(j2)); // thought something
//like this would work to pass jpanel2 to jpanel1 using
//myjpanel as the common class
add(p1,"North");
myJPanel2 p2 = new myJPanel2(j2);
add(p2,"Center");
}
panel1
public class myJPanel1 extends JPanel implements ActionListener
{
student st1 = new student("Fred","Fonseca",44);
JButton j = new JButton(st1.getInfo());
JButton b1 = new JButton("..");
public myJPanel1(JButton j2)
{
super();
setBackground(Color.yellow);
// the whatsUp of this student has to shown in the other panel
j.addActionListener(this);
add(j);
add(b1);
}
public void actionPerformed(ActionEvent event)
{
Object obj = event.getSource();
//=====================================
if (obj == j){
{j2.setText(st1.whatsUp()); // Output on JButton in JPanel2
{b1.setText(st1.whatsUp());
}
}
}
}
}
jpanel2
public class myJPanel2 extends JPanel { JButton j1 = new JButton("When the
user clicks on the button in the UPPER panel" );
public void setButton(JButton j2){
j1 = j2; // shouldn't this pass convert the information
//between the classes?
}
public myJPanel2(JButton j1)
{
super();
setBackground(Color.pink);
setLayout(new GridLayout(3,1));
add(j1);
j1.setText("");
}
}
I have an assignment where I have to JPanels and I need to be able to push
button1 in jpanel1 and get information to change on button2 of jpanel2.
I've been working on the problem for a few days and no matter what I try I
get stuck.
My idea is that I need a method to convert the button in jpanel2 to a
button in jpanel that changes once the button in jpanel1 is pushed. Thing
is that I can't figure out how to get a method to work with a button.
Here's what I have so far.
MyJPanel:
public class myJPanel extends JPanel {
public myJPanel()
{
super();
JButton j2 = new JButton("..");
setBackground(Color.gray);
setLayout(new BorderLayout());
myJPanel1 p1 = new myJPanel1(JButton(j2)); // thought something
//like this would work to pass jpanel2 to jpanel1 using
//myjpanel as the common class
add(p1,"North");
myJPanel2 p2 = new myJPanel2(j2);
add(p2,"Center");
}
panel1
public class myJPanel1 extends JPanel implements ActionListener
{
student st1 = new student("Fred","Fonseca",44);
JButton j = new JButton(st1.getInfo());
JButton b1 = new JButton("..");
public myJPanel1(JButton j2)
{
super();
setBackground(Color.yellow);
// the whatsUp of this student has to shown in the other panel
j.addActionListener(this);
add(j);
add(b1);
}
public void actionPerformed(ActionEvent event)
{
Object obj = event.getSource();
//=====================================
if (obj == j){
{j2.setText(st1.whatsUp()); // Output on JButton in JPanel2
{b1.setText(st1.whatsUp());
}
}
}
}
}
jpanel2
public class myJPanel2 extends JPanel { JButton j1 = new JButton("When the
user clicks on the button in the UPPER panel" );
public void setButton(JButton j2){
j1 = j2; // shouldn't this pass convert the information
//between the classes?
}
public myJPanel2(JButton j1)
{
super();
setBackground(Color.pink);
setLayout(new GridLayout(3,1));
add(j1);
j1.setText("");
}
}
C++14 std::dynarray vs std::vector stackoverflow.com
C++14 std::dynarray vs std::vector – stackoverflow.com
C++14 presents std::dynarray: std::dynarray is a sequence container that
encapsulates arrays with a size that is fixed at construction and does not
change throughout the lifetime of the ...
C++14 presents std::dynarray: std::dynarray is a sequence container that
encapsulates arrays with a size that is fixed at construction and does not
change throughout the lifetime of the ...
Any way to massively edit broken github twitter bootstrap links=?iso-8859-1?Q?=3F_=96_meta.stackoverflow.com?=
Any way to massively edit broken github twitter bootstrap links? –
meta.stackoverflow.com
Twitter Bootstrap was moved from the Twitter organization to the TWBS
organization. This has resulted in numerous broken links all over the
internet and it would be nice if GitHub did something about …
meta.stackoverflow.com
Twitter Bootstrap was moved from the Twitter organization to the TWBS
organization. This has resulted in numerous broken links all over the
internet and it would be nice if GitHub did something about …
Monday, 30 September 2013
error: file'/boot/grub/x86_64-efi/normal.mod' not found
error: file'/boot/grub/x86_64-efi/normal.mod' not found
I get this error:
error: file'/boot/grub/x86_64-efi/normal.mod' not found.
grub rescue>
I am on a ASUS U38DT which came pre-installed with windows 8 and I tried
to install Ubuntu 13.04 instead via USB (not dual boot). Now my computer
doesn't boot into any OS and I'm a little screwed. How do i completely
remove windows 8 and get Ubuntu to work?
I get this error:
error: file'/boot/grub/x86_64-efi/normal.mod' not found.
grub rescue>
I am on a ASUS U38DT which came pre-installed with windows 8 and I tried
to install Ubuntu 13.04 instead via USB (not dual boot). Now my computer
doesn't boot into any OS and I'm a little screwed. How do i completely
remove windows 8 and get Ubuntu to work?
Why use a resistor in filter circuits electronics.stackexchange.com
Why use a resistor in filter circuits – electronics.stackexchange.com
Since capacitors and inductors can filter on their own. Why are separate
resistors needed? For example in a RC circuit, using only a capacitor
would be different in what manner?
Since capacitors and inductors can filter on their own. Why are separate
resistors needed? For example in a RC circuit, using only a capacitor
would be different in what manner?
How do I use this debug macro?
How do I use this debug macro?
using namespace std;
#ifdef DEBUG
#define debug(args...) {dbg,args; cerr<<endl;}
#else
#define debug(args...) // Just strip off all debug
tokens
using namespace std;
#ifdef DEBUG
#define debug(args...) {dbg,args; cerr<<endl;}
#else
#define debug(args...) // Just strip off all debug
tokens
How to connect MS SQL dynamically with postgreSQl data base
How to connect MS SQL dynamically with postgreSQl data base
I am very new in PostgreSQL database. I am currently using MS SQL server
2008. Now i need the whole data in postgreSQL, I have installed postgreSQL
in my server. Kindly tell me the procedure to connect with PostgreSQl. If
there is no option, kindly tell me whether we can take back up of MS SQl
and restore it in postgreSQl
thanks in advance
I am very new in PostgreSQL database. I am currently using MS SQL server
2008. Now i need the whole data in postgreSQL, I have installed postgreSQL
in my server. Kindly tell me the procedure to connect with PostgreSQl. If
there is no option, kindly tell me whether we can take back up of MS SQl
and restore it in postgreSQl
thanks in advance
Sunday, 29 September 2013
How are HashMap et al really O(1)?
How are HashMap et al really O(1)?
I'm studying Java collection performance characteristics, Big O notation
and complexity, etc. There's a real-world part I can't wrap my head
around, and that's why HashMap and other hash containers are considered
O(1), which should mean that finding an entry by key in a 1,000 entry
table should take about the same time as a 1,000,000 entry table.
Let's say you have HashMap myHashMap, stored with a key of first name +
last name. If you call myHashMap.get("FredFlinstone"), how can it
instantly find Fred Flinstone's Person object? How can it not have to
iterate through the set of keys stored in the HashMap to find the pointer
to the object? If there were 1,000,000 entries in the HashMap, the list of
keys would also be 1,000,000 long (assuming no collision), which must take
more time to go through than a list of 1.000, even if it were sorted. So
how can the get() or containsKey() time not change with n?
Note: I thought my question would be answered in Is a Java hashmap really
O(1)? but the answers didn't really address this point. My question is
also not about collisions.
I'm studying Java collection performance characteristics, Big O notation
and complexity, etc. There's a real-world part I can't wrap my head
around, and that's why HashMap and other hash containers are considered
O(1), which should mean that finding an entry by key in a 1,000 entry
table should take about the same time as a 1,000,000 entry table.
Let's say you have HashMap myHashMap, stored with a key of first name +
last name. If you call myHashMap.get("FredFlinstone"), how can it
instantly find Fred Flinstone's Person object? How can it not have to
iterate through the set of keys stored in the HashMap to find the pointer
to the object? If there were 1,000,000 entries in the HashMap, the list of
keys would also be 1,000,000 long (assuming no collision), which must take
more time to go through than a list of 1.000, even if it were sorted. So
how can the get() or containsKey() time not change with n?
Note: I thought my question would be answered in Is a Java hashmap really
O(1)? but the answers didn't really address this point. My question is
also not about collisions.
Find over an Unsorted vector
Find over an Unsorted vector
I need to apply a FIND functionality over vector elements (similar to the
MATLAB FIND command) returning all ocurrences. While being unable to find
this using the STL functions with iterators, i concocted this function:
vector<int> find(vector<int> v, int value,vector<int>*ive)
{
//Generic Find
vector<int> ve;
for (int i=0;i<v.size();i++)
{
if (v[i]==value)
{
ive->push_back(i);
ve.push_back(v[i]);}
}
return ve;
}
called with:
//Values
vector<int> v1 = {1,3,3,4,5,2,3,4,6,7,7,8,1,2,2,3,2,2,3,2};
vector<int> iRange,vRange;
int val=2;
//Manual FIND
vRange=find(v1,val,&iRange);
PrintArray(vRange);
PrintArray(iRange);
Returning the correct result:
*vRange: 2 2 2 2 2 2
iRange: 5 13 14 16 17 19*
WHich of course do not use the pair object, the sort and equal_range
function, which would be the ideal:
pair<vector<int>::iterator,vector<int>::iterator> Range;
sort(v1.begin(),v1.end());
Range=equal_range(v1.begin(),v1.end(),val);
Returning the absolutely proper, but -so far- totally useless result, if
one wishes the vector unsorded:
*Range Iters: 2 2 2 2 2 2
Range: 2 3 4 5 6 7*
What is the solution for this?
Thanks, hyp
I need to apply a FIND functionality over vector elements (similar to the
MATLAB FIND command) returning all ocurrences. While being unable to find
this using the STL functions with iterators, i concocted this function:
vector<int> find(vector<int> v, int value,vector<int>*ive)
{
//Generic Find
vector<int> ve;
for (int i=0;i<v.size();i++)
{
if (v[i]==value)
{
ive->push_back(i);
ve.push_back(v[i]);}
}
return ve;
}
called with:
//Values
vector<int> v1 = {1,3,3,4,5,2,3,4,6,7,7,8,1,2,2,3,2,2,3,2};
vector<int> iRange,vRange;
int val=2;
//Manual FIND
vRange=find(v1,val,&iRange);
PrintArray(vRange);
PrintArray(iRange);
Returning the correct result:
*vRange: 2 2 2 2 2 2
iRange: 5 13 14 16 17 19*
WHich of course do not use the pair object, the sort and equal_range
function, which would be the ideal:
pair<vector<int>::iterator,vector<int>::iterator> Range;
sort(v1.begin(),v1.end());
Range=equal_range(v1.begin(),v1.end(),val);
Returning the absolutely proper, but -so far- totally useless result, if
one wishes the vector unsorded:
*Range Iters: 2 2 2 2 2 2
Range: 2 3 4 5 6 7*
What is the solution for this?
Thanks, hyp
Cordova error when adding Android
Cordova error when adding Android
I am getting the following error when trying to add android to my cordova
project. iOS was working just fine.
$ cordova platform add android [Error: An error occured during creation of
android sub-project. An unexpected error occurred: "$ANDROID_BIN" create
project --target $TARGET --path "$PROJECT_PATH" --package $PACKAGE
--activity $ACTIVITY >&/dev/null exited with 1 Deleting project...
Any ideas what the reason for that can be?
Thanks, Nik
I am getting the following error when trying to add android to my cordova
project. iOS was working just fine.
$ cordova platform add android [Error: An error occured during creation of
android sub-project. An unexpected error occurred: "$ANDROID_BIN" create
project --target $TARGET --path "$PROJECT_PATH" --package $PACKAGE
--activity $ACTIVITY >&/dev/null exited with 1 Deleting project...
Any ideas what the reason for that can be?
Thanks, Nik
Calling a method of view in emberjs
Calling a method of view in emberjs
I have a one method in my view and i want to call this method from
controller.The controller and view is like this :
App.theController = Ember.ArrayController.extend({
methodA:function(){
//how to call methodB in view
}
});
App.theView = Ember.View.extend({
methodB:function(){
//do something
}
});
the question is how methodA can call methodB ?
I have a one method in my view and i want to call this method from
controller.The controller and view is like this :
App.theController = Ember.ArrayController.extend({
methodA:function(){
//how to call methodB in view
}
});
App.theView = Ember.View.extend({
methodB:function(){
//do something
}
});
the question is how methodA can call methodB ?
Saturday, 28 September 2013
pushing values in a array javascript
pushing values in a array javascript
I have this array of (x,y) values and I want to change the form in
to(x:,y:). I tried to initialize data to rows and to an emplty array but
it didnt work.
var rows = new Array(
Array(0,0),
Array(90,90),
Array(59,70),
Array(65,77),
Array(85,66)
);
for (var i =0; i < rows.length; i++) {
data.push({x: rows[i][0], y: rows[i][1]});
}
how to initialize data array in order to have the wanted array.
I have this array of (x,y) values and I want to change the form in
to(x:,y:). I tried to initialize data to rows and to an emplty array but
it didnt work.
var rows = new Array(
Array(0,0),
Array(90,90),
Array(59,70),
Array(65,77),
Array(85,66)
);
for (var i =0; i < rows.length; i++) {
data.push({x: rows[i][0], y: rows[i][1]});
}
how to initialize data array in order to have the wanted array.
C++ base 10 to base 2 logic error
C++ base 10 to base 2 logic error
I am doing a basic program to convert number from base 10 to base 2. I got
this code:
#include <cstdlib>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int main()
{
int num=0, coc=0, res=0, div=0;
printf ("Write a base 10 number\n");
scanf ("%d", &num);
div=num%2;
printf ("The base 2 value is:\n");
if(div==1)
{
coc=num/2;
res=num%2;
while(coc>=1)
{
printf ("%d", res);
res=coc%2;
coc=coc/2;
}
if(coc<1)
{
printf ("1");
}
}
else
{
printf ("1");
coc=num/2;
res=num%2;
while(coc>=1)
{
printf ("%d", res);
res=coc%2;
coc=coc/2;
}
}
printf ("\n");
system ("PAUSE");
return EXIT_SUCCESS;
}
Everything is good with certain numbers, but, if I try to convert the
number 11 to base 2, I get 1101, if I try 56 I get 100011... I know is a
logic problem and I am limited to basic algoritms and functions :(... any
ideas?
I am doing a basic program to convert number from base 10 to base 2. I got
this code:
#include <cstdlib>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int main()
{
int num=0, coc=0, res=0, div=0;
printf ("Write a base 10 number\n");
scanf ("%d", &num);
div=num%2;
printf ("The base 2 value is:\n");
if(div==1)
{
coc=num/2;
res=num%2;
while(coc>=1)
{
printf ("%d", res);
res=coc%2;
coc=coc/2;
}
if(coc<1)
{
printf ("1");
}
}
else
{
printf ("1");
coc=num/2;
res=num%2;
while(coc>=1)
{
printf ("%d", res);
res=coc%2;
coc=coc/2;
}
}
printf ("\n");
system ("PAUSE");
return EXIT_SUCCESS;
}
Everything is good with certain numbers, but, if I try to convert the
number 11 to base 2, I get 1101, if I try 56 I get 100011... I know is a
logic problem and I am limited to basic algoritms and functions :(... any
ideas?
new BitmapDrawable() is deprecated - Eclipse: Unable to resolve this error using several arguments?
new BitmapDrawable() is deprecated - Eclipse: Unable to resolve this error
using several arguments?
Team, Instead of using the easy way out [@SuppressWarnings("deprecation")]
I want to learn the right way. I tried several ways of fixing this but no
luck. How do I resolve this? thanks in advance.
new BitmapDrawable(mContext.getResoursces(), null) < not working new
BitmapDrawable(mContext.getResoursces()) < not working
mContext = context;
protected Drawable mBackground = null;
mWindowManager = (WindowManager)
context.getSystemService(Context.WINDOW_SERVICE);
if (mBackground == null)
mWindow.setBackgroundDrawable(new *BitmapDrawable()*);
else
mWindow.setBackgroundDrawable(mBackground);
public void setBackgroundDrawable(Drawable background) {
mBackground = background;
}
using several arguments?
Team, Instead of using the easy way out [@SuppressWarnings("deprecation")]
I want to learn the right way. I tried several ways of fixing this but no
luck. How do I resolve this? thanks in advance.
new BitmapDrawable(mContext.getResoursces(), null) < not working new
BitmapDrawable(mContext.getResoursces()) < not working
mContext = context;
protected Drawable mBackground = null;
mWindowManager = (WindowManager)
context.getSystemService(Context.WINDOW_SERVICE);
if (mBackground == null)
mWindow.setBackgroundDrawable(new *BitmapDrawable()*);
else
mWindow.setBackgroundDrawable(mBackground);
public void setBackgroundDrawable(Drawable background) {
mBackground = background;
}
Subscribe to:
Posts (Atom)