Thursday, 3 October 2013

Django application database error: No module named

Django application database error: No module named

I was trying to connect my database application to project in django.
Succeded on connecting psycopg and database. Then I started to build
application for it by
python manage.py startapp books
and wrote some code in models.py.
But when I tried to put application in INSTALLED_APPS, it caused on error.
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'tut1.books',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
So, I'm in project's folder and type in Command Line:
%>python manage.py syncdb
ImportError: No module named 'tut1.books'
If I remove my app from INSTALLED_APPS, everything goes fine. I suspect,
there gotta be different syntax for linking application.
Tried to change 'tut1.books' to just 'books'. Causes another error.
%>python manage.py syncdb
AttributeError:'module' object has no attribute 'URLFIELD'

Wednesday, 2 October 2013

JSF - Get managed bean by name revisited

JSF - Get managed bean by name revisited

I have been using the following bit of code in a servlet to locate a
session backing bean (as suggested by BalusC) without problems until
recently. Now it only works on Internet Explorer. Chrome and Firefox
appear to be getting a totally new backing bean rather than the original
backing bean. When calling functions in the backing bean, it falls over
with null pointer errors for objects in the backing bean that were
definitely initialized in the original.
FacesContext facesContext = FacesUtil.getFacesContext(req, res);
ProductSelection productSelection = (ProductSelection)
facesContext.getApplication().evaluateExpressionGet(facesContext,
"#{productSelection}", ProductSelection.class);
if(productSelection.getProductType() == null)
{
System.out.println("Sevlet: product type is NULL; did not get the
original backing bean");
}
else
{
System.out.println("Sevlet: product type is: " +
productSelection.getProductType().getProductTypeName());
}
It is a while since I tested this code and there have been several updates
to Java but I'm not sure if these are the cause; I have changed something
in my configuration or Chrome and Firefox have changed something in their
code (unlikely). Is anyone else having similar problems? I am at a loss as
to where to go from here, as there does not appear to be any errors
associated with not finding the backing bean and my debugging skills for
the java lib code are not that great (they don't comment their code very
well and it is hard to follow); any suggestions would be greatly
appreciated.
I am using Netbeans 7.01, JSF 2.0, Glassfish 3.1, and a Derby database. I
tested it on my tower and laptop and it is doing it on both (Win XP and
Win 7). The JRE is 7 update 40 build 1.7.0_40-b43. JDK is 1.6.0_04. Chrome
version is 29.0.1547.76 m. Firefox is 23.0.1. Internet Explorer is
8.0.6001.18702.
The FacesUtil is slightly different to BalusC's code (but it was working
fine):
package searchselection;
import javax.faces.FactoryFinder;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.context.FacesContextFactory;
import javax.faces.lifecycle.Lifecycle;
import javax.faces.lifecycle.LifecycleFactory;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
// By BalusC http://balusc.blogspot.com
// Utility to get the FacesContext.
// Used by the CriteriaServlet to get the backing bean when the user
submits a customised
// search criteria object.
public class FacesUtil
{
// Getters
-----------------------------------------------------------------
//
public static FacesContext getFacesContext(ServletRequest request,
ServletResponse response)
{
// Get current FacesContext.
FacesContext facesContext = FacesContext.getCurrentInstance();
// Check current FacesContext.
if (facesContext == null)
{
// Create new Lifecycle.
LifecycleFactory lifecycleFactory = (LifecycleFactory)
FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
Lifecycle lifecycle =
lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
// Create new FacesContext.
FacesContextFactory contextFactory = (FacesContextFactory)
FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
facesContext = contextFactory.getFacesContext(
request.getServletContext(), request, response,
lifecycle);
// Create new View.
UIViewRoot view =
facesContext.getApplication().getViewHandler().createView(
facesContext, "");
facesContext.setViewRoot(view);
// Set current FacesContext.
FacesContextWrapper.setCurrentInstance(facesContext);
}
return facesContext;
}
// Helpers
-----------------------------------------------------------------
// Wrap the protected FacesContext.setCurrentInstance() in a inner class.
private static abstract class FacesContextWrapper extends FacesContext
{
protected static void setCurrentInstance(FacesContext facesContext)
{
FacesContext.setCurrentInstance(facesContext);
}
}
}
Kind thanks in advance...

