Tuesday, April 24, 2012

SQLITE Sql query to get the value while comparing value

There are three table.




Table X

| Field 1 | Field 2



Table Y



| Field 2 | Field 3



Table Z



| Field 3 | Field 4




The idea is to get the row from table Z but need to go from table X comparing a value selected value for field 1.



From Table X field 1, will get the value for field 2. On Table Y the value from field 2 will get the value for field 3.



On Table Z field 3 will get the final value from Field 4.



Any idea on how to do it in sqlite?





"string is not a type" in namespace

I write a program in c++ with two files.



main.cpp



#include "var.hpp"
#include <iostream>
using namespace std;
using namespace YU;

int main()
{
string god = "THL";
age = 10;
cout << age << endl;
cout << god << endl;
return 0;
}


var.hpp



#ifndef __VAR_H__
#define __VAR_H__

#include <string>

namespace YU
{
int age;
string name;
}

Digit/Number Recognition Hand-written

Can anyone recommend a handwritten digit/number recognition library which I could use in c++/OpenGL. I need to recognise the digits/numbers in my OpenGL project written by a user.



Thanks





Asterisk GUI Using php or any other framework

In asterisk I would like to have GUI to add/remove/edit Extensions.
This gui will also enable to update mysql database along with extension.conf add/edit when I add/delete new users. FreePbx can add/remove/edit extensions only.



Is there any framework exists for this purpose or I should purely go to write PHP from scratch ?



Thanks.





Should sensitive data be encrypted through both script and database means?

I don't know too much about encryption, but is there any benefit to encrypting the already encrypted, lets say passwords? I am aware of salts, but before this is done, does it matter or not?





Django: creating form which has relationship

I've prepared a model with a relationship.
I'd like to get a form which will make it possible to create User for that form.



Could someone explain me how it can be resolved?



class UserProfile(models.Model):
user = models.OneToOneField(User, unique=True, primary_key=True)
website = models.URLField(null=True, blank=True)
accepted_rules = models.BooleanField(default=False)
accepted_rules_date = models.DateTimeField(auto_now_add=True)


class UserProfile(ModelForm):
class Meta:
model = UserProfile

@csrf_protect
def register(request):
if request.method == "POST":

form = UserProfile(request.POST or None)
if form.is_valid():
website = form.cleaned_data['website']
accepted_rules = form.cleaned_data['accepted_rules']

username = form.cleaned_data['username']
email = form.cleaned_data['email']
password = form.cleaned_data['password']



formset.save()


print "All Correct"


return TemplateResponse(request, 'base.html', {
'form':form,
}
)




On iOS, why the init in ViewController didn't work?

In the ViewController's interface, I have



@property int count;


and in the implementation, I have



@synthesize count;

-(id) init {
self = [super init];
if (self) {
self.count = 100;
}
return self;
}

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"%i", self.count++);
}


but for some reason, the first time self.count got printed, it is 0 but not 100?





table based declarative reactive programming

Is there a programming language or package that supports table based reactive declarative programming in memory very similar to the SQL language and trigger facility?



For example, I could define PERSON and JOB tables as functions



name: PERSON -> STRING
female: PERSON -> BOOLEAN
mother: PERSON -> PEOPLE
father: PERSON -> PEOPLE

title: JOB -> STRING
company: JOB -> STRING
salary: JOB -> INTEGER
empoyee: JOB -> PERSON


Then I would like to calculate functions like:



childcount: PERSON -> INTEGER
childcount(P) = |{ Q in PERSON : father(Q) = P or mather(Q) = P }|

income: PERSON -> INTEGER
income(P) = SUM { salary(J) : J in JOB and empoyee(J) = P }

incomeperchild: PERSON -> INTEGER
incomeperchild(P) = income(P) / childcount(P)

parent: PERSON x PERSON -> BOOLEAN
person(P,Q) = (P = father(Q)) or (P = mother(Q))

error: PERSON -> BOOLEAN
error(P) = (female(P) and (exists Q in PERSON)(father(Q) = P))
or (not female(P) and (exists Q in PERSON)(mother(Q) = P))
or (exists Q in PERSON)(parent(P,Q) and error(Q))


So essentially I would like to have calculated columns in tables that are automatically updated whenever values in the tables change. Similar things could be expressed with SQL triggers, but I would like to have such functionality built into a language and executed in memory. The propagation of changes need to be optimized. Are there frameworks to do this?



The observer patter and reactive programming focuses on individual objects. But I do not want to maintain pointers and extra structure for each row in my tables as there could be million of rows. All the rules are generic (although they can refer to different rows via parent/children relations, etc), so some form of recursion is required.





Is there a limit on the number of lines of code you can put in an Eclipse java doument

