Posts

Showing posts from July, 2015

php - Html button action only on first click -

i can set action on click html button. need set action on first click. there way this? button radio in form. javascript maybe? what's important - radio button still might changed. action has done once. this doesn't work function myfunction(i){ oform = document.forms["myform"]; if(oform.elements["field"+i].checked) alert("action done earlier"); else action } the cleanest solution use removeeventlistener to... remove event listener : var mybutton = document.getelementbyid('someid'); var handler = function(){ // dosomething mybutton.removeeventlistener('click',handler); } mybutton.addeventlistener('click', handler); (to make cleaner, wrap in iife, in example below) demonstration

.net - Server.MapPath returning a path with a folder that doesn’t exists -

i have following code: var dir = @"content\posts\" + yr + @"\" + mnth + @"\"; var = path.combine(dir, dy.tostring() + pid.tostring() + ".txt"); //a contains: "content\\posts\\2013\\8\\file01.txt" stts = obj.notifymail(title, writeup, "author@gmail.com", a); and in notifymail function have this: public bool notifymail(string subject, string body, string toadd, string filepath) { … string attachments = httpcontext.current.server.mappath(filepath); //now here attachments contains: "g:\\program files\\derby\\work\\development\\proj\\proj\\`post`\\content\\posts\\2013\\8\\file01.txt" var attchmnts = new linkedresource(attachments); attchmnts.contentid = "attchmnts"; … } now problem in notifymail when attachments retrieving physical file path through server.mappath returning path invalid folder included in i.e. post folder doesn't exists anywhere, not i

layout - Yii is not rendering theme -

i'm having strange issue yii , theme. set in config/main.php like: 'theme'=>'themename', as usual. when try render view, rendered is, without layout, if called: $this->renderpartial i double check don't call renderpartial, themes seem equal others theme i've done. can issue about? thank's help, i'm going out of mind on this... here structure , syntax should have check -yiiroot -!-!protected -!-!-!controllers -!-!-!-!testcontroller.php -!-!themes -!-!-!themename (it 1 have set on config file) -!-!-!-!views -!-!-!-!-!layouts -!-!-!-!-!-!main.php // default if public $layout has not been overwriten or layout file has been set not found -!-!-!-!-!test -!-!-!-!-!-!viewname.php on controller testcontroller public $layout main default or overwritten there in actionindex set $this->render('viewname'); if rendered page method renderpartial() directly in controller , not layout template sure re

android - Programatically setColor,font to Textviews -

i have created list view 3 items in each list view item using 2 seperate .'xml's. 1)list_view.xml <listview xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/listview"> </listview> 2)list_item.xml <?xml version="1.0" encoding="utf-8"?> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancelarge" android:text="text here" android:id="@+id/textview" android:layout_aligntop="@+id/textview" android:layout_alignleft="@+id/textview" android:layout_centervertical="true"/> <textview android:layout_width="wrap_content" android:l

How to set Borders graphics G JAVA -