Python regex parsing and putting into a multidimensional list

Python regex parsing and putting into a multidimensional list

I know that regex is the way to go here but I am woeful at writing regex
expressions. I have a file where each line looks like this:
"defenders\t2\n" and I want to remove the \t and the \n and put the word
"defenders" into the [0] of my multidimensional list and put the number
"2" in the [1] of my list. Is there an easy regex way to do this in
python?
import re
d = []
with open("somefile.txt") as f:
for line in f:
word = re.search()
rank = re.search()
d.append([word][rank])
This is what I am trying but I do not know how to make it work. Thanks for
the help.

I want to connect android apps to mysql database on web

I want to connect android apps to mysql database on web

Please provide me information about how i am connect my android app on
server based mysql database.
Thnaks in advance..

Java Arrays (java.lang.NullPointerException)

Java Arrays (java.lang.NullPointerException)

I'm getting this error on my java code, and I can't seem to figure out
what I'm doing wrong..
java.lang.NullPointerException
at Race.toString(Race.java:94)
at TestA2Classes.start(TestA2Classes.java:39)
at TestA2.main(TestA2.java:12)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272)
This is the code for one of the java files. The problem seems to be around
the parts where I use the arrays.. What am I doing wrong?
public class Race {
public static final String[] RACE_DESCRIPTIONS = {"Sprint", "Distance",
"Eliminator", "Keirin"};
public static final int SPRINT = 0;
public static final int DISTANCE = 1;
public static final int ELIMINATOR = 2;
public static final int KEIRIN = 3;
public static final int MAX_COMPETITORS = 8;
private int number;
private int typeIndex;
private MyDate date;
private boolean hasFinished;
private Competitor[] competitors;
private int numberOfCompetitors;
public Race(int number, int typeIndex, MyDate date) {
// TODO
this.number = number;
this.typeIndex = typeIndex;
this.date = date;
this.hasFinished = false;
this.numberOfCompetitors = 0;
Competitor[] competitors = new Competitor[MAX_COMPETITORS];
}
public int getNumber() {
// TODO
return number;
}
public boolean getHasFinished() {
// TODO
return hasFinished;
}
public int getTypeIndex() {
// TODO
return typeIndex;
}
public MyDate getDate() {
// TODO
return date;
}
public Competitor getCompetitor(int number) {
// TODO
Competitor competitor = competitors[0];
for(int i=0; i<competitors.length; i++){
if(competitors[i].getNumber() == number){
return competitor;
}
}
return null;
}
public void finishRace(int first, int second, int third) {
// TODO
this.hasFinished = true;
for(int i=0; i<competitors.length; i++){
if(competitors[i].getNumber() == first){
competitors[i].setPosition(1);
} else if(competitors[i].getNumber() == second){
competitors[i].setPosition(2);
} else if(competitors[i].getNumber() == third){
competitors[i].setPosition(3);
} else{
competitors[i].setPosition(0);
}
}
}
public boolean addCompetitor(Competitor competitor) {
// TODO
if(numberOfCompetitors < MAX_COMPETITORS){
numberOfCompetitors++;
return true;
}
return false;
}
public String toString() {
// TODO
String details = number + ", " + RACE_DESCRIPTIONS[typeIndex] + " [" +
date + "]";
if(hasFinished = false){
details += ": Race not finished";
} else if(hasFinished = true){
details += "\n 1st: " + competitors[1].getName();
details += "\n 2nd: " + competitors[2].getName();
details += "\n 3rd: " + competitors[3].getName();
}
return details;
}
}

Tuesday, 1 October 2013

Remove Border From UIStepper (iOS 7)

