Wednesday, 11 September 2013

Proper syntax for "CASE WHEN ... THEN ... DELETE ... END" in SQLite triggers?

Proper syntax for "CASE WHEN ... THEN ... DELETE ... END" in SQLite triggers?

I'm trying to figure out how to put a delete statement inside a
conditional in an SQLite trigger.
I've come up with this code:
CREATE TRIGGER mytrigger
BEFORE INSERT ON mytable
BEGIN
SELECT CASE WHEN
1 == 1
THEN
DELETE FROM mytable
END;
END;
But it fails with:
Error: near "DELETE": syntax error
If I replace DELETE FROM mytable with RAISE(FAIL, "mytrigger was
activated"), it compiles fine.

Getting list out of python list of list

Getting list out of python list of list

I am using python list of list as follows,
List L = [ ['a',4] ['b',2] ,['c',13]]
I want to generate new List for all the number which are the position
second in each set of the list
New List L* = [ 4, 2, 13]
Is there any shortcut in python to get above L* list

Which one runs faster, ArrayList or LinkedList? [duplicate]

Which one runs faster, ArrayList or LinkedList? [duplicate]

This question already has an answer here:
When to use LinkedList<> over ArrayList<>? 24 answers
Performance differences between ArrayList and LinkedList 6 answers
List li = new LinkedList();
for (int i = 0; i < 100; i++) {
li.add(i);
}
long start1 = System.nanoTime();
li.get(57);
long end1 = System.nanoTime();
long diff1 = end1-start1;
System.out.println("Time taken by LinkedList = "+diff1);
List al = new ArrayList();
for (int i = 0; i < 100; i++) {
al.add(i);
}
long start2 = System.nanoTime();
al.get(57);
long end2 = System.nanoTime();
long diff2 = end2-start2;
System.out.println("Time taken ArrayList = "+diff2);
System.out.println((diff1<diff2)?"LinkedList runs faster":"ArrayList
runs faster");
}
What ever operations i perform on both the Lists, when i print out the
time taken, it is always ArrayList that runs faster. Can somebody explain
which performs better in terms of time taken? Also let me know if there is
something wrong in the code. Thanks!

Tuesday, 10 September 2013

Audio Comparison using Micorosft speech recognition engine

Audio Comparison using Micorosft speech recognition engine

I have an application in which user can speak and a word and he will be
given the percentage accuracy of the word he spoke. i.e how much clearly
the engine recognized the word.
This all works fine ,but i have a dilemma that what words needed to be
added to the dictionary which i will give to the recognition engine as
dictionary.
If i give words starting with "p" for case pen then words like pendant
,pent etc all will be added to the dictionary.In that case i am not
getting the recognized word as "pen".
Instead i always get other words like "pendant" etc
But if i only add limited words to dictionary like "pe","pen" then for the
same recorded file i got the recognized words as "Pen" only.
Means it clearly depends on the words which we give to the dictionary.
I have conveyed the same to my client.But what they want is that they can
speak wrong words also for a given input words ,so at that time they need
not want to get the accuracy and also get the recognized text.
I have done what i could have done for the issue.But my client needs
something apart from universe.
Do any experts have solution for this here? Any help will be appreciated.
Thanks

How to get "isDirty" flag in Epf (Ember Persistence Foundation) to reset after flush or refresh?

How to get "isDirty" flag in Epf (Ember Persistence Foundation) to reset
after flush or refresh?

I'm using Epf in a new project, and have set up my model as so:
Etst.Persona = Ep.Model.extend
name: Ep.attr 'string'
age: Ep.attr 'number'
favorite_food: Ep.attr 'string'
isClean: ( ->
! @get("isDirty")
).property("name", "age", "favorite_food")
I need the "isClean" rather than straight "isDirty" to make a disabled
button show up only when the model is dirty.
I find that when I change any field through an Ember.TextField it changes
perfectly.
However, I find that after I do either a call to flush() or refresh(), the
model in memory does NOT have its "isDirty" flag cleared, even though it's
been successfully saved or reloaded.
Thanks!

CollectionProxy returns nil when creating a new object

CollectionProxy returns nil when creating a new object

I have a model with a has_many relationship that's built through nested
forms:
class User < ActiveRecord::Base
has_many :properties
accepts_nested_attributes_for :properties, allow_destroy: true
def billing_address
debugger
properties.find_by(billing_address: true)
end
end
Overall, the relationship and nested form works. However, if I call the
method billing_address during creation, then it returns nil, even if there
is a nested property with billing_address set to true. I experimented with
this in debugger, and it seems that calling properties.find_by or
properties.where during creation always results in nil, even if the
parameters match a real object.
When I type properties into debugger, I get results like this, which
clearly show that there is a property with billing_address set to true:
#<ActiveRecord::Associations::CollectionProxy [#<User::Property id: nil,
address: "1111 E 1st", city: "Austin", state: "TX", zip_code: "11111",
phone_number: "11111111111", user_id: nil, primary: true, billing_address:
true, created_at: nil, updated_at: nil>]>
So why can't I find it with a query such as
properties.find_by(billing_address: true)? Is there another approach to
getting at this data?

