Thursday, 15 April 2010

javascript - Node-Mysql database query + res.json far too slow -



javascript - Node-Mysql database query + res.json far too slow -

i learning node.

using express , node-mysql, able query mysql database , homecoming result client json.

however, far slow. simple query limit of 100 taking 6 seconds response.

according logger, db query takes 8 ms run - not think node-mysql problem.

but other thing doing passing resultset response object converted json.

here code, roughly:

route:

app.get( "/exercises", function( req, res ){ exercises.get( req.query, function( result ){ res.json( result ); }); });

model:

module.exports.get = function( params, cb ){ var sql = "select * exercises limit 100"; db.do( sql, function( result ){ var response = {}; response.data = result[ 0 ]; response.meta = result[ 1 ][ 0 ]; cb( response ); }); };

db:

module.exports.do = function( sql, vals, cb ){ var selectstart = +new date(); pool.acquire(function( err, db ){ db.query( sql, vals, function( err, result ) { cb( result ); console.log( "query execuction: %d ms", +new date() - selectstart ); pool.release( db ); }); }); };

does know doing wrong / why taking long send resultset client?

thanks (in advance) help.

i'm not familiar pool, , unfortunately can't comment yet. 1 thing noticed calling db.do 2 arguments, while takes three. should raise 'undefined not function' when seek callback.

javascript node.js node-mysql

jquery - Grabbing, Resizing, and Displaying Image from JSON -



jquery - Grabbing, Resizing, and Displaying Image from JSON -

basically, i'm trying following:

a user enters id asset on our system the id submitted part of api phone call returns json field called "videostillurl", contains url thumbnail image. resize thumbnail image existing size smaller that, if right clicks , saves hard drive, resized version , not original.

i'm not sure if possible... can bits , pieces of it, haven't been able set , thought i'd see if had insight.

below format of json returning. i'm having hardest time figuring out how load image url videostillurl item, because url has slashes in it.

{"name":"test item","videostillurl":"http:\/\/brightcove.vo.llnwd.net\/d21\/unsecured\/media\/1547387903001\/1547387903001_2146991932001_vs-5112b14ee4b0a4075c1c8334-1592194027001.jpg?pubid=1547387903001","thumbnailurl":"http:\/\/brightcove.vo.llnwd.net\/d21\/unsecured\/media\/1547387903001\/1547387903001_2146991933001_th-5112b14ee4b0a4075c1c8334-1592194027001.jpg?pubid=1547387903001"}

any help appreciated!

extra slashes shouldn't issue escaped.

let you're doing mockup:

$(document).ready(function() { ... ajaxsuccesscallhere(data) { var image = $("<img/>"); $(image).attr('src', data.thumbnailurl) $(document.body).append(image); } ... });

what find impossible do, in you're trying achieve, making save videostillurl when right clicking on image alone. how i'd wrap <a href='[videostillurl]'> tag around image - right clicking, , picking "save source" save original image , not thumbnail

jquery

Java MySQL calling commit() on a large EntityTransaction object failed -



Java MySQL calling commit() on a large EntityTransaction object failed -