Remove Border From UIStepper (iOS 7)

Does anyone have any clue how to remove the border from the stepper
control? I know you can set the divider image, but I can't find any way to
get rid of the border. I'm trying to recreate the control in the mail app
which allows you to flip through mail messages.
Thanks in advance

Python Version Issues With 2.7

Python Version Issues With 2.7

I am Mac user and I have been using 2.6 for quiet sometime. And I had to
upgrade it to 2.7 for some reason. Now it keeps throwing some packages
aren't available like httplib2 etc.,
when I checked in /usr/lib/ i see only 2.5 and 2.6 folders. I dont see 2.7
in there but 2.7 files are here
"/Library/Frameworks/Python.framework/Versions/2.7/lib/Python2.7 So I
added the path as well..but nothing seems to work.I am very poor with
configuring the environment variable
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH

Number of terms in $n$ variables over finite field

Number of terms in $n$ variables over finite field

I'm reading a paragraph in book that say:
Let be $\mathbb{F}$ a finite field. For $d>0$ (degree of the system) the
expression $A={\sum_i^{\min(|\mathbb{F}|-1,d)}}$ ${n}\choose{i}$ represent
the number of terms in $n$ variables over finite field. My question is Why
this formula?. For example for $n=3$, $d=2$. I have $A=7$ but for mine
this is wrong because I will be able to form the polynomial:
$a+bx_1+cx_2+dx_3+ex_1^2+fx_2^2+gx_3^2+x_1x_2 + x_2x_3+x_1x_3$ with $10$
terms.

can we decompose $\mathcal{A}$ of $\Bbb{R}^n$as an orthogonal transformation and a dilation?

can we decompose $\mathcal{A}$ of $\Bbb{R}^n$as an orthogonal
transformation and a dilation?

Problem
Any linear transformation of $\Bbb{R}^n$ is the composition of an
orthogonal transformation and a dilation along perpendicular
directions(with distinct coefficients)


for any linear transformation $\mathcal{A}$ of $\Bbb{R}^n$, assume its
correspond matrix is $A$,it can be decomposed as below $$A=UDW$$,where
$U,W$ is unitary matrices, $D$ is diagonal matrix. So any linear
transformation $\mathcal{A}$ is the composition of an orthogonal
transformation($W$) and a dilation($D$) along perpendicular directions and
an orthogonal transformation($U$). But I don't know how to decompose
$\mathcal{A}$ as an orthogonal transformation and a dilation along
perpendicular. Please Help me. thanks.

Monday, 30 September 2013

Can't put expression in terms of y (Derivatives of Inverses Formula)

Can't put expression in terms of y (Derivatives of Inverses Formula)