i trying make game there few borders on map, being generated text document. text document has 1s , 0s ther 1 shows wall. how make character stops infront of wall my code: main class: public class javagame { public static void main(string[] args) { final platno p = new platno(); final jframe okno = new jframe("test"); mapa map = new mapa(); okno.setresizable(false); okno.setdefaultcloseoperation(jframe.exit_on_close); okno.setsize(800, 600); okno.setvisible(true); map.nacti(); okno.add(p); p.mapa = map; okno.addkeylistener(new keylistener() { @override public void keytyped(keyevent e) { } @override public void keypressed(keyevent e) { int kod = e.getkeycode(); if(kod == keyevent.vk_left) { platno.x -= 3; p.repaint(); } else if(kod == keyevent.vk_right) { platno.x +=3;

perl - function to print document in json format (mongodb) -

hi i'm using perl query mongodb, when cursor how can print documents in json format { "_id" : objectid("51fdbfefb12a69cd35000502"), "biography" : "colombian pop singer, born on february 2, 1977 colombian mother of spanish-italian descent , american father of lebanese-italian descent. shakira known high iq , fluent in spanish, english, italian , portuguese.\r\rwriting songs , belly-dancing since childhood, first album released when mere 14 years old. other spanish-language albums followed, each faring better predecessor, not until 2001 achieved world-wide breakthrough english-language \"laundry service\" album.\r", "imguri" : "http://api.discogs.com/image/a-5530-1218936486.jpeg", "index" : "shakira", "name" : "shakira", "ready" : "yes", "requests" : "0"} i dont see function in mongodb module migh try this run_command({printjs

swing - java JPanel setSize and setLocation -

hey second post don't mad @ me i'm having issues jpanel in java. trying set size , location won't work, have tried repaint(); not work. help? here's code: package test.test.test; import java.awt.color; import java.awt.flowlayout; import java.awt.textfield; import javax.swing.jbutton; import javax.swing.jframe; import javax.swing.jpanel; public class test extends jframe { jpanel colorpanel = new jpanel(); public display(){ super("jpanel test"); setlayout(new flowlayout()); add(colorpanel); colorpanel.setbackground(color.cyan); colorpanel.setsize(300, 300); repaint(); } } for benefit of reading question later, here's short, self contained, correct example of defining jpanel background color. almost time, should let swing component layout manager determine size of swing components. in case, define preferred size of jpanel because jpanel not contain other swing components. the default layout manager of

regex - Regular Expression to split by VbCrLf + ignores VbCrLf within double quotes. VB.NET -

Image
still trying understand regex. need split string on vbcrlf, not when inside double quotes. so string built using stringbuilder below: "abcdef" "this is sampletext" so io stream , parse it. in io stream, single string parse "abcdef" vbcrlf "this vbcrlf sampletext" now convert iostream string , want split this. required output is "abcdef" "this sampletext" (if possible explain me expression, can understand , modify per needs) thank you description i think easier use regex matching routine output each line. regex will: assumes \r\n equivalent vbcrlf matches entire lines , text trims delimiting \r\n mimic how split command drop delimiter keeps quoted strings if quoted string contains \r\n ^(?:[^"\r\n]|"[^"]*")*(?=\r\n|\z) example live demo of regex sample text line 1 line 2 line 3 "this line 3a line 3b line 3c" , more text line 4 line 5 code vb

javascript - How to characterize z-indexing for the DOM? (2) -

i've been bit care-less choosing z-indexes in css. i'd traverse dom , report z-indexes respective id's. for example: id z-index header 10 main 0 menu 20 the end result object keys element id , value z-index. 1 might call z_obj // pseudo code var z_obj = {el_id: el_zindex}; getting z-index each element ( el ) should easy using filter , code below: // attr attribute data = _.filter(el.attributes, function (attr) { return (/^z-index/).test(atttr.name); }); but how traverse dom z-indexes , store in object? i'd w/ out libraries, , using code above if possible. this debug tool in general. you can elements getelementsbytagname("*") , iterate on collection for loop, , use window.getcomputedstyle(node) . there, can retrieve z-index . here's example: var zobj, allels, i, j, cur, style, zindex; zobj = {}; allels = document.body.getelementsbytagname("*"); (i = 0, j = allels.length;

SQL server: Order by multiple columns incorrect syntax -

i'm using sql server 2008. select resulttable.ordernumber, resulttable.projectid, resulttable.batchid, resulttable.customerid, resulttable.city, resulttable.street, resulttable.postalcode, resulttable.country, resulttable.createddate, resulttable.name, count(*) over() orderscount, row_number() on (order case when @sortby = 'ordernumber' resulttable.ordernumber end, case when @sortby = 'projectid' resulttable.projectid end, case when @sortby = 'address' resulttable.country, resulttable.city, resulttable.street, resulttable.postalcode end, case when @sortby = 'createddate' resulttable.createddate e

http - AngularJS 1.1.5 $resource.get is not creating XHR request from setTimeout -

i have asked question on google forum angularjs , haven't heard until now. can me understand going on here? i trying periodically refresh resource , doesn't seem working. have tracked until fact promise has been obtained $http service xhr request never created , fired when method invoked in settimeout. however, if same without settimeout seems working fine. working jsfiddle: http://jsfiddle.net/hponnu/z62qn/2/ window.root_module = angular.module("myapp", ['ngresource']); function maincontroller($scope, $resource) { $scope.buttonclick = function () { var res = $resource("http://www.google.com"); res.get({}, function (response) { alert("response"); }, function (err) { alert("error"); }); } } broken jsfiddle: http://jsfiddle.net/hponnu/h8aet/10/ window.root_module = angular.module("myapp", ['ngresource']); window.count = 0; function mainc

angularjs - Angular, ng-repeat to build other directives -

i'm building complex layout, takes json document , formats multiple rows, each row having more rows and/or combinations of rows/columns inside them. i'm new angular , trying grips directives. easy use simple things, become difficult once need more complicated. i guess i'm doing wrong way around, there way add name of directive (in example below, i've used ) , directive rendered on ng-repeat? maybe same way can use {{{html}}} instead of {{html}} inside of mustache partial render html , not text. as expected, example below writes name of directive dom. need angluar take name of directive, understand it, , render before before written. due complex layout of page need design, rendering many different directives, inside each other, 1 json document (which has been structured different rows , row / column combinations). example code renders name of directive page, gives idea of how i'd write solution problem... <div app-pag

mysql - SQL full outer join or Union -

i have 2 different tables. 1 article table , gallery table. gallery contains multiple images , there table named images (which not shown here). images in images table link gallery table foreign key gallery_id . now trying achieve is, in home page, need combined result of both articles , galleries. if article, thumbnail of article displayed , if gallery, last image gallery displayed. |article | |-----------| |id | |category_id| |title | |slug | |filename | |body | |created | |modified | |gallery| |-----------| |id | |category_id| |title | |slug | |body | |created | |modified | i using complex union query achieve it. how can sort results. possible use order by clause. can result achieved outer join ? sounds outer join not apply here because want results in 1 column. joins make data in 2 columns, unions make data 1 column. to sort can this select id , category_id , title

node.js - Mongo/Mongoose: cleanup orphaned refs -

suppose typical one-to-many relationship modeled using references suggested mongodb official documentation : var user = mongoose.schema({ }); var group = mongoose.schema({ user: [{ type: mongoose.schema.types.objectid, ref: 'user' }] }); let's assume care order, in users appear in group, array necessary. now, let's assume user has been deleted -- , groups have not been maintained $pull reason. if use mongoose's populate looks fine, garbage persists in array. is there way identify orphaned refs , remove them? maybe automatically -- cascade in relational world? what's best approach maintain referential integrity in mongo/mongoose? finally, what's efficient one? first, use remove hook on user model try maintain data integrity on ongoing basis: user.post('remove', pulluserfromgroups); keep integrity intact. can remove user every group single $pull operation. mongo analog cascade relational dbs. for after-the

sql - Remove the only single column from datatable and insert it into a generic list of strings c# -

here method public virtual list<string> getjobname(nullable<int> id, nullable<int> userid) { list<sqlparameter> parameters = new list<sqlparameter>(); var idparameter = id.hasvalue ? new sqlparameter("id", id) : new sqlparameter("id", typeof(int)); parameters.add(idparameter); var useridparameter = userid.hasvalue ? new sqlparameter("userid", userid) : new sqlparameter("userid", typeof(int)); parameters.add(useridparameter); table = executespdatatable("getjobname", parameters, out list); // datafiller<string> j = new datafiller<string>(); // list<string> rows = j.fromdatatabletolist(table); } table holds 1 value, single job , want put single string list<string> , return. any help? if variable table string, , want return string list of str

c# - ADO.net Data Model Best Practice -

i've been working time ado.net data models (in asp.net). i'm not sure, use correctly. for example, have model, "sqlentities.edmx" , try simplify access. created class called "eh" (for entity helper), kinda looks this private static class eh { private static sqlentities _sql = new sqlentities(); public static list<user> users { { return _sql.users.tolist(); } } public static void save(this object o) { dbset entities = _sql.set(o.gettype()); entities.add(o); _sql.savechanges(); } public static void delete(this object o) { dbset entities = _sql.set(o.gettype()); entities.remove(o); _sql.savechanges(); } public static void update() { _sql.savechanges(); } } first tried use it, needed it, like: using(sqlentities sql = new sqlentities()) { user utemp = new user() { name = "foo" }; sql.users.add(utemp);

git - Compilation Error when building Giraph -

i trying build giraph. have following: java version "1.7.0_25", apache maven 3.0.4, hadoop 1.0.4. following instruction in page: https://cwiki.apache.org/confluence/display/giraph/quick+start+guide when run: mvn compile , following error: [info] scanning projects... [info] ------------------------------------------------------------------------ [info] reactor build order: [info] [info] apache giraph parent [info] apache giraph core [info] apache giraph examples [info] apache giraph accumulo i/o [info] apache giraph hbase i/o [info] apache giraph hcatalog i/o [info] apache giraph hive i/o [info] apache giraph rexster i/o [info] [info] ------------------------------------------------------------------------ [info] building apache giraph parent 1.1.0-snapshot [info] ------------------------------------------------------------------------ [info] [info] --- mavanagaiata:0.5.0:branch (git-commit) @ giraph-parent --- [info] [info] --- mavanagaiata:0.5.0:commit (git-commit) @

Converter .rrd to json -

i working on project have database in .rrd need , converts json, can create graphs jqueryplot. tried use following code in documentation not more, returns me following error. start time: unparsable time: toe. have idea can do? i googling this, , found blog post mentioning rrdtool xport --json , added in rrdtool 1.4.6. not want?

google maps - Android Update Current Location -

so here method getting user saved location , move camera location: private void updateplaces(){ locman = (locationmanager)getsystemservice(context.location_service); location lastloc = locman.getlastknownlocation(locationmanager.network_provider); double lat = lastloc.getlatitude(); double lng = lastloc.getlongitude(); latlng lastlatlng = new latlng(lat, lng); if(usermarker!=null) usermarker.remove(); usermarker = themap.addmarker(new markeroptions() .position(lastlatlng) .title("you here") .icon(bitmapdescriptorfactory.fromresource(usericon)) .snippet("your last recorded location")); themap.animatecamera(cameraupdatefactory.newlatlng(lastlatlng), 3000, null); } how can modify code in order new position once, compare , camera it? thank in advance. i don't understand question, if run method updateplaces() ones getlastknownlocation once , updates user marker once. please more expla

How do I add a border to my entire android app programmatically? -

i trying add 10 pixel border sides of app, breaks every time try add margin/padding. can give me clue need doing make happen? i've included code below. first post if have done wrong apologize in advance. import android.app.activity; import android.content.context; import android.os.bundle; import android.view.motionevent; import android.view.keyevent; import android.view.window; import android.view.windowmanager; import android.view.view; import android.view.viewgroup; import android.widget.textview; import android.widget.edittext; import android.text.editable; import android.widget.button; import android.widget.imageview; import android.widget.linearlayout; import android.widget.framelayout; import android.graphics.drawable.drawable; import android.content.res.configuration; import android.app.notification; import android.app.notificationmanager; import android.app.pendingintent; import android.content.intent; import android.view.view.onkeylistener; import android.view.me

servlets - Google App Engine : user login page -

if want require users logged in view page on web site, how achieve this? check user login status @ beginning of doget() in every servlet class , redirect log-in page? once user logs in, redirect original servlet? achieve same thing simple configuration if such thing exists? add tag web.xml file: <security-constraint> <web-resource-collection> <url-pattern>/*</url-pattern> </web-resource-collection> <auth-constraint> <role-name>*</role-name> </auth-constraint> </security-constraint> this require user authenticated in whatever role ( role-name ) access servlet ( url-pattern )

performance - Access 2007 user-defined function over join slow -

why query using user-defined function on query several joins including outer joins slow? reason function modify string sorts numerically. sorting string means 100 < 99 . function reformats 99 099 . so, 099 < 100 . lets other non-numeric values remain unchanged. the problem query uses function on query joins. takes 27 seconds return 100 rows. same query, function, on 1 table takes subsecond. sql-replacement query on query joins subsecond. query without function on query joins subsecond. primary table tbltests 517 rows. column function operates on text column fldpurity. tbltests fldtestsid autonumber fldpurity text. field size 50. indexed (duplicates ok). 0 length no. here function code. notice different inputs. public function sortablepercent(byval pvar variant) string '------------------------------------------------------------------ ' purpose: formats string may contain numbers or text values. ' string percent may contain % or + cha

c# - Requirements for client-server model over the internet -

for college project, hoping develop client/server model in c# allow client stream audio , video server. (android device, streaming pc) i understand using tcp sockets , ports, should able (eventually) achieve on internet using port forwarding on router. is possible without port forwarding? how i, say, have install app on pc in phone, , have them communicate? required so? i have long way go studies before attempt hoping guidance on involved. you need have static ip , given isp , deploy on iis or can use azure - guess project asp.net webapi has thhe capability stream data

android - Use precompiled drivers to build aosp -

i wanna build aosp samsung galaxy s advance. ste doesn't share driver's of our board. question posible use precompiled drivers (wich in samsung opensource package think? kernel source delivered samsung) compile aosp? you should able use pre-compiled drivers. building aosp of nexus devices requires downloading binary blobs , adding them source tree images built , able interact of hardware sensors , camera in cases. trying should possible. hope helps.

How to center the message inside an alert box in JavaScript? -

suppose have alert message like: alert("message"); when command executed, alert box pops message aligned left of alert box. is there way center message inside alert box? well, 1 thing should know can't style alert box. it's system object not css thing . if still want use alert , want move text left right use \t , tab. can figure out how many characters you're going use on line , encase text in \t s. eg: \t text centered \t\n \t in middle of alert \t it's not perfect, it's close 1 can move text center in alertbox. \t works perfect firefox not chrome. love chrome, web developer pain in neck. my alert box looks messy without \t s. google need fix issue... suggestion so it's better to create own. example, jquery ui dialog have here : demo the best thing used display message using toast messages. pops up, show message in beautiful box , pops out in sleek manner. have @ materialize css toasts

objective c - Accessing a second NSDictionary in the plist? -

Image
i wondering how access second nsdictionary in plist other root dictionary, have string in second dictionary show in console right i'm getting of them. here's code, console , plist. my plist. (its name multi.plist) my code. nsstring *pathforplist = [[nsbundle mainbundle] pathforresource:@"multi" oftype:@"plist"]; nsdictionary *dict = [[nsdictionary alloc] initwithcontentsoffile:pathforplist]; nslog(@"%@", [dict objectforkey:@"abs"]); and console spitting out right now. so after looking @ that, i'll explain again like, instead of having of contents of abs nsdictionary being in console, show title string lies within dictionary. appreciated. thanks the abs entry dictionary itself, have : nsdictionary * abs = dict[@"abs"]; nslog(@"%@", abs[@"title"]);

java - Activity can't be resumed -

Image
over past months have been developing versatile real-time game engine, , have learned lot, still feel naive when comes application life cycle. specifically, trying implement activity can shuffled in background user, resumed. my current architecture such: have xml menu launcher activity can create real-time game activity using intent. relevant data in game activity referenced through static data structures , variables. game activity creates worker threads in onsurfacecreate() callback of surfaceview object. when user presses button, activity destroyed, , sent xml menu in launcher activity. fine, now. when user presses home button, activity sent background. ok, great. problems arise when user tries find way in game activity once has been sent background. when user touches launcher icon, game destroyed , menu re-launched. also, when user resumes game through task manager, onsurfacecreate() callback fires , worker threads started, game frozen. so, have 2 questions. first, how res

geometry - Opengl - Moving object along (parallel or perpendicular) the view plane -

i think have unique problem. have 2 objects. 1 cube static. have sphere want move. glulookat is: float theta = (float) math.toradians(yrot); float phi = (float) math.toradians(xrot); glu.glulookat(math.sin(phi) * math.cos(theta) * cameramovementradius, math.sin(phi) * math.sin(theta) * cameramovementradius, math.cos(phi) * cameramovementradius, 0, 0, 0, math.cos(theta), math.sin(theta), 1); this positions camera along spherical path. want move sphere along view-plane no matter angel looking @ cube. example: if looking @ cube from: phi = 30 & theta = 85, sphere's forward , backward movement should perpendicular view-plane not towards origin (illustrated below). how achieve this? trying transform navigation of sphere. | | | forward & backward movement of sphere | | ---------------- view plane (forward & backward movement viewed top) ___________ left & right movement of sphere ---------------- view plane (forw

java - How to move a visible image diagonally? -

i have been trying figure out how make visible image move diagonally in applet window. if press up, down, left, or right image (a gif) moves accordingly, if try press 2 keys @ once (up , right @ same time example) image moves in direction pressed second (even if press keys @ same time there still microscopic delay). there might simple way fix not aware of, or perhaps workaround has figured out... appreciate or advice can given. thank-you hero class (this class defines "hero" is; in case simple pixel man, , can do) import objectdraw.*; import java.awt.*; public class hero extends activeobject { private drawingcanvas canvas; private visibleimage player; public hero(location initlocation, image playerpic, drawingcanvas acanvas) { canvas = acanvas; player = new visibleimage(playerpic, canvas.getwidth()/3, canvas.getwidth()/3, canvas); start(); } public void run() { } public void move(double dx, double dy) { player.move(dx, dy); } } herogame cla

android - How to Update contact image using contact provider operation. -

the following code used update image throws illegal or bad value exception.any body can solve this. bitmap bitmap = ((bitmapdrawable)image.getdrawable()).getbitmap(); file f = new file(picturepath); uri photouri = uri.fromfile(f); add array list coding ops.add(contentprovideroperation .newupdate(contactscontract.data.content_uri) .withselection( contactscontract.data.contact_id + " = ? , " + contactscontract.data.mimetype + " = ?", new string[] { contactid, contactscontract.commondatakinds.photo.content_item_type }) .withvalue(photo.photo_uri,photouri ).build()); try following bitmap bitmap = ((bitmapdrawable)image.getdrawable()).getbitmap(); file f = new file(picturepath); uri photouri = uri.fromfile(f);

excel - Querying a table that CONTAINS wildcards -

short version: basically want this , in excel. instead of querying table using wildcards, want query table contains wildcards. long version: i'm creating spreadsheet summarize bank account transactions @ end of each month. want organise transactions in bank statement categories "groceries", "entertainment", "fuel" etc , sum total amount spent on each category. i have sheet acts database, list of known account names each category (e.g. under "clothing" have names of accounts of clothing stores go to). have sheet first 2 columns containing transactions (account name, , amount), , column each category. copy each amount in column 2 correct category column using following formula: =if(isna(match($b2,database!b:b,0)),"",$c2) where column b "account name" column bank statement, , column c contains amounts. this works fine long data in database worksheet exact match. lot of account names similar e.g. &qu

standards - error reading MIDI files into program -

i have midi file generated using musescore. plays in windows media player, causes midi reading program crash. i've been using following links me: midi specification , mobilefish midi guide , second 1 primarily. 4d 54 68 64 = mthd 00 00 00 06 = header length of 6 00 01 = track format 1 00 02 = 2 tracks 01 e0 = 480 delta-ticks per quarter note 4d 54 72 6b = mtrk 00 00 00 86 = length of 0x86 00 ff 58 04 04 02 18 08 = time signature 00 ff 59 02 00 00 = key signature 00 c0 00 = program change (channel 1) 02 b0 07 64 = control mode change (channel 1) 02 0a = running status 40 02 = running status 5b 1e = running status 02 5d = running status 1e ac 78 90 = aftertouch event (channel 13, not applicable in context) 3e 50 = running status 83 5f 3e = delta time (83 5f) , 3e, not status byte (more bytes context): 00 01 40 50 what exists in midi standard i've overlooked here? this question, wrote, flawed, , i'm sorry people tried me; must have copied output notepad++ in

html - div inside li-tag inside ul-tag has an unexpected stretch/resize behavior -

Image
my pen: http://codepen.io/anon/pen/gthpc my goal pen have sort of stacked divs text vertically , horizontally centered. when @ gray or red/blue "stack" see reached goal. comes quirk. when resize window in height gray , red/blue stack gets shrinked in height there black (because background of body black) gap between gray , red/blue stack. gap visible depending @ point resize. look @ image: the div around red/blue stack has of height 24.50 % take 100% 7 areas inside each of 7 'areas' inside div have height of 14.20 % i have alreay tried value of 100% / 7 = 14.28571428571429 % instead of 14.20 % makes situation not better. the black gap still there. i use box-sizing:border-box; html elements available 24.50% divided 7 areas results in clean number of 3.50% height each area including border or padding use latest chrome. so can not understand why there black gap when resize? html <div id="responsechart" style="height:100%;"