Discarding transport error while using nodejs + socketio

Discarding transport error while using nodejs + socketio

I am building an android chat application. I am using nodejs at server end
and trying to implement android client for socketIO. First the client
echoes "hello" to the server and the server echoes it back to the client.
This works fine. Now there is a Button, which when pressed echoes the text
in the EditText to the server. Server is supposed to echo the text back to
the client. However, as soon as text is echoed to the server, I get
Discarding transport error at server end and nothing is echoed back.
Client is unable to echo anything further. What is wrong with the codes ?
Server
var http = require('http'),fs = require('fs');
var app = http.createServer(function (req, res) {
res.end();
}).listen(8000,
'127.0.0.1');
var io = require('socket.io').listen(app);
io.sockets.on('connection', function(socket) {
socket.on('echo', function(data) {
socket.emit('echoback', data);
});
});
Client
package com.jack.pri;
import java.net.MalformedURLException;
import org.json.JSONException;
import org.json.JSONObject;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import io.socket.*;
public class MainActivity extends Activity {
private SocketIO socket;
private TextView tview;
private Button btn;
private EditText tt;
private String k;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tview=(TextView) findViewById(R.id.tv);
tt = (EditText) findViewById(R.id.et);
btn = (Button) findViewById(R.id.button1);
//socket = null;
try {
socket = new SocketIO("http://10.0.2.2:8000");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
socket.connect(new IOCallback() {
@Override
public void on(String event, IOAcknowledge ack, Object... args) {
if ("echoback".equals(event) && args.length > 0) {
tview.setText(""+args[0]);
Log.e("received",""+args[0]);
}
}
@Override
public void onMessage(JSONObject json, IOAcknowledge ack) {}
@Override
public void onMessage(String data, IOAcknowledge ack) {}
@Override
public void onError(SocketIOException socketIOException) {
socketIOException.printStackTrace();}
@Override
public void onDisconnect() {}
@Override
public void onConnect() {}
});
///
socket.emit("echo", "hello");
btn.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
k=tt.getText().toString();
socket.emit("echo", k);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
Errorlog at server end
debug - client authorized
info - handshake authorized kaHbMG-lFmuFtvkFGY2W
debug - setting request GET /socket.io/1/websocket/kaHbMG-lFmuFtvkFGY2W
debug - set heartbeat interval for client kaHbMG-lFmuFtvkFGY2W
debug - client authorized for
debug - websocket writing 1::
debug - websocket writing 5:::{"name":"echoback","args":["hello"]}
debug - emitting heartbeat for client kaHbMG-lFmuFtvkFGY2W
debug - websocket writing 2::
debug - set heartbeat timeout for client kaHbMG-lFmuFtvkFGY2W
debug - got heartbeat packet
debug - cleared heartbeat timeout for client kaHbMG-lFmuFtvkFGY2W
debug - set heartbeat interval for client kaHbMG-lFmuFtvkFGY2W
debug - websocket writing 5:::{"name":"echoback","args":["this is textbox
input text"]}
info - transport end (undefined)
debug - set close timeout for client kaHbMG-lFmuFtvkFGY2W
debug - cleared close timeout for client kaHbMG-lFmuFtvkFGY2W
debug - cleared heartbeat interval for client kaHbMG-lFmuFtvkFGY2W
debug - discarding transport