i have big javax.persistence.entitytransaction object, ent, when called method commit() on object (to insert new record (mysql) table: ent.commit();

i got quere error (please see below). think problem relates size of entitytransaction object, because smaller size (4k, 5m, 9m) calls succeeds new records inserted table. size of entitytransaction object caused failure 15m, not big (i guess) because utilize longblob columns.

any help, pointer or advice highly appreciated.

please help!

thanks,

tri

================================== code:

public static boolean inserttransaction(transaction tran) { em.gettransaction().begin(); if (!em.contains(tran)) { system.out.println("dbmanager.inserttransaction persist"); em.persist(tran); system.out.println("dbmanager.inserttransaction persist returned"); } else { system.out.println("dbmanager.inserttransaction merge"); em.merge(tran); } system.out.println("dbmanager.inserttransaction commit"); em.gettransaction().commit();////>>>>>>>>>>>>>failure happened here big object system.out.println("dbmanager.inserttransaction commit returned"); homecoming true; }

================================== output:

dbmanager.inserttransaction commit [el warning]: 2013-02-07 16:53:08.947--unitofwork(13583728)--exception [eclipselink-4002] (eclipse persistence services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.databaseexception internal exception: com.mysql.jdbc.exceptions.jdbc4.communicationsexception: communications link failure exception in thread "awt-eventqueue-0" java.lang.nullpointerexception lastly packet received server 234 milliseconds ago. lastly packet sent server 234 milliseconds ago. error code: 0 call: insert transaction_tbl (tnc, dest, rtcn, src, status, time_stamp, tran_file, tran_file_size, tran_file_type, ttype) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) bind => [10 parameters bound] query: insertobjectquery(com.cmbios.db.client.transactiontbl[ tnc=358cph8ltl ]) [el warning]: 2013-02-07 16:53:08.95--clientsession(10091188)--exception [eclipselink-4002] (eclipse persistence services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.databaseexception internal exception: com.mysql.jdbc.exceptions.jdbc4.mysqlnontransientconnectionexception: no operations allowed after connection closed.connection implicitly closed driver. error code: 0 [el warning]: 2013-02-07 16:53:08.95--unitofwork(13583728)--java.lang.nullpointerexception @ org.eclipse.persistence.sessions.server.serversession.setcheckconnections(serversession.java:814) @ org.eclipse.persistence.sessions.server.connectionpool.releaseconnection(connectionpool.java:285) @ org.eclipse.persistence.sessions.server.serversession.releaseclientsession(serversession.java:762) @ org.eclipse.persistence.sessions.server.clientsession.release(clientsession.java:555) @ org.eclipse.persistence.internal.jpa.transaction.entitytransactionimpl.commitinternal(entitytransactionimpl.java:99) @ org.eclipse.persistence.internal.jpa.transaction.entitytransactionimpl.commit(entitytransactionimpl.java:63) @ com.cmbios.db.client.dbmanager.inserttransaction(dbmanager.java:137)

java mysql persistence commit large-data

ruby on rails - Easiest way to dump Heroku database for use in local seed.rb? -



ruby on rails - Easiest way to dump Heroku database for use in local seed.rb? -

i can dump heroku database $ heroku pgbackups:capture. also, this post shows there tools taking development database , dumping seed.rb.

i'm wondering if there easy way combine 2 processes, dumping info production heroku database local seeds.rb more realistic development testing.

if possible, what's cleanest way this?

update:

based on insightful reply db', may consider using pgsql locally. still interested, however, in seed.rb aspect of question if there way easily.

there couple ways accomplish such thing. @db' has outlined 1 of them - using the pg backups add-on export database. it's great options involves few (trivial) manual commands.

i recommend using pg:transfer heroku cli plugin transfer info in single step. under covers it's still much same thing happening using pg backups, it's packaged bit nicer , has useful defaults.

from app's directory, re-create production database locally (assuming local pg db), installing plugin , execute pg:transfer command.

$ heroku plugins:install https://github.com/ddollar/heroku-pg-transfer $ heroku pg:transfer

there couple options can set well. see my writeup more details.

hope helps! , yes, please utilize same database during development in production.

ruby-on-rails ruby-on-rails-3 heroku seeding database-dump

android - How to tell if a bluetooth device is connected? My code isn't working -



android - How to tell if a bluetooth device is connected? My code isn't working -

i trying hear bluetooth connection/disconnection events determine if there bluetooth device connected. i'm trying way app run on older android versions.

i registered receiver in manifest such:

<receiver android:name=".bluetoothreceiver"> <intent-filter> <action android:name="android.bluetooth.device.action.acl_connected" /> </intent-filter> </receiver>

and in bluetoothreceiver class have

public class bluetoothreceiver extends broadcastreceiver{ public final static string tag = "bluetoothreciever"; public void onreceive(context context, intent intent) { log.d(tag, "bluetooth intent recieved"); final bluetoothdevice device = intent.getparcelableextra(bluetoothdevice.extra_device); string action = intent.getaction(); if (bluetoothdevice.action_acl_connected.equalsignorecase(action)) { log.d(tag, "connected " + device.getname()); } if (bluetoothdevice.action_acl_disconnected.equalsignorecase(action)) { log.d(tag, "disconnected " + device.getname()); } }}

but when connecting , disconnecting bluetooth, nil happens. doing wrong?

you have manipulate modify_audio_settings finger if bluetooth headset connected. 1 time you've defined intent, , configure manifest correctly should work. headphone jack, can applied bluetooth if utilize above mentioned.

here 2 sites may help explain in more detail:

http://www.grokkingandroid.com/android-tutorial-broadcastreceiver/ http://www.vogella.com/articles/androidbroadcastreceiver/article.html

you have define intent; otherwise won't access scheme function. broadcast receiver; alert application of changes you'd hear for.

every receiver needs subclassed; must include onreceive(). implement onreceive() you'll need create method include 2 items: context & intent.

more service ideal; you'll create service , define context through it. in context; you'll define intent.

an example:

context.startservice (new intent(context, yourservice.class));

very basic example. however; particular goal utilize system-wide broadcast. want application notified of intent.action_headset_plug.

how subscribe through manifest:

<receiver android:name="audiojackreceiver" android:enabled="true" android:exported="true" > <intent-filter> <action android:name="android.intent.action.headset_plug" /> </intent-filter> </receiver>

or can define through application; but. particular request; require user permissions if intend observe bluetooth modify_audio_settings.

update:

i misread question, thought trying find bluetooth headsets; not bluetooth paired.

over on question; explain how check paired bluetooth devices.

import bluetooth package.

import android.bluetooth.*;

set permission.

<uses-permission android:name="android.permission.bluetooth" />

access bluetooth adapter:

bluetoothadapter bluetooth = bluetoothadapter.getdefaultadapter();

run check connection not null.

if (bluetooth != null) { // something. }

make sure enabled:

if (bluetooth.isenabled()) { // enabled, work bluetooth } else { // not enabled else. }

display bluetooth state bluetoothadapter.getstate()

by default turned off; you'll have enable it.

string state = bluetooth.getstate(); status = devicename + " : " + devicelocation + " : " + devicestate;

android android-intent

r - Scoping in custom lattice functions (group argument) -



r - Scoping in custom lattice functions (group argument) -

please consider function:

tf <- function(formula = null, info = null, groups = null) { grv <- eval(substitute(groups), data, environment(formula)) # values grn <- as.character(match.call()$groups) # name gr <- match.call()$groups # unquoted name p <- xyplot(formula, data, # draws info not in groups # seek these options: # p <- xyplot(formula, data, groups, # can't find 'cat2' # p <- xyplot(formula, data, groups = data[,grn], # can't fine grn # p <- xyplot(formula, data, groups = grv, # can't find grv panel = function(x, y) { panel.stripplot(x, y, jitter.data = true, pch = 20) } ) p }

which can run with:

tf(formula = mpg~vs, groups = am, info = mtcars)

what doing wrong in passing groups argument xyplot - why can't found? can't figure out how wants group information. thanks.

update:

@agstudy's reply helpful, if add together panel function in original example, groups still not recognized (no grouping, no error occurs either):

tf <- function(formula = null, info = null, groups = null) { ll <- as.list(match.call(expand.dots = false)[-1]) p <- xyplot(as.formula(ll$formula), info = eval(ll$data), groups = eval(ll$groups), panel = function(x, y) { panel.stripplot(x, y, jitter.data = true, pch = 20) } ) p }

something still missing... thanks.

you can utilize eval here since match.call returns symbols.

tf <- function(formula = null, info = null, groups = null) { ll <- as.list(match.call(expand.dots = false)[-1]) p <- xyplot(as.formula(ll$formula), info = eval(ll$data), groups = eval(ll$groups), panel = function(x, y,...) { ## here ... contains groups , subscripts ## here can transform x or y before giving them jitter panel.stripplot(x, y, jitter.data = true, pch = 20,...) } ) p }

r lattice

sql - Referring to a table by variable -



sql - Referring to a table by variable -

i'm sure pretty basic, how set insert statement using variable table name?

for example, have number of input files, configured identically (input1, input2, input3, ...) going insert or merge statement.

i want either loop, working through input files, or phone call insert statement function

insert [outputfile] select i.* [<input variable>] left bring together [outputfile] op on concat(i.field1, i.field6) = concat(op.field1, op.field6) op.field1 null print 'number of rows added ' + cast(@@rowcount char(6));

i'll using merge statements, assume process same.

how set insert statement using variable table name?

you don't, not straight sql. table names , column names cannot variables.

you can accomplish using dynamic sql, have careful not introduce sql injection.

the curse , blessings of dynamic sql fantastic in depth article discussing dynamic sql.

sql sql-server tsql sql-server-2012-express