I have a project I have been working on and all was going well until today. I have close to 6000 lines of code in one java class document. If I try to put one more IF clause into the code, the program throws an exception when the class is called on. I am using eclipse and I have not uploaded my usage yet. Is that the problem. All additional snippets that I have tried to place into the class, cause the class to fail when called on. I have tried to add test code that I know works fine, and they all throw the force close dialog. Trust me there is nothing wrong with the last snippet that I attempt to place into the class. Once I take out the last if statement, there are no errors. Has anyone ever seen this before? The exception is thrown in the emulator, when the class is called. I get the force close alert window. Thanks in advance!





How do I create a centered div of uncertain width containing left-aligned elements?

I have several uniform blue elements (<div style="display: inline-block;">) inside a red div inside a purple div. Mockup (imgur).



I would like the blue elements to be left-aligned (as many in a row as will fit in the purple div width), with a red div shrink-wrapped around them. But then I would like the red div be horizontally centered inside the purple div.



I was hoping to do something like this (jsFiddle), but that only works if the red div has a specified width.





java: about counting in txt file

i want to counting some words in txt file

myfile.txt



ABC,xyzwegwegwe
ABC,12312312312
ABC,sdfsdf3sdfs




how can i count the words"ABC"?

output:"ABC" have: 3



File abcfile = new File("myfile.txt");
Scanner myfile = new Scanner(abcfile);
String line = null;
int words = 0;
while (myfile.hasNextLine()) {
line = myfile.nextLine();
lines.add(line);
if(xxxxx){ //if have ABC, words++
words++;
}
}
System.out.print("\"ABC\" have: "+words);




Knockout.js repeat rows in table for nested model / containerless "foreach" inside table

I'm building an application to track orders of tailor made products. Each product can have many custom details. The screen to add products to an order and customize each one should look like this:



<button>+</button><!-- "Add new product line" button -->
<table>
<thead>
<tr>
<th></th>
<th>Producto</th><!-- The product category or type -->
<th>Modelo</th><!-- The product -->
<th>Cantidad</th><!-- Quantity -->
<th>Unitario</th><!-- Unit Price -->
<th>Mano de Obra</th><!-- The price of the product itself -->
<th>Genero</th><!-- The price of the customization -->
</tr>
</thead>
<tbody>
<tr class="producto"><!-- Product line -->
<td><button>-</button></td><!-- "Remove" button, should remove the product and it's customizations -->
<td><select>Producto</select></td><!-- Choose category -->
<td><select>Modelo</select></td><!-- Choose product -->
<td><input type="text" class="cantidad" /></td><!-- Enter quantity -->
<td><input type="text" class="unitario" /></td><!-- Enter unit price -->
<td>$ <span class="mano_obra"></span></td><!-- Line total. The product lines calculates on this column -->
<td><button>+</button></td><!-- "Add customization" button. Should add a line like the next <tr> -->
</tr>
<tr class="genero"><!-- Customization line -->
<td><button>-</button></td><!-- "Remove" button, should remove only this customization line -->
<td>Genero</td><!-- Fixed text -->
<td><input type="text" class="genero" /></td><!-- Enter customization description -->
<td><input type="text" class="cantidad" /></td><!-- Enter quantity -->
<td><input type="text" class="unitario" /></td><!-- Enter unit price -->
<td>&nbsp;</td><!-- On customizations, this column is empty -->
<td>$ <span class="genero"></span></td><!-- Line total. The customizations calculates on this column -->
</tr>
<tr class="genero">
<!-- Another customization for the first product -->
</tr>
<tr class="genero">
<!-- Another one -->
</tr>
<tr class="producto">
<!-- A different product -->
</tr>
<tr class="genero">
<!-- The new product customization -->
</tr>
<!-- (etc) -->
</tbody>
<tfoot>
<tr>
<td colspan="5">Subtotales</td><!-- Fixed text -->
<td>$ <span class="subtotal_mano_obra"></span></td><!-- SUM of each line total, for products -->
<td>$ <span class="subtotal_genero"></span></td><!-- SUM of each line total, for customizations -->
</tr>
</tfoot>
</table>


I've tried to do this:



<tbody data-bind='foreach: lineas_pedido'>
<tr class="producto">
<!-- All the bindings here works fine -->
</tr>
<!-- ko foreach: generos -->
<tr class="genero">
<!-- ... -->
</tr>
<!-- /ko -->
</tbody>


But after getting errors and looking, came to this: Knockout.js containerless "foreach" not working with <table>



So, I found this plugin: https://github.com/mbest/knockout-repeat
And now my code looks like this:



<tbody data-bind='foreach: lineas_pedido'>
<tr class="producto">
<!-- All the bindings here works fine -->
</tr>
<tr class="genero" data-bind="repeat: {foreach: generos, item: '$genero'}">
<!-- ... -->
</tr>
</tbody>