Disclaimer: This is not a student posting his homework assignment.
I am an adult learning Calculus. I think this is a great forum,
Ok, you know the formula for the derivative of an inverse:
$f^{-1}(x)=\frac{1}{f'(f^{-1}(x))}$
Using this, how do you answer this one?
Find $(f^{-1})'(x)$ if $f(x)=\frac{2x-1}{x+1}$
First, using Chain rule, I determined that $f'(x) = \frac{3}{(x+1)^2}$
But, I was having trouble getting the inverse of f(x).
$y=\frac{2x-1}{x+1}$
Inverse is: $x=\frac{2y-1}{y+1}$
But, I can not put this in terms of y! What do I do?

disable appbar button programatically?

disable appbar button programatically?

I have two icons (buttons) in my appbar. One is next and another one is
back. While user viewing the first, there is no use of back button and
also for last page, no use of next button. So, I wanna decide to disable
appbar icons programmatically. Below is my code. But, App breaks for my
code.
Breaking reason:
An exception of type 'System.InvalidOperationException' occurred in
Microsoft.Phone.ni.dll but was not handled in user code
If there is a handler for this exception, the program may be safely
continued.
XAML CODE:
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar Mode="Default" Opacity="1.0"
IsMenuEnabled="False" IsVisible="True">
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
C# CODE:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (NavigationContext.QueryString.ContainsKey("Page"))
{
var page = NavigationContext.QueryString["Page"];
IsolatedStorageSettings.ApplicationSettings["File"] = page;
IsolatedStorageSettings.ApplicationSettings.Save();
browser.Navigate(new Uri("htmlfiles/" + page + ".html",
UriKind.Relative));
if (page == "1")
{
ApplicationBarIconButton b = new ApplicationBarIconButton();
b.Text = "next";
b.IconUri = new Uri("Assets/next.png", UriKind.Relative);
ApplicationBar.Buttons.Add(b);
}
if (page == "69")
{
ApplicationBarIconButton b = new ApplicationBarIconButton();
b.Text = "back";
b.IconUri = new Uri("Assets/back.png", UriKind.Relative);
ApplicationBar.Buttons.Add(b);
}
else
{
ApplicationBarIconButton a = new ApplicationBarIconButton();
a.Text = "next";
a.IconUri = new Uri("Assets/next.png", UriKind.Relative);
ApplicationBar.Buttons.Add(a);
ApplicationBarIconButton b = new ApplicationBarIconButton();
b.Text = "back";
b.IconUri = new Uri("Assets/back.png", UriKind.Relative);
ApplicationBar.Buttons.Add(b);
}
}
}

Compare BCrypt hash to Bcrypt hash PHP

Compare BCrypt hash to Bcrypt hash PHP

here's what I'm up against.
I have an app for iPhone that I am building that communicates with
password protected pages on my site. The app can get through the password
protection fine and can get the response from the page just fine. The
problem is that when I try to login to the site from my app it gets
rejected. I believe this is because I am hashing the password with Bcrypt
in the app before sending it to the site and then checking it with
password_verify(), which of course takes the plain text of the password
and then the hashed version, but I am giving it two hashed versions of the
same thing which it is not accepting.
My question is this: is it possible to compare the two encrypted passwords
using password_verify or some other function, or not? And if not, is it
secure enough to (dare I say it) send the password in plain text from the
app?
Thanks to everyone in advance!

Data insertion using array in PHP

Data insertion using array in PHP

I have a php script for conducting online test. while taking test, I am
using post method to get the answers in the action page.The answers are
passed as an array with question id and the selected option value(true or
false/the answers the candidate entered like that).Then I have to insert
the answers marked by the candidate in the database. The code is as shown
below:
$student_id=$_POST['name'];
$survey_id=$_POST['survey_id'];
$store = array();
if (isset($_POST['question_id'])) {
foreach ($_POST['question_id'] as $key => $option) {
$option1 = array_filter($option);
print_r($option1);
if (count($option1) > 1) {
$option2 = implode("^", $option1);
$store[] = $option2;
} else {
$value = $option1;
$i = implode(null, $option1);
$store[] = $i;
}
}
print_r($store);
}
$t = new DateTime();
$t->setTimestamp($time = time());
$t->setTimeZone(new DateTimeZone("Asia/Singapore"));
$date = $t->format(DateTime::RFC850);
$SQL = "INSERT INTO answer_table(student_id ,survey_id, ans_1, ans_2,
ans_3, ans_4, ans_5, ans_6, ans_7, ans_8, ans_9, ans_10, timestamp)
VALUES ('$student_id','$survey_id', '$store[0]', '$store[1]',
'$store[2]', '$store[3]', '$store[4]', '$store[5]', '$store[6]',
'$store[7]', '$store[8]', '$store[9]', '$date')";
$result = mysql_query($SQL);
If the student answers the test in sequential order(from question number 1
to 10) the code works fine. But when the candidate answers in random
manner(first 10 then 5 like that),the table field named,ans_1 will get
inserted with answer of question number 10. I need to insert fields with
corresponding answers ,(ans_1 with answer of question 1 like that) what
ever pattern,the candidate takes test.
Can anyone help me to solve this issue. Thanks in advance.

