How bet Netbeans 7.2 to use 32 Bit JVM
So I am using Netbeans to develop a Jenkins Groovy Post Build Script.
Jenkins runs in 32 bit mode (Production cannot touch), Netbeans wants to
run in 64 bit mode.
I can get EITHER environment to work, the problem is that I need to keep
switching my PATH variable so the right version of a DLL is on the path,
but switch is time consuming and annoying.
I am trying to figure out how to get Netbeans to either run in 32 bit mode
or to change the PATH variable in Netbeans to use the 64 Bit DLL
(something Visual Studio supports).
So far, nothing I've done has convinced Netbeans to use 32 mode and I see
no way to change the path for the Netbeans IDE.
Suggestions?
Frank
Thursday, 15 August 2013
pythone 3.3.2 age >= 24: TypeError: unorderable types: str() >= int()`enter code here`
pythone 3.3.2 age >= 24: TypeError: unorderable types: str() >=
int()`enter code here`
print("how old are you")
age = input(">")
if age >= 24:
print("you are getting old")
print (age)
else:
print("i don't care")
print (age)
#this is the error i am getting dam i am so noob if age >= 24: TypeError:
unorderable types: str() >= int()enter code here
int()`enter code here`
print("how old are you")
age = input(">")
if age >= 24:
print("you are getting old")
print (age)
else:
print("i don't care")
print (age)
#this is the error i am getting dam i am so noob if age >= 24: TypeError:
unorderable types: str() >= int()enter code here
ArrayIndexOutOfBoundsException: -1 in jList
ArrayIndexOutOfBoundsException: -1 in jList
hey i have a jList in this i add elements from a database all, when i
create a new element in the database and press the button to get the new
element in the jList i get a IndexOutofBound BUT when i press again it
works ... Create new Element
try{
String date = jDateChooser1.getDate().toString();
String Termin = jTextArea1.getText();
System.out.println(date+"\n"+Termin);
sessionBean.createTermin(date, Termin);
}catch(NullPointerException npe){
JOptionPane.showMessageDialog(null, "Bitte Datum Auswählen");
}
Get the elements for tge jList
listModel.removeAllElements();
termin = sessionBean.getTermin();
datum = sessionBean.getDatum();
for (int i = 0 ; i < datum.size(); i++){
listModel.addElement(datum.get(i).toString());
}
and here the methode when i press at a element from the jList i get the
information
termin = sessionBean.getTermin();
index = jList1.getSelectedIndex();
if (!evt.getValueIsAdjusting()){
jTextArea2.setText(termin.get(index).toString());
}
hey i have a jList in this i add elements from a database all, when i
create a new element in the database and press the button to get the new
element in the jList i get a IndexOutofBound BUT when i press again it
works ... Create new Element
try{
String date = jDateChooser1.getDate().toString();
String Termin = jTextArea1.getText();
System.out.println(date+"\n"+Termin);
sessionBean.createTermin(date, Termin);
}catch(NullPointerException npe){
JOptionPane.showMessageDialog(null, "Bitte Datum Auswählen");
}
Get the elements for tge jList
listModel.removeAllElements();
termin = sessionBean.getTermin();
datum = sessionBean.getDatum();
for (int i = 0 ; i < datum.size(); i++){
listModel.addElement(datum.get(i).toString());
}
and here the methode when i press at a element from the jList i get the
information
termin = sessionBean.getTermin();
index = jList1.getSelectedIndex();
if (!evt.getValueIsAdjusting()){
jTextArea2.setText(termin.get(index).toString());
}
OpenNI 1.5 Playing a second oni file
OpenNI 1.5 Playing a second oni file
I have a .oni file playing and receiving skeleton information from it from
OpenNI. However I would like to be able to switch to a different .oni file
while the application is running (say on file drop).
However when I attempt to call xn::Context::OpenFileRecording a second
time, i receive the message that the node is locked for changes.
How can I unlock the node (whichever one that is), so that I can play the
file?
I have a .oni file playing and receiving skeleton information from it from
OpenNI. However I would like to be able to switch to a different .oni file
while the application is running (say on file drop).
However when I attempt to call xn::Context::OpenFileRecording a second
time, i receive the message that the node is locked for changes.
How can I unlock the node (whichever one that is), so that I can play the
file?
These seem to be some arrays, but, what do these PHP codes mean?
These seem to be some arrays, but, what do these PHP codes mean?
Can somebody explain to me what does each line of the code inside the for
loop below mean or do?
$var = array();
$ship = $_POST['product'];
$amount = count( $ship );
for ($i = 0; $i < $amount; $i++){
$var[$i]['product']
$ship[$i]
$var[$i]['name'] = $ship[$i];
echo $var;
}
Thank you!
Can somebody explain to me what does each line of the code inside the for
loop below mean or do?
$var = array();
$ship = $_POST['product'];
$amount = count( $ship );
for ($i = 0; $i < $amount; $i++){
$var[$i]['product']
$ship[$i]
$var[$i]['name'] = $ship[$i];
echo $var;
}
Thank you!
Delphi XE2 and SPNEGO
Delphi XE2 and SPNEGO
We are currently trying to accomplish a single signon solution using JBoss
with SPNEGO negotiation on the serverside and a Delphi (XE2) application
using Indy on the clientside.
However, I'm lost in space. I got the answer that I have to write my own
negotiation mechanism, but lack of knowledge make this somehow impossible
:)
//Andreas
We are currently trying to accomplish a single signon solution using JBoss
with SPNEGO negotiation on the serverside and a Delphi (XE2) application
using Indy on the clientside.
However, I'm lost in space. I got the answer that I have to write my own
negotiation mechanism, but lack of knowledge make this somehow impossible
:)
//Andreas
Wednesday, 14 August 2013
What is the class similar to hero-unit class in twitter bootstrap
What is the class similar to hero-unit class in twitter bootstrap
I could not find hero-unit css class (present in bootstrap 2) in bootstrap
3. Are there any class similar to hero-unit in bootstrap 3 ?
I could not find hero-unit css class (present in bootstrap 2) in bootstrap
3. Are there any class similar to hero-unit in bootstrap 3 ?
Ruby methods returning results in repl.it but not when I run the program
Ruby methods returning results in repl.it but not when I run the program
I'm very new to ruby and I have been writing some simple programs. I've
noticed that alot of my programs are creating no returned values when I
try to run them through the command line, but seem to be working perfectly
when I use repl.it for testing. For example:
def rev(a)
b = []
c = []
b = a.scan(/\w+/)
c = b.map {|x| x.reverse }
return c.join(' ')
end
rev('hello')
If I use puts c.join(' ') the answer will appear but it's not being
returned which is what I need to happen. I have a feeling this is
something very simple. Any help is appreciated, I've had to create some
weird and blocky work arounds to make my other programs work but have
limited what I've been able to do.
I'm very new to ruby and I have been writing some simple programs. I've
noticed that alot of my programs are creating no returned values when I
try to run them through the command line, but seem to be working perfectly
when I use repl.it for testing. For example:
def rev(a)
b = []
c = []
b = a.scan(/\w+/)
c = b.map {|x| x.reverse }
return c.join(' ')
end
rev('hello')
If I use puts c.join(' ') the answer will appear but it's not being
returned which is what I need to happen. I have a feeling this is
something very simple. Any help is appreciated, I've had to create some
weird and blocky work arounds to make my other programs work but have
limited what I've been able to do.
ASP.NET Model binding One to Many + AJAX
ASP.NET Model binding One to Many + AJAX
I have a model with a one-to-many relationship kinda similar to this:
public class people
{
public int id { get; set; }
public sting name { get; set; }
public virtual stuff things { get; set; }
}
public class stuff
{
public int id { get; set; }
public string name { get; set; }
public int thingType { get; set; }
}
I now need to be able to create and edit "stuff" for the person I am
currently editing on my "editPeople" page. I'm using AJAX to create JQuery
UI Dialog box for the stuff edit/create form, and then I post it back to
the server to create a bunch of hidden fields so I can actually save this
data later.
I'm concerned that these hidden fields would be named in a way that such
that when I post my peopleEdit back to the controller, the Model binding
won't properly convert the "stuff" that I have created/edited. Am I doing
this wrong/Is there a better method? Am I forced into creating a custom
model binder?
I have a model with a one-to-many relationship kinda similar to this:
public class people
{
public int id { get; set; }
public sting name { get; set; }
public virtual stuff things { get; set; }
}
public class stuff
{
public int id { get; set; }
public string name { get; set; }
public int thingType { get; set; }
}
I now need to be able to create and edit "stuff" for the person I am
currently editing on my "editPeople" page. I'm using AJAX to create JQuery
UI Dialog box for the stuff edit/create form, and then I post it back to
the server to create a bunch of hidden fields so I can actually save this
data later.
I'm concerned that these hidden fields would be named in a way that such
that when I post my peopleEdit back to the controller, the Model binding
won't properly convert the "stuff" that I have created/edited. Am I doing
this wrong/Is there a better method? Am I forced into creating a custom
model binder?
Will someone critique my code?
Will someone critique my code?
I know this is not very good. I am currently in my first programming
class(java). It seems like it works, but I am sure there are things I have
not thought of. The goal is to have a user enter one by one, how many
credit units each class they need to take is worth. Then enter how many
credit units you will complete in a term. The program should calculate how
many credit units are left, how many terms it will take to complete the
degree, and how much it will cost. Thanks and PLEASE BE GENTLE! import
java.util.ArrayList; import java.util.Scanner;
public class GraduationPlanner {
public static void main(String[] args) {
int sum = 0;
String creditUnits;
int unitsLeft;
int plannedUnits = 0;
int termsLeft = 0;
double tuitionCost = 0;
final double TUITION_RATE = 2890;
ArrayList<Integer> cu = new ArrayList<Integer>();
Scanner in = new Scanner(System.in);
System.out.println("Please input the Credit Units for each course.
Press enter after each course. Press Q when finished: ");
while (in.hasNextInt()) {
int temp = (in.nextInt());
if (temp < 0) {
System.out.print("ERROR! Please enter a number 1-9.: ");
} else {
cu.add(temp);
}
}
System.out.println(cu);
Scanner ex = new Scanner(System.in);
System.out.print("Please enter the number of Credit Units you will
complete per term: ");
if (ex.hasNextInt()) {
plannedUnits = ex.nextInt();
}
for (int a : cu)
{
sum += a;
}
unitsLeft = (sum - plannedUnits);
termsLeft = (sum / plannedUnits);
tuitionCost = (termsLeft * TUITION_RATE);
System.out.println("After this term there are " + unitsLeft + " credit
units remaining.");
System.out.println("You will complete your degree in " + termsLeft + "
terms.");
System.out.print("It will cost you " + tuitionCost + " to complete
your degree.");
}
}
I know this is not very good. I am currently in my first programming
class(java). It seems like it works, but I am sure there are things I have
not thought of. The goal is to have a user enter one by one, how many
credit units each class they need to take is worth. Then enter how many
credit units you will complete in a term. The program should calculate how
many credit units are left, how many terms it will take to complete the
degree, and how much it will cost. Thanks and PLEASE BE GENTLE! import
java.util.ArrayList; import java.util.Scanner;
public class GraduationPlanner {
public static void main(String[] args) {
int sum = 0;
String creditUnits;
int unitsLeft;
int plannedUnits = 0;
int termsLeft = 0;
double tuitionCost = 0;
final double TUITION_RATE = 2890;
ArrayList<Integer> cu = new ArrayList<Integer>();
Scanner in = new Scanner(System.in);
System.out.println("Please input the Credit Units for each course.
Press enter after each course. Press Q when finished: ");
while (in.hasNextInt()) {
int temp = (in.nextInt());
if (temp < 0) {
System.out.print("ERROR! Please enter a number 1-9.: ");
} else {
cu.add(temp);
}
}
System.out.println(cu);
Scanner ex = new Scanner(System.in);
System.out.print("Please enter the number of Credit Units you will
complete per term: ");
if (ex.hasNextInt()) {
plannedUnits = ex.nextInt();
}
for (int a : cu)
{
sum += a;
}
unitsLeft = (sum - plannedUnits);
termsLeft = (sum / plannedUnits);
tuitionCost = (termsLeft * TUITION_RATE);
System.out.println("After this term there are " + unitsLeft + " credit
units remaining.");
System.out.println("You will complete your degree in " + termsLeft + "
terms.");
System.out.print("It will cost you " + tuitionCost + " to complete
your degree.");
}
}
how to read specified string from url
how to read specified string from url
Below is my string .i want to do following operation like if my url
contain "Destinationfolder" then i have to get folder1 and folder2 , and
result has to assign to another string one by one.
string strpath = @"D:\Multilingual\Destinationfolder\folder1\folder2";
Below is my string .i want to do following operation like if my url
contain "Destinationfolder" then i have to get folder1 and folder2 , and
result has to assign to another string one by one.
string strpath = @"D:\Multilingual\Destinationfolder\folder1\folder2";
Geometric problem in spherical coordinates
Geometric problem in spherical coordinates
I have the following problem.
I wanted to find a model for a line in spherical coordinates!
At first I had a line that had a constant z-coordinate $z_c$. so i just
said: whenever $$z_c= r \cos(\theta)$$ a point is on that line.
Now I had to rotate this line by an angle beta. But now I do not know
anymore how to find a similar expression for this line, like I had
earlier. Does anybody know? ( I should stress that the origin of the
spherical coordinate system is in the CENTER of the sphere) Image that
describes my problem.
Maybe my picture gives you a wrong idea, since the center of the rotation
is the center of the sphere. so i should have better drawn the angle
between a new and the old z-axis.
I have the following problem.
I wanted to find a model for a line in spherical coordinates!
At first I had a line that had a constant z-coordinate $z_c$. so i just
said: whenever $$z_c= r \cos(\theta)$$ a point is on that line.
Now I had to rotate this line by an angle beta. But now I do not know
anymore how to find a similar expression for this line, like I had
earlier. Does anybody know? ( I should stress that the origin of the
spherical coordinate system is in the CENTER of the sphere) Image that
describes my problem.
Maybe my picture gives you a wrong idea, since the center of the rotation
is the center of the sphere. so i should have better drawn the angle
between a new and the old z-axis.
NetApp SnapManager for SQL Server Update backup script
NetApp SnapManager for SQL Server Update backup script
I was very disappointed that NetApp just doesn't add Feature to
automatically update the (MS)SQL Job automatically every time a new
Database gets created. (for a Full backup)
So i now want to share with you what I did to automatically add a new
Database to out full SQL backup job.
Maybe someone has some ideas on how to make things a little bit more
efficient or create not so much temporary files :)
Just Create a SQL job with executes the flowing batch file to update the
NetApp SnapManager SQL Job.
@echo off
set SQLinstance=YOUR_SQL_SERVERNAME
REM if something differs
set SQL_SERVER=%SQLinstance%
REM SQL Verify Instalce
set SQL_VERIFY=ANOTHER_SERVERNAME\VERIFY
set db_list=list_%SQL_SERVER%.txt
set db_list_wo_summary=list_new_%SQL_SERVER%.txt
set linecount_file=linecount_%SQL_SERVER%.txt
set output-Full-User-file=output-Full-%SQL_SERVER%.txt
set output-Inc-User-file=output-Inc-%SQL_SERVER%.txt
set SQLCMD="C:\Program Files\Microsoft SQL Server\110\Tools\Binn\sqlcmd.exe"
set arg_start=C:\Program Files\NetApp\SnapManager for SQL
Server\SmsqlJobLauncher.exe new-backup -svr ''%SQLinstance%'' -d
''%SQLinstance%'',
set arg_end_full= -ver -verInst ''%SQL_VERIFY%'' -mp -mpdir ''C:\Program
Files\NetApp\SnapManager for SQL Server\SnapMgrMountPoint''
-RetainBackupDays 8 -RetainShareBackupDays 17 -cpylgbkshare
COPYLOG_TOSHARE -lb -bksif -RetainSnapofSnapInfoDays 17 -rudays 1 -gen
-mgmt daily
set arg_end_incremental= -ver -verInst ''%SQL_VERIFY%'' -mp -mpdir
''C:\Program Files\NetApp\SnapManager for SQL Server\SnapMgrMountPoint''
-RetainBackupDays 8 -RetainShareBackupDays 17 -cpylgbkshare
COPYLOG_TOSHARE -lgbkonly -bksif -RetainSnapofSnapInfoDays 17 -gen -mgmt
daily
set SQL_QUERIE="SELECT NAME FROM master.sys.databases AS dtb WHERE NOT
(CAST(case when dtb.name in ('master','model','msdb','tempdb') then 1 else
dtb.is_distributor end AS bit)=1) ORDER BY NAME"
set JOBNAME_FULL_BACKUP=jobname_full
set JOBNAME_INCREMENTAL_BACKUP=jobname_incremental
set SQL_UPDATE_COMMAND_START="UPDATE msdb.dbo.sysjobsteps SET command='
set SQL_UPDATE_COMMAND_END=' FROM msdb.dbo.sysjobs, msdb.dbo.sysjobsteps
WHERE msdb.dbo.sysjobs.job_id = msdb.dbo.sysjobsteps.job_id AND name =
'%JOBNAME_FULL_BACKUP%'"
set SQL_UPDATE_COMMAND_END_INC=' FROM msdb.dbo.sysjobs,
msdb.dbo.sysjobsteps WHERE msdb.dbo.sysjobs.job_id =
msdb.dbo.sysjobsteps.job_id AND name = '%JOBNAME_INCREMENTAL_BACKUP%'"
REM Delete Old files (just to be sure)
del %db_list_wo_summary% %db_list% %linecount_file%
REM Get a List af all Databases and write them into a File
%SQLCMD% -E -S %SQLinstance% -o %db_list% -h -1 -s "," -W -Q %SQL_QUERIE%
setLocal EnableDelayedExpansion
REM Remove the last 2 Lines (one is a summary line, ant the other is empty)
set count=
for /f %%x in ('type %db_list% ^| find /c /v ""') do set /a lines=%%x-2
copy /y nul %tmp%\tmp.zzz > nul
for /f "tokens=*" %%x in ('type %db_list% ^| find /v ""') do (
set /a count=count+1
if !count! leq %lines% echo %%x>>%tmp%\tmp.zzz
)
move /y %tmp%\tmp.zzz %db_list_wo_summary% > nul
REM removes all linebreaks and adds a ' on every star and ending of the
string (and adds a comma)
for /f "tokens=* delims= " %%a in (%db_list_wo_summary%) do (set
s=!s!%%a'', '')
REM removes the last four chars (, '')(comma, space, and 2 '')
set s=!s:~0,-4!
REM counts the lines of the file NOT containing the string XXXYYYZZZ
(basicaly a line count)
type %db_list_wo_summary% | find /V /C "XXXYYYZZZ" > %linecount_file%
for /f "tokens=* delims= " %%c in (%linecount_file%) do (set cn=%%c)
REM Creates the final string for the SQL job
set s1=%arg_start% ''%CN%'', ''!s!%arg_end_full%
set s2=%arg_start% ''%CN%'', ''!s!%arg_end_incremental%
REM Update the SQL Job step command with the new string via SQLCMD
%SQLCMD% -E -S %SQLinstance% -Q
%SQL_UPDATE_COMMAND_START%%s1%%SQL_UPDATE_COMMAND_END%
%SQLCMD% -E -S %SQLinstance% -Q
%SQL_UPDATE_COMMAND_START%%s2%%SQL_UPDATE_COMMAND_END_INC%
REM deleting the temp file
del %db_list_wo_summary% %db_list% %linecount_file%
I hope this can help anyone make things a bit more efficient.
I was very disappointed that NetApp just doesn't add Feature to
automatically update the (MS)SQL Job automatically every time a new
Database gets created. (for a Full backup)
So i now want to share with you what I did to automatically add a new
Database to out full SQL backup job.
Maybe someone has some ideas on how to make things a little bit more
efficient or create not so much temporary files :)
Just Create a SQL job with executes the flowing batch file to update the
NetApp SnapManager SQL Job.
@echo off
set SQLinstance=YOUR_SQL_SERVERNAME
REM if something differs
set SQL_SERVER=%SQLinstance%
REM SQL Verify Instalce
set SQL_VERIFY=ANOTHER_SERVERNAME\VERIFY
set db_list=list_%SQL_SERVER%.txt
set db_list_wo_summary=list_new_%SQL_SERVER%.txt
set linecount_file=linecount_%SQL_SERVER%.txt
set output-Full-User-file=output-Full-%SQL_SERVER%.txt
set output-Inc-User-file=output-Inc-%SQL_SERVER%.txt
set SQLCMD="C:\Program Files\Microsoft SQL Server\110\Tools\Binn\sqlcmd.exe"
set arg_start=C:\Program Files\NetApp\SnapManager for SQL
Server\SmsqlJobLauncher.exe new-backup -svr ''%SQLinstance%'' -d
''%SQLinstance%'',
set arg_end_full= -ver -verInst ''%SQL_VERIFY%'' -mp -mpdir ''C:\Program
Files\NetApp\SnapManager for SQL Server\SnapMgrMountPoint''
-RetainBackupDays 8 -RetainShareBackupDays 17 -cpylgbkshare
COPYLOG_TOSHARE -lb -bksif -RetainSnapofSnapInfoDays 17 -rudays 1 -gen
-mgmt daily
set arg_end_incremental= -ver -verInst ''%SQL_VERIFY%'' -mp -mpdir
''C:\Program Files\NetApp\SnapManager for SQL Server\SnapMgrMountPoint''
-RetainBackupDays 8 -RetainShareBackupDays 17 -cpylgbkshare
COPYLOG_TOSHARE -lgbkonly -bksif -RetainSnapofSnapInfoDays 17 -gen -mgmt
daily
set SQL_QUERIE="SELECT NAME FROM master.sys.databases AS dtb WHERE NOT
(CAST(case when dtb.name in ('master','model','msdb','tempdb') then 1 else
dtb.is_distributor end AS bit)=1) ORDER BY NAME"
set JOBNAME_FULL_BACKUP=jobname_full
set JOBNAME_INCREMENTAL_BACKUP=jobname_incremental
set SQL_UPDATE_COMMAND_START="UPDATE msdb.dbo.sysjobsteps SET command='
set SQL_UPDATE_COMMAND_END=' FROM msdb.dbo.sysjobs, msdb.dbo.sysjobsteps
WHERE msdb.dbo.sysjobs.job_id = msdb.dbo.sysjobsteps.job_id AND name =
'%JOBNAME_FULL_BACKUP%'"
set SQL_UPDATE_COMMAND_END_INC=' FROM msdb.dbo.sysjobs,
msdb.dbo.sysjobsteps WHERE msdb.dbo.sysjobs.job_id =
msdb.dbo.sysjobsteps.job_id AND name = '%JOBNAME_INCREMENTAL_BACKUP%'"
REM Delete Old files (just to be sure)
del %db_list_wo_summary% %db_list% %linecount_file%
REM Get a List af all Databases and write them into a File
%SQLCMD% -E -S %SQLinstance% -o %db_list% -h -1 -s "," -W -Q %SQL_QUERIE%
setLocal EnableDelayedExpansion
REM Remove the last 2 Lines (one is a summary line, ant the other is empty)
set count=
for /f %%x in ('type %db_list% ^| find /c /v ""') do set /a lines=%%x-2
copy /y nul %tmp%\tmp.zzz > nul
for /f "tokens=*" %%x in ('type %db_list% ^| find /v ""') do (
set /a count=count+1
if !count! leq %lines% echo %%x>>%tmp%\tmp.zzz
)
move /y %tmp%\tmp.zzz %db_list_wo_summary% > nul
REM removes all linebreaks and adds a ' on every star and ending of the
string (and adds a comma)
for /f "tokens=* delims= " %%a in (%db_list_wo_summary%) do (set
s=!s!%%a'', '')
REM removes the last four chars (, '')(comma, space, and 2 '')
set s=!s:~0,-4!
REM counts the lines of the file NOT containing the string XXXYYYZZZ
(basicaly a line count)
type %db_list_wo_summary% | find /V /C "XXXYYYZZZ" > %linecount_file%
for /f "tokens=* delims= " %%c in (%linecount_file%) do (set cn=%%c)
REM Creates the final string for the SQL job
set s1=%arg_start% ''%CN%'', ''!s!%arg_end_full%
set s2=%arg_start% ''%CN%'', ''!s!%arg_end_incremental%
REM Update the SQL Job step command with the new string via SQLCMD
%SQLCMD% -E -S %SQLinstance% -Q
%SQL_UPDATE_COMMAND_START%%s1%%SQL_UPDATE_COMMAND_END%
%SQLCMD% -E -S %SQLinstance% -Q
%SQL_UPDATE_COMMAND_START%%s2%%SQL_UPDATE_COMMAND_END_INC%
REM deleting the temp file
del %db_list_wo_summary% %db_list% %linecount_file%
I hope this can help anyone make things a bit more efficient.
Tuesday, 13 August 2013
Algorithms - optimal way to buy and sell a stock over an interval
Algorithms - optimal way to buy and sell a stock over an interval
Someone gave me a problem from a textbook that I can't figure out. It is:
Let's say that you have a stock STOK that you are set on investing all of
your money in for a month (days 0...30), and at the end of the month you
can't hold any of the stock. You have m money. For any day d the price of
STOK is p(d), and on any day you can either buy or sell stock. However,
there is a limit, l(d), to how much stock you can buy and sell in one day
(it's the same for buying and selling). You can buy non-integer units of
stock if you want, for ease of calculation. Given these functions, how do
you schedule a purchase plan to maximize your profit?
The naive solution: Every day buy as much stock as you can under the
following constraints: If you are unable to sell all of your stock by the
sell date do not buy any more; If you are out of money, do not buy any
more. When you reach the point where you must begin selling stock (this is
known, for you know the stock prices in advance) then sell as much as you
can every day. This solution doesn't work, however, because what if the
stock dips at the beginning of the month then soars after the first five
days?
This smells like dynamic programming, but the fact that the stock price
isn't monotone makes it hard. Brute force is clearly out given the
continuous nature of the problem. Any solutions?
Someone gave me a problem from a textbook that I can't figure out. It is:
Let's say that you have a stock STOK that you are set on investing all of
your money in for a month (days 0...30), and at the end of the month you
can't hold any of the stock. You have m money. For any day d the price of
STOK is p(d), and on any day you can either buy or sell stock. However,
there is a limit, l(d), to how much stock you can buy and sell in one day
(it's the same for buying and selling). You can buy non-integer units of
stock if you want, for ease of calculation. Given these functions, how do
you schedule a purchase plan to maximize your profit?
The naive solution: Every day buy as much stock as you can under the
following constraints: If you are unable to sell all of your stock by the
sell date do not buy any more; If you are out of money, do not buy any
more. When you reach the point where you must begin selling stock (this is
known, for you know the stock prices in advance) then sell as much as you
can every day. This solution doesn't work, however, because what if the
stock dips at the beginning of the month then soars after the first five
days?
This smells like dynamic programming, but the fact that the stock price
isn't monotone makes it hard. Brute force is clearly out given the
continuous nature of the problem. Any solutions?
Very slow query
Very slow query
I am completely new to mysql and have been trying to run the below mysql
query, but it seems to be running incredibly slowly, taking hours. The
table is about 100MB and contains about 2 million rows.
Create TEMPORARY table temp_table as
(
SELECT
pcur.RECORD_ID,
pcur.Price,
(pcur.Price - plast.Price) as 'Price_Difference',
CASE
when plast.Price between 0 and 0.25 then ((pcur.Price -
plast.Price)/0.001)
when plast.Price between 0.2501 and 0.5 then ((pcur.Price -
plast.Price)/0.005)
when plast.Price between 0.5001 and 10 then ((pcur.Price -
plast.Price)/0.01)
when plast.Price between 10.0001 and 20 then ((pcur.Price -
plast.Price)/0.02)
when plast.Price between 20.0001 and 100 then ((pcur.Price -
plast.Price)/0.05)
when plast.Price between 100.0001 and 200 then ((pcur.Price -
plast.Price)/0.1)
when plast.Price between 200.0001 and 500 then ((pcur.Price -
plast.Price)/0.2)
when plast.Price between 500.0001 and 1000 then ((pcur.Price -
plast.Price)/0.5)
when plast.Price between 1000.0001 and 2000 then ((pcur.Price -
plast.Price)/1)
when plast.Price between 2000.0001 and 5000 then ((pcur.Price -
plast.Price)/2)
when plast.Price between 5000.0001 and 9995 then ((pcur.Price -
plast.Price)/5)
END AS Price_Diff_Ticks
FROM
/* First aliased table is the current record */
00005 pcur
/* Second aliased table is the previous one, whose id is one behind */
LEFT JOIN 00005 plast ON (pcur.Record_ID = plast.Record_ID + 1)
)
;
The table's index reports;
"Table" "Non_unique" "Key_name" "Seq_in_index" "Column_name"
"Collation" "Cardinality" "Sub_part" "Packed" "Null" "Index_type"
"Comment" "Index_comment"
============================================================================================
"00005" "0" "PRIMARY" "1" "RECORD_ID" "A" "2275579" "" "" ""
"BTREE" "" ""
What am I doing wrong or what have I missed to manage to make it so slow?
I am completely new to mysql and have been trying to run the below mysql
query, but it seems to be running incredibly slowly, taking hours. The
table is about 100MB and contains about 2 million rows.
Create TEMPORARY table temp_table as
(
SELECT
pcur.RECORD_ID,
pcur.Price,
(pcur.Price - plast.Price) as 'Price_Difference',
CASE
when plast.Price between 0 and 0.25 then ((pcur.Price -
plast.Price)/0.001)
when plast.Price between 0.2501 and 0.5 then ((pcur.Price -
plast.Price)/0.005)
when plast.Price between 0.5001 and 10 then ((pcur.Price -
plast.Price)/0.01)
when plast.Price between 10.0001 and 20 then ((pcur.Price -
plast.Price)/0.02)
when plast.Price between 20.0001 and 100 then ((pcur.Price -
plast.Price)/0.05)
when plast.Price between 100.0001 and 200 then ((pcur.Price -
plast.Price)/0.1)
when plast.Price between 200.0001 and 500 then ((pcur.Price -
plast.Price)/0.2)
when plast.Price between 500.0001 and 1000 then ((pcur.Price -
plast.Price)/0.5)
when plast.Price between 1000.0001 and 2000 then ((pcur.Price -
plast.Price)/1)
when plast.Price between 2000.0001 and 5000 then ((pcur.Price -
plast.Price)/2)
when plast.Price between 5000.0001 and 9995 then ((pcur.Price -
plast.Price)/5)
END AS Price_Diff_Ticks
FROM
/* First aliased table is the current record */
00005 pcur
/* Second aliased table is the previous one, whose id is one behind */
LEFT JOIN 00005 plast ON (pcur.Record_ID = plast.Record_ID + 1)
)
;
The table's index reports;
"Table" "Non_unique" "Key_name" "Seq_in_index" "Column_name"
"Collation" "Cardinality" "Sub_part" "Packed" "Null" "Index_type"
"Comment" "Index_comment"
============================================================================================
"00005" "0" "PRIMARY" "1" "RECORD_ID" "A" "2275579" "" "" ""
"BTREE" "" ""
What am I doing wrong or what have I missed to manage to make it so slow?
Get JS from part of page with ajax
Get JS from part of page with ajax
I use $('.class').load('url #id'), but it get only html code, or I'm doing
something wrong). How get JS from page?
Site where I use this code: http://vbtes.p.ht/Amira/#!contacts (haven't
js, don't work tabs).
Have JS: http://vbtes.p.ht/Amira/contacts
$(window).hashchange( function(){
// Alerts every time the hash changes!
var linkmenuurl = $(location).attr('href').split("#!")[1];
if(location.hash == ''){linkmenuurl ='';}
if(sm==1 && selectedmenu !== linkmenuurl){
$('.active').removeClass('active');
$(elemthis).addClass('active');
if($(elemthis).parent('.main-menu__item_level_1')){
$(elemthis).parent().parent().parent().children('.main-menu__item-link').addClass('active');}
selectedmenu = linkmenuurl;
sm=0;
$('.new').load(linkmenuurl+' #lay_body_get', function(){
$('.new').show();
$('.lb2').css({top:$('.lb1').height()*-1-60});
$('.new').animate({left: 0},500 );
$('.old').animate({left: -1450},500, function() {
$('.old').addClass('ob1');
$('.new').addClass('nw1');
$('.ob1').removeClass('old').addClass('new').css({left:1450}).hide(100);
$('.nw1').removeClass('new').addClass('old').animate({top:0},100,function(){sm=1;});
$('.ob1').removeClass('ob1');
$('.nw1').removeClass('nw1');
});});}
})
// Trigger the event (useful on page load).
$(window).hashchange();
});
I use $('.class').load('url #id'), but it get only html code, or I'm doing
something wrong). How get JS from page?
Site where I use this code: http://vbtes.p.ht/Amira/#!contacts (haven't
js, don't work tabs).
Have JS: http://vbtes.p.ht/Amira/contacts
$(window).hashchange( function(){
// Alerts every time the hash changes!
var linkmenuurl = $(location).attr('href').split("#!")[1];
if(location.hash == ''){linkmenuurl ='';}
if(sm==1 && selectedmenu !== linkmenuurl){
$('.active').removeClass('active');
$(elemthis).addClass('active');
if($(elemthis).parent('.main-menu__item_level_1')){
$(elemthis).parent().parent().parent().children('.main-menu__item-link').addClass('active');}
selectedmenu = linkmenuurl;
sm=0;
$('.new').load(linkmenuurl+' #lay_body_get', function(){
$('.new').show();
$('.lb2').css({top:$('.lb1').height()*-1-60});
$('.new').animate({left: 0},500 );
$('.old').animate({left: -1450},500, function() {
$('.old').addClass('ob1');
$('.new').addClass('nw1');
$('.ob1').removeClass('old').addClass('new').css({left:1450}).hide(100);
$('.nw1').removeClass('new').addClass('old').animate({top:0},100,function(){sm=1;});
$('.ob1').removeClass('ob1');
$('.nw1').removeClass('nw1');
});});}
})
// Trigger the event (useful on page load).
$(window).hashchange();
});
How does this example of a Go closure work?
How does this example of a Go closure work?
I'm reading a (really good) Go book and saw this example, but I don't see
how it works.
func makeEvenGenerator() func() uint {
i := uint(0)
return func() (ret uint) {
ret = i
i += 2
return
}
}
func main() {
nextEven := makeEvenGenerator()
fmt.Println(nextEven()) // 0
fmt.Println(nextEven()) // 2
fmt.Println(nextEven()) // 4
}
Incrementing i is common closure behaviour. That's fine. But if you look
at nextEven, it's a function that takes no arguments and returns a uint
called ret. But what's the point of naming the return value? Won't any
code that calls this use its own variable name?
And the return statement returns nothing - so what's being printed? How is
0 / 2 / 4 coming out of this function?
And how is this different from doing this:
func makeEvenGenerator() func() uint {
i := uint(0)
return func() uint {
current := i
i += 2
return current
}
}
Which seems much simpler and makes things more obvious. Is there some deep
Go / math concept that I'm missing?
I'm reading a (really good) Go book and saw this example, but I don't see
how it works.
func makeEvenGenerator() func() uint {
i := uint(0)
return func() (ret uint) {
ret = i
i += 2
return
}
}
func main() {
nextEven := makeEvenGenerator()
fmt.Println(nextEven()) // 0
fmt.Println(nextEven()) // 2
fmt.Println(nextEven()) // 4
}
Incrementing i is common closure behaviour. That's fine. But if you look
at nextEven, it's a function that takes no arguments and returns a uint
called ret. But what's the point of naming the return value? Won't any
code that calls this use its own variable name?
And the return statement returns nothing - so what's being printed? How is
0 / 2 / 4 coming out of this function?
And how is this different from doing this:
func makeEvenGenerator() func() uint {
i := uint(0)
return func() uint {
current := i
i += 2
return current
}
}
Which seems much simpler and makes things more obvious. Is there some deep
Go / math concept that I'm missing?
Unsure about using singular or plural in a sentence
Unsure about using singular or plural in a sentence
consider the following to sentence:
This table outlines a class of proteins that primarily attack the brain.
I am not sure whether to use "attack" or "attacks". If attack refers to
"class" then I should use attacks but if it refers to "proteins" then I
should use attack.
In this case both versions might work. However, I am not sure about this.
Any help is greatly appreciated.
consider the following to sentence:
This table outlines a class of proteins that primarily attack the brain.
I am not sure whether to use "attack" or "attacks". If attack refers to
"class" then I should use attacks but if it refers to "proteins" then I
should use attack.
In this case both versions might work. However, I am not sure about this.
Any help is greatly appreciated.
How to call the Image function With in UIImagePickerViewController
How to call the Image function With in UIImagePickerViewController
How to call this function with in UIImagePickerviewcontroller -
(UIImage*)imageByScalingAndCroppingForSize:(CGSize)targetSize { UIImage
*sourceImage = self;
UIImage *newImage = nil;
CGSize imageSize = sourceImage.size;
CGFloat width = imageSize.width;
CGFloat height = imageSize.height;
CGFloat targetWidth = targetSize.width;
CGFloat targetHeight = targetSize.height;
CGFloat scaleFactor = 0.0;
CGFloat scaledWidth = targetWidth;
CGFloat scaledHeight = targetHeight;
CGPoint thumbnailPoint = CGPointMake(0.0,0.0);
if (CGSizeEqualToSize(imageSize, targetSize) == NO)
{
CGFloat widthFactor = targetWidth / width;
CGFloat heightFactor = targetHeight / height;
if (widthFactor > heightFactor)
{
scaleFactor = widthFactor; // scale to fit height
}
else
{
scaleFactor = heightFactor; // scale to fit width
}
scaledWidth = width * scaleFactor;
scaledHeight = height * scaleFactor;
// center the image
if (widthFactor > heightFactor)
{
thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;
}
else
{
if (widthFactor < heightFactor)
{
thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
}
}
}
UIGraphicsBeginImageContext(targetSize); // this will crop
CGRect thumbnailRect = CGRectZero;
thumbnailRect.origin = thumbnailPoint;
thumbnailRect.size.width = scaledWidth;
thumbnailRect.size.height = scaledHeight;
[sourceImage drawInRect:thumbnailRect];
newImage = UIGraphicsGetImageFromCurrentImageContext();
if(newImage == nil)
{
NSLog(@"could not scale image");
}
//pop the context to get back to the default
UIGraphicsEndImageContext();
return newImage;
}
(UIImage *)imageByCropping:(UIImage *)imageToCrop toRect:(CGRect)rect {
CGImageRef imageRef = CGImageCreateWithImageInRect([imageToCrop CGImage],
rect);
UIImage *cropped = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return cropped;
}
How to call this function with in UIImagePickerviewcontroller -
(UIImage*)imageByScalingAndCroppingForSize:(CGSize)targetSize { UIImage
*sourceImage = self;
UIImage *newImage = nil;
CGSize imageSize = sourceImage.size;
CGFloat width = imageSize.width;
CGFloat height = imageSize.height;
CGFloat targetWidth = targetSize.width;
CGFloat targetHeight = targetSize.height;
CGFloat scaleFactor = 0.0;
CGFloat scaledWidth = targetWidth;
CGFloat scaledHeight = targetHeight;
CGPoint thumbnailPoint = CGPointMake(0.0,0.0);
if (CGSizeEqualToSize(imageSize, targetSize) == NO)
{
CGFloat widthFactor = targetWidth / width;
CGFloat heightFactor = targetHeight / height;
if (widthFactor > heightFactor)
{
scaleFactor = widthFactor; // scale to fit height
}
else
{
scaleFactor = heightFactor; // scale to fit width
}
scaledWidth = width * scaleFactor;
scaledHeight = height * scaleFactor;
// center the image
if (widthFactor > heightFactor)
{
thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;
}
else
{
if (widthFactor < heightFactor)
{
thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
}
}
}
UIGraphicsBeginImageContext(targetSize); // this will crop
CGRect thumbnailRect = CGRectZero;
thumbnailRect.origin = thumbnailPoint;
thumbnailRect.size.width = scaledWidth;
thumbnailRect.size.height = scaledHeight;
[sourceImage drawInRect:thumbnailRect];
newImage = UIGraphicsGetImageFromCurrentImageContext();
if(newImage == nil)
{
NSLog(@"could not scale image");
}
//pop the context to get back to the default
UIGraphicsEndImageContext();
return newImage;
}
(UIImage *)imageByCropping:(UIImage *)imageToCrop toRect:(CGRect)rect {
CGImageRef imageRef = CGImageCreateWithImageInRect([imageToCrop CGImage],
rect);
UIImage *cropped = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return cropped;
}
Garbage Collection misunderstanding in c#
Garbage Collection misunderstanding in c#
i have searched on google not getting what i want. i don't know i am right
or wrong. look , i have trying to understand GC.Collect() so here is the
code..
public class class1
{
public static int Count;
public class1(int j)
{
int i = j;
}
~class1()
{
SomeSubscriber.Count++;
}
}
i have run this code in my main method..
for (int i = 0; i < 10; i++)
{
class1 subscriber = new class1(i);
subscriber = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
Debug.WriteLine(class1.Count.ToString());
i am getting output 0 but it should bebe 10 according to me because
GC.Collect() must have remove class1 objects from memory so class1
destructor must be called so the count must be increased to 10..can any
body explain this..
i have searched on google not getting what i want. i don't know i am right
or wrong. look , i have trying to understand GC.Collect() so here is the
code..
public class class1
{
public static int Count;
public class1(int j)
{
int i = j;
}
~class1()
{
SomeSubscriber.Count++;
}
}
i have run this code in my main method..
for (int i = 0; i < 10; i++)
{
class1 subscriber = new class1(i);
subscriber = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
Debug.WriteLine(class1.Count.ToString());
i am getting output 0 but it should bebe 10 according to me because
GC.Collect() must have remove class1 objects from memory so class1
destructor must be called so the count must be increased to 10..can any
body explain this..
Subscribe to:
Posts (Atom)