My question is: Is there any way to avoid using the plugin, and accomplish the same result using native KO templating/bindings?



Thanks in advance.



Edit:



Here is the jsfiddle, I've added a resource linking to my sample data (categories and products).



Here is the actual code on my testing host.



Also, I've used this example as the start point.





Displaying the UK on a Google map

I have created an application in which I have displayed a Google map (version 3.0 tablet).



I need to show the UK, with zoom, when I load it for the first time.



The user should be able to zoom in and zoom out.



How can I do this?





what is the specific re for this

I'm trying to use python re to find a set of the same letter or number repeated a specific number of times. (.) works just fine for identifying what will be repeated, but I cannot find how to keep it from just repeating different characters. here is what I have:



re.search(r'(.){n}', str)


so for example it would match 9999 from 99997 if n = 4, but not if n = 3.

thanks





Javascript/jQuery: Unable to get proper keyCode when capsLock is ON

I'm trying to determine the proper key/char code in javascript when a key is pressed.
It seems that when the CapsLock key is on, lowercase letters are not detectable.



Try the combinations:
1. a = a (97) shift:false
2. Shift+A = A (65) shift:true
3. Capslock,A = A (65) shift:false
4. Capslock, Shift+A = A (65) shift:true -- this should be 'a'


Cases 2 & 4 are indistinguishable.



A simple fiddle to illustrate the problem.
http://jsfiddle.net/sramam/pet5G/3/



OUTPUT:
keypress 'a' shift:false charCode97 keyCode:97 which:97
keypress 'A' shift:true charCode65 keyCode:65 which:65
(CAPSLOCK ON)
keypress 'A' shift:false charCode65 keyCode:65 which:65
keypress 'A' shift:true charCode65 keyCode:65 which:65


I only have a MacPro(Lion) to try this on.
Is it even possible to detect character to be rendered correctly?





Membership testing in a large list that has some wildcards

How do I test whether a phrase is in a large (650k) list of phrases when that list includes special categories?



For instance, I want to test if the phrase ["he", "had", "the", "nerve"] is in the list. It is, but under ["he", "had", "!DETERMINER", "nerve"] where "!DETERMINER" is the name of a wordclass that contains several choices (a, an, the). I have about 350 wordclasses and some of them are quite lengthy, so I don't think it would be feasible to enumerate each item in the list that has one (or more) wordclasses.



I would like to use a set of these phrases instead of slowly working my way through a list, but I don't know how to deal with the variability of the wordclasses. Speed is pretty important, since I need to make this comparison hundreds of thousands of times per go.





Random split list, keeping the original order in new lists

I am having a hard time formulating my question so I'll just show by example.



x = ['abc', 'c', 'w', 't', '3']
a, b = random_split(x, 3) # first list should be length 3
# e.g. a => ['abc', 'w', 't']
# e.g. b => ['c', '3']


Is there an easy way of splitting a list into two random samples while maintaining the original ordering?






edit I know that I could use random.sample and then reorder, but I was hoping for an easy, simple, one line method.





Javascript While loop integers

I have to create a while loop displaying the integers from 1-20 but only 5 integers per line.
I can't get the 5 integers per line part. What is the best way to do that?





Slickgrid add new row on demand

Is there a way to add a new row to a slickgrid on demand? For example, have a button on the page that shows the new row when clicked.





Android listview with multiple controls

I am new to android. I am developing an application in which there is a list view of students with edit and delete buttons. Like







 STUDENT LIST


[ABC]              [edit]              [delete]



[DEF]              [edit]              [delete]







With this code im able to list student details in a <Textview>



public class DataBaseDemoActivity extends ListActivity {
/** Called when the activity is first created. */
SQLiteDatabase db;
Button btnInsert;
ArrayAdapter<String> students;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try{
db=openOrCreateDatabase("StudentDB",SQLiteDatabase.CREATE_IF_NECESSARY,null);

Cursor c=db.rawQuery("SELECT * FROM temp",null);
String[] students = new String[c.getCount()];

if (c.moveToFirst())
{
for (int i = 0; i < c.getCount(); i++)
{
students[i] = c.getString(0).toString()+" "+c.getString(1).toString();
c.moveToNext();
}
}
c.close();

setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, students));

ListView lv = getListView();
lv.setTextFilterEnabled(true);

lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
Toast.LENGTH_SHORT).show();
}
});


}catch(SQLException e)
{
}
}


}



I need to store the id of the record with in the list view so that when i click on the edit or delete button, i'll have to find out the id and make changes on the DB. How can i set values to two fields say <TextView>[show details] and <EditText>[visibility: insisible - to save id of the record]. I am able to get the details to the <TextView> using the above code. Any suggestion will be appreciated.