Sunday, 29 September 2013

difference between (unsigned)1 and (unsigned)~0 in c

difference between (unsigned)1 and (unsigned)~0 in c

what is the difference between (unsigned)~0 and (unsigned)1.why is
unsigned of ~0 -1 and unsigned of 1 is 1? does it have something to do
with the way unsigned numbers are stored in the memory.why does an
unsigned number give a signed result.it dint give any overflow error
either. i used gcc
#include<sdio.h>
main()
{
unsigned int x=(unsigned)~0;
unsigned int y=(unsigned)1;
printf("%d\n",x); //prints -1
printf("%d\n",y); //prints 1
}

Is FBconnect from 2010 out of use?

Is FBconnect from 2010 out of use?

I have taken over an app project for iOS 5 that was built in 2010/2011.
The project has facebook connectivity but it does not work and I suspect
it is because it uses an old interface towards fb. In the files I can see
that the FBConnect.h file is Copyright 2010.
Is there any legacy support or do I have to throw this out and use a newer
interface instead?
In my code I have among other things
#define ACCESS_TOKEN_KEY @ ######
#define EXPIRATION_DATE_KEY @
if ([defaults objectForKey:ACCESS_TOKEN_KEY] && [defaults
objectForKey:EXPIRATION_DATE_KEY]) {
facebook.accessToken = [defaults objectForKey:ACCESS_TOKEN_KEY];
facebook.expirationDate = [defaults
objectForKey:EXPIRATION_DATE_KEY];
}
From what I can see on the fb API it wants an App ID and a Secret instead
of the above.
When running, it doesn't crash but neither is it able to connect to fb.
The login screen does not show and it seems always to end up in the
- (void)fbDidNotLogin:(BOOL)cancelled {
[[self delegate] didNotLoginOnFacebook:(BOOL)cancelled];
}
The app is built for iOS5 and forward. I know that iOS6 has built in
facebook integration which would probably make everything easier. Question
now is if my code is useable at all or if I have to throw it out?

Split lines in excel by delimeter?

Split lines in excel by delimeter?

I wish to know if its possible to do the following: In case of the
following scenario:
a value1 3
b value2 1
c value3\nvalue3_1\nvalue3_2 1
d value4 1
e value5\nvalue5_1 1
to transform it into: a value1 3 b value2 1 c value3 1 c value3_1 1 c
value3_2 1 d value4 1 e value5 1 e value5_1 1
I dont mind that if the input is in sheet1, the output is in sheet2. my
excel skills are pretty much a beginner, so im not sure if thats even
possible

How to safely host proofing site without exposing the host

How to safely host proofing site without exposing the host

I am setting up a network. In this network, we have:
1) 4 Development machines (3 Windows, 1 Mac)
2) 1 Server (Ubuntu)
3) 1 Router (WRT54GL with Tomato)
4) 1 Cable Modem
As this is for web development, we have several stages in our production
cycle. We are using Git for version control, and XAMPP on each machine to
host the website. Each machine host its own full copy of the website, but
all machines share the same database since Git does not handle versioning
for that. We use Git hooks to backup the database on Pulls/Pushes and Cron
Jobs run to back it up as well.
Therefore, a typical workflow would be as such:
1) Each developer works on the site on their own local copy from the Git bare
repo
2) Each developer pulls, then commits and pushes their changes to the bare
repo
3) After this, we go to a staging environment where we ensure everything is
going to work on a totally different setup than the development machines
This environment is still using the same database as for development.
4) From there, we would upload the changes to the FTP.
The question is, I need a way to host the site on our local machine in a
step AFTER the staging environment but BEFORE going to their remote server
(a stage called proofing) so that clients can view the site, suggest
modifications, etc. I want to know how to do this as securely as possible.
I have most of this setup. We are using a WRT54GL router, which connects
to afraid.org free DNS, and we will update the dynamic IP using the query
string supplied by afraid.org in the firmware settings of Tomato. The site
will not be live all the time. The server gets shut down at night and does
not come on until morning. It is off on weekends. Once the site is out of
proofing, it will be taken off from being hosted on our local server and
be pushed to FTP, on to be live on a remote web server. Proofing uses a
different database for security / integrity reasons.
I cannot get a new machine to host this. It must be done on the same
machine that we do staging on and have the Git repo stored on. This
machine has AFP, FTP and SAMBA shares, VNC and SSH. Data is backed up
remotely, on external drives, and another server.
Is there any way I can put the 'proofing stage' on a Virtual Machine,
allowing web access there, etc while limiting requests to the host
(remember, it is running XAMPP, too)? Can I force external / non-LAN
requests to port 80 to be pushed to the VM and ignored by the host? How
can I protect our local sites for development, while allowing remote
access to the sites in the proofing stage?
Ideally, I would be able to have an entirely separate machine isolated
from the rest of the LAN to do this, but in this case it is not possible.
I know how to setup virtual hosts, virtual machines, etc and will be
installing some security software to protect mission critical files from
being had through the internet.
I have a picture of the theoretical setup, but cannot post it due to
reputation.

