Posts

Showing posts from June, 2014

java - How to take inceremental backup in lucene? -

i want perform backup , restore process in project. used snapshotdeletionpolicy take hot backup of indexes location. is possible take incremental backup in lucene? (for e.g: if added 100 documents in lucene how should update indexes during backup @ backup location) if so, how should achieve this? snapshotdeletionpolicy me this? by using replicationhandler can update index in 10sec in master copy , backup also, once check url http://wiki.apache.org/solr/solrreplication

php - Securing REST API using HTTP_X_REQUESTED_WITH and SESSION IDS -

i'm building api website , want api accessible own website. way i've built call php file using ajax: <?php session_start(); ?> <script> $.ajax({ type: "get", datatype: "json", url: "secureapi.php", data: "test="+document.cookie.substring(document.cookie.lastindexof('phpsessid')).replace(/phpsessid=/gi, '') + "userid=123", success: function(response){ console.log(response); } }); </script> in php file check if it's called xmlhttprequest , session_id correct: <?php session_start(); if(strtolower($_server['http_x_requested_with']) == 'xmlhttprequest' , $_post['test'] == session_id()){ //query database , return json } ?> is secure enough or can session_id curl or something?

java - Android SQLite Database Version, changed structure now cannot view DB -

my sqlite database appears entering entries fine cannot pull them view them, everytime load activity app crashes, changing database version throws sql exception , force closes app also. below class sql handled: package com.uhi.fatfighter; import android.content.contentvalues; import android.content.context; import android.database.cursor; import android.database.sqlexception; import android.database.sqlite.sqlitedatabase; import android.database.sqlite.sqliteopenhelper; public class stats { public static final string key_rowid = "_id"; public static final string key_weight = "weight"; public static final string key_waist = "waist"; public static final string key_chest = "chest"; public static final string key_legs = "legs"; public static final string key_arms = "arms"; private static final string database_name = "statsdb"; private static final string database_table = "...

objective c - Should a BOOL ivar be a pointer to allow another class to set it? -

my class has bool property needs set class, trying use pointer. i'm declaring property this: @interface someclass : superclass { bool *_shared; } @property(nonatomic) bool *shared; is correct way this? i'd set , access value this: *self.shared = yes; or proper way set retainable property? no, not want send pointer instance variable other class can set instance variable. doing fragile , breaks encapsulation. awful design pattern. it unnecessary. if instance can "send pointer" instance b, instance can send reference instance b. there, instance b can [instancea setshared:yes]; . @interface b:uiviewcontroller @property(strong) *controllera; @end @interface a:uiviewcontroller @property bool dogdoorenabled; @end @implementation ... - (void) dosomething { b *b = .... instance of b ...; [b setcontrollera: self]; } @end @implementation b ... - (void) dosomethingelse { bool ischeeseonfire = ... calculate whether cheese burnin...

python - Displaying ASCII-art in TKinter -

Image
i trying develop offline version of candy box (solely personal use only) using tkinter , ascii art won't display on tkinter canvas. this way i'd displayed: """ .---. | '.| __ | ___.--' ) _.-'_` _%%%_/ .-'%%% a: %%% %% l %%_ _%\'-' | /-.__ .-' / )--' #/ '\ /' / /---'( : \ / | /( /|##| \ | / ||# | / | /| \ \ | ||##| \/ | | _| | ||: | o |#| | / | | || / |:/ / |/ | || | o / / / | \| | |. / / \ /|##| o |.| / \/ \::|/\_ / ---'| """) and way displayed (i've attempted changing font used in idle (courier, 10), because seemed display correctly, didn't seem help. using following code, ended looking like: self.merchantshow = tk.label(self, font=self.fontused, text= """ .---. | '.| __ | ___.--' ) _.-'_` _%%%_/ ...

How to properly sanitize URL as a link in PHP? -

i have site users can share link homepage such http://example.com/user . currently, using php function filter_var($_post['url'], filter_validate_url) validate url before adding database using prepared statement. however, realize php filter function accepts input such http://example.com/<script>alert('xss');</script> used cross-site scripting. counter that, use htmlspecialchars on url within <a> tag , rawurlencode on href attribute of tag. but rawurlencode causes / in url converted %2f , makes url unrecognizable. thinking of doing preg_replace %2f / . way sanitize url display link? this outdated : i using php function filter_var($_post['url'], filter_validate_url) validate url before adding database using prepared statement. instead of filter_validate_url you can use following trick : $url = "your url" $validation = "/^(http|https|ftp):\/\/([a-z0-9][a-z0-9_-]*(?:\.[a-z0-9][a-z0-9_-]*)+):?...

java - Hibernate get SQL query.list() : ArrayIndexOutOfBoundsException 0 -

@suppresswarnings("unchecked") public list<object[]> findadcampstatistics(long adcampid, string startdate, string enddate, float costperclick, string orderstatus){ string sqlstr = "select adcamp_id, alternative_ids, click, ordercount, conversion, ((100*ordercount)/click) conversionrate, (click * " + (costperclick != 0?costperclick:0) + ") cost " + "from ( " + "select adcamp_id, alternative_ids, count(*) click, " + "sum(( " + "select count(*) "+ "from nc_order, nc_cart "+ "where nc_order.cart_id = nc_cart.id "+ "and nc_cart.adcamp_click_id = nc_adcamp_click.id "+ (orderstatus != ""? "and nc_order.order_status = '"+ orderstatus +"' " : " ")+ ...

java - Column cannot be null could not insert -

dear developers. i'm going ask question think hard solve me because don't know basic why answer, mean?? let's see. associations in jboss documentations did not comprehensive answer: why should use jointable instead of foreign key , not understand how mappings works, mean this? know association manytomany or manytoone etc. , aims are, but how work's , collaborate each other don't need answer bi-directional or unidirectional or jointable or associations, have link can find full info 2 questions: 1) why should use jointable instead of foreign key ???? 2) how entity work's , collaborate each other (without explanations manytomany etc. associations , bi or unidirectional associations are)??? so, have piece of code stuck because misunderstanding, i'm trying insert data i'm mysql database: name_institution , type_name(type of institution):* my entity class: @entity @table(name="institution") public cla...

javascript - How to detect collisions between fast moving objects -

generally detect collisions in canvas games use like: function collides(a, b) { return a.x < b.x + b.width && a.x + a.width > b.x && a.y < b.y + b.height && a.y + a.height > b.y; } but detects collisions if objects touching @ time frame processed. if have sprite speed (in pixels/frame) greater width of obstacle in path, pass through obstacle without collision being detected. how go checking what's in between sprite , destination? that's hard problem , high-quality solution box 2d library useful. a quick , dirty solution (that gives false positives on diagonally moving objects) — check collision between bounding boxes cover position of object in current and previous frame. instead of a.x use min(a.x, a.x - a.velocity_x) , instead of a.x + a.width use max(a.x + a.width, a.x + a.width - a.velocity_x) , etc. if object moving fast small (a bullet), test collision between line (from origin origin + velo...

html - Shopify theme top menu issue, can't get it to fit on one line -

here's site: http://sawsafetystore-com.myshopify.com/ you can see menu @ top (home, chain saw safety, etc.). no matter how tinker css, cannot fit on 1 line. i've changed padding, font-size, etc. though can see should fit on 1 line now, or @ least 1 more item, can't to. is there tag or property missing somewhere? i've tinkered element #main-nav li a element's font-size, margins, padding, etc. thanks. use css c6-screen.css --> line number 94 #main-nav { font-size: 12px; width: 100%; }

Extract text from PDF document based on position c++ -

Image
i trying extract text pdf document based on it's coordinates, have came across 2 notions in adobe pdf reference (chap. 5.3): text positioning operators text showing operators for interested in td & tm positioning operators, while using td have tx , ty , relative start of current line specified in pdf document: tx ty td , have used method extract text tx , ty coordinates. problem don't know how extract text pdf based on position, while supplying tx , ty . a b c d e f tm this 'formula for' tm usage. a-f values represent ? input tm: bt /f1 8.88 tf 0 0 0 rg 0.9998 0 0 1 401.52 448.08 tm [<0014>-11<0015>-11<0013>-11<000f>-19<0014>-11<0019>] tj et why each group of 4 have leading 00 ? in hex? should convert hex int , corresponding character? this input td: bt 43.20 421.90 td 0 tw /c001 10.00 tf 0.00 tw <blablablatextinhexthaticanprocess>tj et this clearer, coordinates clearer. how extract text tm p...

java - Adding cssErrorClass to a div -

i using twitter bootstrap spring webapp. i added validation , want add error class div.controlgroup if validation fails. part of view: <div class="control-group"> <form:label cssclass="control-label" path="subject" csserrorclass="inputerror">subject</form:label> <div class="controls"> <form:input path="subject"/> <span class="help-block"><form:errors path="subject" /></span> </div> </div> part of controller: @requestmapping(value="/add", method = requestmethod.post) public string addtask(@modelattribute("task") task task, bindingresult result) { if (result.haserrors()) { return "tasks"; } taskrepository.save(task); return "redirect:/"; } i able add error class div using <spring:bind> <spring:bind path="task.duedate...

vb.net - How to insert/run a Windows command (ping, getmac, vmic, etc) from VB .net - Visual Studio 2012 -

i'm new here , more beginner in coding. want, "on side" project, create tool coded in vb helpdesk team. type computer id in text field , have several buttons below performs windows command ping, getmac, wmic, etc etc.. how possible load or integrate windows prompt or vb call dll perform windows commands. there built-in tool in visual studio 12 that? thought "console" argument i'm way n00b in coding have working. any appreciated! for creating forms read msdn article: http://msdn.microsoft.com/en-us/library/vstudio/dd492132.aspx for executing processes use process.start . if need read process output, see process.start: how output? a tutorial start : http://www.dotnetperls.com/process-start-vbnet

3d - Algorithm to interpolate any view from individual view mapped on a sphere -

Image
i'm trying create graphics engine show point cloud data (in first person now). idea precalculate individual views different points in space viewing , mapping them sphere. possible interpolate data determine view point on space? i apologise english , poor explanation, i'm can't figure out way explain. if don't understand question i'll happy reformulate if it's needed. edit: i'll try explain example image 1: image 2: in these images can see 2 different views of pumpkin (imagine have sphere map of 360 view in both cases). in first case have far view of pumpkin , can see surroundings of , imagine have chest right behind character (we'd have detailed view of chest if looked behind). so, first view: surroundings , low detail image of pumpkin , detail of chest without surroundings. in second view have exact opposite: detailed view of pumpkin , non detailed general view of chest (still behind us). the idea combine data both views calculate ...

GWT: Help trying to format a composite widget. Tried CSS stuff and it has no effect -

Image
consider following widget: import com.google.gwt.user.client.ui.composite; import com.google.gwt.user.client.ui.label; import com.google.gwt.user.client.ui.listbox; import com.google.gwt.user.client.ui.textbox; import com.google.gwt.user.client.ui.hashorizontalalignment; import com.google.gwt.user.client.ui.hasverticalalignment; import com.google.gwt.user.client.ui.flextable; public class selectorpanel extends composite { private final flextable flextable = new flextable(); private final label lbltitle = new label("##title"); private final listbox listbox = new listbox(); private final label lblsearchtext = new label( "##searchtext" ); private final textbox tbsearch = new textbox(); public selectorpanel() { listbox.setvisibleitemcount( 10 ); flextable.setstylename("searchpanel"); flextable.setborderwidth(0); initwidget( flextable ); flextable.setsize("200px", "0px...

php - Image upload and delete to Amazon S3 -

i have uploaded image amazon s3 using site below : http://www.flynsarmy.com/2011/03/upload-to-amazon-s3-with-uploadify/ now need delete (already uploaded) image s3 convert original image thumbnail , need upload both original , thumbnail image s3 these 2 things should client side above tutorial.. 1 please me find solution?

sql server - SQL Returning todays data only -

i need return data (todays) table. i'm using query job not fast like. current query where (calldetail.dnis='456456') , calldetail.connecteddatetimegmt > cast(floor(cast(getdate() float))as datetime) another query use returns past weeks worth of data in matter of seconds. where (calldetail.localname='name') , (calldetail.connecteddate between dateadd(wk,-1,getdate()) , getdate()) is there more effective query can use return data today? instead of casting 2 times return date part getdate() slows down query where (calldetail.dnis='456456') , calldetail.connecteddatetimegmt > cast(floor(cast(getdate() float))as datetime) use faster way return date part getdate() where (calldetail.dnis='456456') , calldetail.connecteddatetimegmt > dateadd(dd, 0, datediff(dd, 0, getdate()))

java - Nothing happens when button is clicked -

i'm writing program in java i'm using jtabbedpane. each tab associated different panel labels, textfields , button. have used gridbaglayout in panels. have added actionlistener button, when click nothing happens. edit: have other buttons outside jtabbedpane works fine. i can see nothing happening because this: public void actionperformed( actionevent e ) { if ( e.getsource() == button ) { system.out.println("blablabla"); } and nothing printed out. is there common problems using buttons , gridbaglayout/jtabbedpane? edit sscce import java.awt.*; import java.awt.event.actionevent; import java.awt.event.actionlistener; import java.awt.event.keyevent; import java.awt.event.windowadapter; import java.awt.event.windowevent; import javax.swing.*; public class hjelp extends jframe { private flowlayout layout; private jbutton button1; private jbutton button2; private jpanel menu, frontpage; private jpanel present, pr...

javascript - How to add a delay between each getjson call? -

i calling getjson inside loop. code prints items doesnt ommit items not on sale! this part checks if item on sale or not: $.getjson('http://anyorigin.com/get?url=http://www.asite.com/itemtocheck.php='+ itemname + '/&callback=?', function(data){ var sitecontents = data.contents; var n=sitecontents.search("this item not on sale"); if(n=-1) { //alert("this item on sale. n:"+n); var sitecontents2 = "this item on sale:"+itemname; document.getelementbyid("mydiv").innerhtml += sitecontents2; }; i dont know problem if statement comes true if item not on sale! there way put delay between each call getjson inside "for loop"(very short delay getjson fetch data , have enough time filter it)? i not sure think maybe "for loop" calling getjson fast not giving enough time each item checked. tried doing this: settimeout(getjsonresult('pen...

Ruby detect if a column value has changed -

so have line: if self.company_changed? and works fine detects if company has changed on object. need know if database value has changed , not if value in memory has changed. tried this: if :company_changed? this seems work in debug mode when execute 1 line. if let run, fails in testing on infinite loop. my question can used in ruby check see if column value has changed. there excellent screencast on great ryan bates.

matlab - write data into the text output file -

i have input.dat that: 1 1 1 2 3 10 17 16 15 8 9 2 1 3 4 5 12 19 18 17 10 11 3 1 5 6 7 4 21 20 19 12 13 4 1 15 16 17 24 31 30 29 22 23 1st column : numel 2nd column : matno 3rd-12st column : lnods i wrote follow; fprintf(fid6,'n pro points \n'); matno=zeros(4,1); lnods=zeros(4,9); ielem=1:nelem numel(ielem,:)=fscanf(fid5, '%d', 1); matno(ielem,:)=fscanf(fid5, '%d', 1); lnods(ielem,:)=fscanf(fid5, '%d %d %d %d %d %d %d %d %d',[9,1]); end fprintf(fid6, '%-2d %-2d %-2d %-2d %-2d %-2d %-2d %-2d %-2d %-2d %- 2d\n',numel,matno,lnods); i expect: n pro    points 1  1    1 2 3 10 17 16 15 8 9 2  1    3 4 5 12 19 18 17 10 11 3  1    5 6 7 4 21 20 19 12 13 4  1    15 16 17 24 31 30 29 22 23 but n pro    points 1  2    3 4 1 1 1 1 1 3 5 15  2    4...

android - SharedPreferences setChecked crash -

i'm trying switch toggle button in preference screen false once toggle turned off. here when time flipped want turn off name. blows up. see i'm doing wrong? import android.content.context; import android.content.sharedpreferences; import android.content.sharedpreferences.onsharedpreferencechangelistener; import android.os.bundle; import android.preference.preferenceactivity; import android.widget.toast; import android.widget.togglebutton; public class usersettingactivity extends preferenceactivity implements onsharedpreferencechangelistener{ sharedpreferences mpreferences; boolean frequency; @suppresswarnings("deprecation") @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); addpreferencesfromresource(r.xml.settings); } @override public void onsharedpreferencechanged(sharedpreferences sharedpreferences, string key) { boolean mbool = false; if (key.e...

java - Consuming Restful WCF Service in Android -

i not sure causing request not execute. trying call wcf restful service in android, , receive error message "request error". looking @ example, don't see reason why example should not work. see below: here .net service: [servicecontract] public interface isampleservice { [operationcontract] [webinvoke( method="post", uritemplate="/login", bodystyle= webmessagebodystyle.wrappedrequest, responseformat = webmessageformat.json, requestformat = webmessageformat.json)] string login(string value); } public class sampleservice : isampleservice { public string login(string value) { string t = ""; try { //foreach (string s in value) //{ // t = s; //} return t; } catch (exception e) { return e.tostring(); ...

javascript - Windows Mobile 6 and Its Screen Pixel Ratio -

wazzzup! i'm developing screens in html , css web app, , must run in windows mobile 6. until now, nothing special. requiring images change depending on pixel ratio of device, found hard do, since device not support neither media queries nor javascript (window.devicepixelratio). asking same technique linux (opera mobile browser), , palm os. in whole knowledge, never concerned such platforms capable of having high-quality display pixel ratio bigger 1! that's weird... am losing something, or there way detect pixel ratio of these devices adapt images? thank all!

Python:Multi-thread not works as epected -

i want start project learn python, , chose write simple web proxy. in case, thread seems null request, , python rasie exception: first_line: http://racket-lang.org/ http/1.1 connect to: racket-lang.org 80 first_line: exception in thread thread-2: traceback (most recent call last): file "c:\python27\lib\threading.py", line 551, in __bootstrap_inner self.run() file "c:\python27\lib\threading.py", line 504, in run self.__target(*self.__args, **self.__kwargs) file "fakespider.py", line 37, in proxy url = first_line.split(' ')[1] indexerror: list index out of range first_line: first_line: http://racket-lang.org/plt.css http/1.1get http://racket-lang.org/more.css http/1.1 connect to:connect to: racket-lang.orgracket-lang.org 8080 my code simple. don't know what's going on, appreciated:) from threading import thread time import time, sleep import socket import sys recv_buffer = 8192 debug = true def recv_time...