Saturday, 28 September 2013

$V(X^m + Y^m - Z^m)$ (projective Fermat curve) isomorphic to projective line iff $m=1, 2$

$V(X^m + Y^m - Z^m)$ (projective Fermat curve) isomorphic to projective
line iff $m=1, 2$

I've convinced myself that the projective Fermat curve $V(X^m + Y^m - Z^m)
\subset \mathbb{P}^2$ is isomorphic to a projective line if and only if $m
=1$ or $m = 2$, but I'm not sure how to prove this fact.
Are there proofs of this fact available online? Can anyone provide a proof?

Passing parameter from a nested RadListView to it's datasource

Passing parameter from a nested RadListView to it's datasource

I've a RadListView inside a RadListView, the inner RadListView's
datasource is ObjectDataSource. I need to pass a parameter value from
inner RadListView to it's objectDataSource. How do I do this?
I set the Outer RadListView's datasource from code-behind.
(FormField="CategoryLabel" doesn't work below)
<asp:ObjectDataSource ID="ReportsDataSource" runat="server"
SelectMethod="GetAllReportsByType"
TypeName="abc.Service.DataService">
<SelectParameters>
<asp:Parameter DefaultValue="abcReports" Name="type"
Type="String" />
<asp:FormParameter DefaultValue="" FormField="CategoryLabel"
Name="category" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<telerik:RadListView runat="server" ID="ReportTypesListView" Skin="Glow">
<ItemTemplate>
<telerik:RadAjaxPanel runat="server">
<div>
<asp:Label runat="server" Text='<%# Container.DataItem
%>' />
<telerik:RadListView runat="server"
ID="ReportsListView" DataSourceID="ReportsDataSource">
<ItemTemplate>
<br />
<asp:Label ID="CategoryLabel" Visible="false"
runat="server" Text='<%# Eval("Category") %>'
/>
<asp:HyperLink runat="server" Text='<%#
Eval("DisplayName") %>'
ToolTip='<%# Eval("Description") %>' />
<br />
</ItemTemplate>
</telerik:RadListView>
<br />
<br />
</div>
</telerik:RadAjaxPanel>
</ItemTemplate>
</telerik:RadListView>

example.com and www.example.com are treated as different sessions

example.com and www.example.com are treated as different sessions

So i have a small website that requires users to log in with a username
and password. Everything works fine apart from 1 tiny problem
when the user logs in using the url studeez.net, he or she is redirected
to a page where the top bar displays his Firstname, lastname and an option
to logout.
But if i add www. before the link so that it becomes www.studeez.net, the
user is given the login /register options.
This is quite the issue because when the user tries to log in, he or she
gets a feedback that they are already logged in.
How do i harmonize studeez.net and www.studeez.net as well as all the
subsequent urls like studeez.ney/path/to/page and
www.studeez.ney/path/to/page