Posts

Showing posts from March, 2014

Javascript, regex: Replace specified characters with space and matched character -

i trying use javascript replace() regex expression when matches characters like: .,!? replace matched character surrounded spaces. example string "hello?!?" become "hello ? ! ? " . is there better way doing string.replace() each character wish replace? i know can select on characters easy enough '/[!\?\.]/g' , getting replace same character matched eluding me. it's simple adding back-reference, so: "hello?!?".replace(/([!?\,\.])/g, ' $1 ');

alignment - How to rearrange these elements with CSS? -

Image
codepen: http://codepen.io/leongaban/pen/ndfgs so have table 2 columns, left column being 60% width , right being 40%. inside of left column have div needs centered, , inside div 3 other elements (a span list , span test , span list ). these elements need floated side side, until browser resized small enough media queries make spans end on top of each other. this perfect example of want achieve: however problem comes play. in order make sure div contains 3 elements remains centered inside of left table column. have set fixed width on it: margin: 0 auto; max-width: 200px; // or width: 70%; however if name, title or company of elements long, break layout. my codepen example of layout: http://codepen.io/leongaban/pen/ndfgs example of layout working: example of layout broken because name long so i'm stuck, if name long 1 of elements (the 3rd span) thrown down onto 2nd row unintentionally. because have fixed width. the solution can think of use jquery

What is the least invasive way to compile Groovy unit test code with Maven -

i have existing java project built maven. want write groovy classes unit testing. least invasive way maven compile classes? current versions of gmaven not support groovy compilation, , don't want use groovy-eclipse-compiler existing java code. simplest way groovy code compiled? some options: use older version of gmaven use new gmavenplus (not sure if has been released can't reach github @ moment) use groovyc ant task

c# - Implementing subtle notifications for WinRT apps -

Image
i develop small reusable component closely resembles btprogresshud monotouch. i'm stuck on how inject overlay visual tree without interfering page content. update: after experimenting around bit, came idea in order able decouple overlays page content change window content frame grid can host both root frame , notification elements. app.xaml.cs protected override async void onlaunched(launchactivatedargs args) { grid rootgrid = window.current.content grid; if(rootgrid == null) { var rootframe = new frame(); rootgrid = new grid(); rootgrid.children.add(rootframe); window.current.content = rootgrid; } } progresshud.cs public static class progresshud { static void show(string msg) { grid rootgrid = window.current.content grid; // testing concept rootgrid.children.add(new progressring { isactive = true }; } } could confirm wether changing window.content root frame grid cause unwanted side effects? depends on rest

jquery - Custom width and height on fancybox image -

i wonder if posible set custom width , height on fancybox images? as standard, width , height of fancybox changes in relative width , height of images, want 800 width , 600 height, @ images. i want create familiar image-box on facebook, see image @ left, , description , comments @ right. could great if me this... :) theyaxxe a simpler way change size of both, fancybox opened image , fancybox parent container using beforeshow callback : $(".fancybox").fancybox({ fittoview: false, // avoids scaling image fit in viewport beforeshow: function () { // set size (fancybox) img $(".fancybox-image").css({ "width": 800, "height": 600 }); // set size parent container this.width = 800; this.height = 600; } }); see jsfiddle note : fancybox v2.x+ edit (april 2014) : with current version of fancybox (v2.1.5 today), it's not necessary app

How to reset a loop jQuery -

ok, i've created div dynamically in jquery display blogposts. <div class="blog-items"> <div class="blog-item"></div> </div> the jquery below adds class of nomargin remove margin on last block. how can reset loop starts again on new row. nomargin class applied remaining blocks. here's jquery excerpt var blogitemlength = $('.blog-item').length; if(blogitemlength > 2) { $('.blog-item:gt(1)').removeclass("blog-item").addclass("blog-item_nomargin"); } hope makes sense, in advance. i'd suggest, little understand of problem: $('.blog-item').filter(function(i){ return (i + 1)%3 === 0; }).removeclass('blog-item').addclass('blog-item_nomargin'); this takes .blog-item elements, filters them keep third, sixth, ninth... elements, removes blog-item class-name , adds blog-item_nomargin class-name. references: addclass() . filter() .

java - JPQL - Update with Multiple where conditions -

does jpql support following update? update person p set p.name = :name_1 p.id = :id_1, p.name = :name_2 p.id = :id_2, p.name = :name_3 p.id = :id_3 if not, there alternatives? tried myself. createquery returned null. case expression supported in jpa 2.0. have provided pseudo-code, can make modifications accordingly. you can try below jpql query using case . update person p set p.name = case when (p.id = :id1) :name_1 when (p.id = :id2) :name_2 when (p.id = :id3) :name_3 end general_case_expression::= case when conditional_expression scalar_expression else scalar_expression end else, can try criteria api build query. when(expression condition, r result) : add when/then clause case expression. criteriabuilder.selectcase().when(criteriabuilder.equal(person.get("id"), id1), name_1);

windows - Remove a network printer with Python's wmi module? -

for starters, here's wmi module i'm referring to . i've tried many combinations of code, , understand how remove network printers wmic command line, basic understanding on how remove network printers wmi in vb, etc. still can't figure out how in python module. does have experience this? i'm testing pydev in eclipse, typically on windows 7 machine (which program used along xp), on windows 8. here's code i've tried: import wmi c = wmi.wmi () c.win32_printer("\\\\server\\printer").delete and following error: wmi.x_wmi_invalid_query: <x_wmi: unexpected com error (-2147217385, 'ole error 0x80041017', none, none)> a friend (who wishes remain unnamed) found solution! for printer in c.win32_printer(): if printer.deviceid == "\\\\server\\printer": printer.delete_() for reason, server name (and possibly printer name) seem case-sensitive, keep eye out that. i'd guess it's because python cas

mysql - How to use curtime() to check in column with now() structure? SQL -

in db when new user register use now() column date_added (i need exact time of registration). store user ip in column ip now need check in sql if there registration ip today but $query = $this->db->query("select * " . db_prefix . "customer ip = '" . $this->db->escape($ip) . "' , date_added = curdate()"); return $query->row; does not work because use now() date_added , now() not = curdate() any ideas how trick? use date() ... , date(date_added) = curdate()

javascript - Unable to check if element hasClass, then not animate the element -

explanation in context(wordpress): want check if li element has class called "current-menu-item" if want stop animate function. if not have class continue animating. script not working. help. $(document).ready(function () { $('.nav li a').hover(function() { if ($(this).parentnode.hasclass('current-menu-item')) { alert('this item has class of current-menu-item'); } else { $(this).animate({color:'#3b3b3b'}, 300, 'linear'); } }, function() { if ($(this).parentnode.hasclass('current-menu-item')) { // nothing } else { $(this).animate({color:'#999'}, 300, 'linear'); } }); }); if ($(this).parent().hasclass('current-menu-item')) jquery objects don't have parentnode property. dom elements do, element returned parentnode doesn'

Git: How do you merge a file with a version of itself from a previous commit? -

there changes made file in commit a, undid changes mistake , went on further make changes in commits b , c. i want changes in commit in file, changes in b , c should not lost either. let's branch @ c. i don't want $ git checkout --patch because want file contain changes made in b , c , doing checkout of file commit rewrite file in both index , working tree. i can't cherry-pick because commit merge commit(there 2 contributors repository , deleted changes mentor made mistake in subsequent commits after merged them) , might end mess if specified either parent. apart manually copying changes want in file, there other way accomplish this? you can create patch , attempt apply patch . if experience issues conflicts such error: patch failed: <file_name>:1 error: <file_name>: patch not apply the merge require manual intervention. here's example: $ git format-patch -n <sha_from_commit_you_want_to_merge> > patch_file.patch

JQuery. Ajax request for each row in table -

i tried ajax request each row in table, can't achieve desired result table: <table> <tr class="data"> <td class="editable"> <a class="refresh btn btn-large" class="page"> col 1 </a> </td> <td class="editable"> <a href="#" data-pk="10" id="query" class="query"> col 2 </a> </td> </tr> <tr class="data"> <td class="editable"> <a class="refresh btn btn-large" class="page"> col 1 one </a> </td> <td class="editable"> <a href="#" data-pk="10" id=&

java - How do I properly register clients on a server in RMI? -

i'm working on small project manages attendance summer program i'm helping run. rmi server run office , has specific port set using following code: registry registry = locateregistry.createregistry(4051); remotemanager stub = (remotemanager) unicastremoteobject.exportobject(theserver, 4051); registry.rebind(server_name, stub); where theserver reference object serve system's server , server_name static string used represent server. shown registry binds server port 4051 clients can query it. i'm working on cross-communication between server , multiple client instances (12 teachers running same client program) , set such clients send stubs of server client registration. public void registerclient(interface_client teach) throws remoteexception { . . . } where interface_client extends remote interface , client sent down calling: server.registerclient((interface_client) unicastremoteobject.exportobject(this, 4052)); where chose port 4052 because didn&#

multithreading - Nested Parallel While Loops -

i trying run 2 while loops in parallel purpose of data acquisition. program run "n" num_trials specific trial duration each trial. during each trial, program collect data while keeping track of trial duration. example, first trial starts collecting data @ 1 seconds , stops @ 10 seconds. process repeat rest number of trials how can run both while loops in parallel? basically, want method break second while loop once specified trial duration complete? thanks in advance. count = 0; num_trials = 5; % number of trials = 5 trials trial_duration = 10; % trial duration = 10 seconds global check check = 0; % number of trials = 1:num_trials fprintf('starting trial %i\n', i); t_start = tic; % start counting , collecting data while toc(t_start) < trial_duration % data collection while (check ~= 1) count = count +1; end end fprintf('ending trial %i\n', i); end have tried usin

lwjgl - Java - How to properly use Extends/Implements -

okay kind of confused uses of "extends" , "implements". let me give scenario, let's making simple tower defense game. understanding if made class (towerbase.java), can fill variables , methods, such as; int hp, int damage, int attack(){ ... }, etc.... figured make many types of towers, lets 1 archer tower, , inside towerarcher.java want set towerbase's variables unique values said tower. understanding inside of towerarcher if extend towerbase have access of towerbase's variables , methods since towerbase parent. tried this: public class towerbase { //health (range: 1-100) int hp; public int attack(int blah){ //blah blah how tower goes attacking foe } then in towerarcher.java public class towerarcher extends towerbase{ //set towerarcher's unique values hp = 10; } now somewhere in game... towerarcher archer; archer.attack(blah); eclipse throws syntax error in towerarcher.java @ "hp = 10;": vara

How do I setup an array in C++ with a constant as the max size allowed? -

class grades { private: char *grade; string course[20]; int numcourse; public: grades(); bool setgrade(char *gradein); bool setcourse(char *namein); }; so that's class declaration. want set constant number instead of 20 in array declaration. how go doing that? have tried static const problem every time class returns error saying out of scope. this doesn't work? class grades { private: char *grade; static const int max_courses = 20; string course[max_courses]; int numcourse; public: grades(); bool setgrade(char *gradein); bool setcourse(char *namein); };

css3 - CSS-only design for hashed border -

Image
is possible design (the bordered edges) without using images, using css only..? one of our designers has fired me , think might photoshop border, want avoid using image if possible. thanks in advance tips! yes can! amazing css3 patterns and rough demo you. html: <div class='pat-ho' ></div> <div class='pat-ve' ></div> <div class='text' >text text text</div> css: .pat-ho { position: absolute; width:500px; height:500px; background-color: gray; background-image: linear-gradient(transparent 50%, rgba(255,255,255,.5) 50%); background-size: 20px 20px; } .pat-ve { position: absolute; width:450px; height:500px; background-color: gray; background-image: linear-gradient(90deg, transparent 50%, rgba(255,255,255,.5) 50%); background-size: 20px 20px; left: 25px } .text { position: absolute;

One form to update multiple pages in Rails -

fairly new rails . i'm trying create form updates 2 models, , outputs 2 separate show pages. one, possible, , two, how? saw lot of posts 1 form being able update multiple models, not sure if can have 1 form creates 2 separate pages. edit: thanks comments far. and, sorry lack of clarity. have 2 models. 1 "course preview" page. , second "actual course". user can view preview page, have purchase course allowed view course page. what trying use 1 form create "course preview" , "course" @ same time. thanks in advance! you can't render 2 pages @ once, user can see 1 page @ time. but can create 1 page displays results clever coding. if have 2 models, model1 , model2, , view each one, model1/show.html.erb, can change show.html.erb code from: <%= @model.name %> etc... to <%= render 'display' %> create file named _display.html.erb, , put contents show.html.erb in there. now, when visit s

create basic controls on windows phone using marmalade sdk 6.3.1 -

Image
i want design sample form in windows phone 8 below screen shot: below code hello world example // include header files s3e (core system) , iwgx (rendering) modules #include "s3e.h" #include "iwgx.h" // standard c-style entry point. can take args if required. int main() { // initialise iwgx drawing module iwgxinit(); // set background colour (opaque) blue iwgxsetcolclear(0, 0, 0xff, 0xff); // loop forever, until user or os performs action quit app while(!s3edevicecheckquitrequest() && !(s3ekeyboardgetstate(s3ekeyesc) & s3e_key_state_down) && !(s3ekeyboardgetstate(s3ekeyabsbsk) & s3e_key_state_down) ) { // clear surface iwgxclear(); // use built-in font display string @ coordinate (120, 150) iwgxprintstring(120, 150, "hello, world!"); // standard egl-style flush of drawing surface iwgxflush(); // standard e

How do I select XML elements with attribute "name" of value "lastName" using JQuery? -

i'm trying create family tree using xml , javascript (/jquery). ask user input name, , search xml file. split name variable firstname , lastname, , search using jquery selector. as can see below, after i've directly set lastname equal string "lawlor", not able select xml element via "family[name=lastname] selector (as evidenced missing console log, i've included way @ bottom). a portion of xml file below, followed code i'm using select elements have family element in "name" attribute equal variable "lastname". what frack doing wrong? <xml id="familytree" class="hidden"> <generation0> <family name="lion" surname= "dt" children="4"> <father>joe</father> <mother>schmoe rose</mother> <child>lu</child> <child>bob</child> <child>sam</child> <child>

android - Proper way of closing Streams in Java Sockets -

i saw posts still can't find answer. this how server interacts client: public void run () { try { //read client request inputstream = server.getinputstream(); byte[] buff = new byte[1024]; int i; bytearrayoutputstream bos = new bytearrayoutputstream(); while ((i = is.read(buff, 0, buff.length)) != -1) { bos.write(buff, 0, i); system.out.println(i + " bytes readed ("+bos.size()+")"); } is.close(); = null; //do client request //write response outputstream os = server.getoutputstream(); os.write("server response".getbytes()); os.flush(); os.close(); os = null; } catch (ioexception ioe) { ioe.printstacktrace(); } } and client side: public void run() { try { inetaddress serveraddr = null; serveraddr = inetaddress.getbyname("10.0.2.2"

java - Comparing two lines in text file & printing single line corresponding to similar dates -

i want take line 1 , line 5 has username , date same in line 1 contains in time,and in line 5 contain out time want read 2 lines , compare check whether both lines have same username , date , if print single line in other text file or in hash map example : "sangeetha-may 02, 2013 , -in-09:48:06:61 -out-08:08:19:27 (in java) this content of text file : line 1. "sangeetha-may 02, 2013 , -in-09:48:06:61 line 2. "lohith-may 01, 2013 , -out-09:10:41:61 line 3 . "sushma-may 02, 2013 , -in-09:48:06:61 line 4. "sangeetha-may 01, 2013 , -out-08:36:38:50 line 5. "sangeetha-may 02, 2013 , -out-08:08:19:27 line 6. "sushma-may 02, 2013 , -out-07:52:13:51 line 7. "sangeetha-jan 01, 2013 , -in-09:27:17:52-out-06:47:48:00 line 8. "madhusudhan-jan 01, 2013 , -in-09:38:59:31-out-07:41:06:40 above data generating using code below import java.io.bufferedreader; import java.io.bufferedwriter; import java.io.file; import java.io.filereader; import

c# - Load page in div when i click button -

i new asp.net. in home page used 2 image buttons. should want when button click different page need load in home page div tag. how can asp.net /csharp use iframe <iframe id="iframe1" ></iframe> use js change src i.e document.getelementbyid('iframe1').src = yourpagepath; thanks

c - How to solve Connect() time-out issues on blocking socket(for SSL handshake)? -

this type of question is(with lot of variations) kinda answered but.. need blocking connect(i'm using ssl)on socket, can set time-out , maximum number of retries , necessary never lasting more t seconds. i hope there thing can set in os(linux: ubuntu/centos) or way in code(c) w/o going ugly, artificial way select wait, timeout events added epoll close socket. thank you. the simplest way use alarm system call before , after connect call , handle alarm signal, not best , useful way. better , recommended way use non-blocking socket , use poll or select system calls handle different stages of making connection. if don't want use non-blocking io way use alarm. for tutorial using non-blocking sockets refer : http://developerweb.net/viewtopic.php?id=3196 for more information happens during connect call refer to: http://www.madore.org/~david/computers/connect-intr.html

function - Passing in a three.js object into javascript -

so basically, making robot object in javascript using three.js , passing in three.js scene variable object using draw robot parts through array- reason, though, scene object not pass function (it won't draw)- missing javascript functions? function robot(sc){ this.sc=sc; var robtexture = new three.meshlambertmaterial({ map: three.imageutils.loadtexture('tex/dmetal.png') }); this.parts = []; var current; //make body current=new three.mesh(new three.cubegeometry(10,15,10), robtexture); this.parts.push(current); alert("hit"); //make legs } robot.prototype.draw = function() { (x in this.parts){ this.sc.add(x); alert("hit"); } } maybe works more intended: robot.prototype.draw = function() { (x in this.parts){ this.sc.add(this.parts[x]); // < - spot difference :) alert("hit"); } }

dynamics crm 2011 - Ribbon changes are not published -

recently i've faced strange problem: i changed ribbon invoice entity on development environment, exported solution managed, imported solution environment, published , nothing happens. i checked customization.xml file , found changes there. next, checked solution.xml , found ribbondiffxml root component included inside solution. but when checked ribbon* tables inside sql database, found relevant commands , rules not updated. does can assist me in solving issue? try tool whcih best way edit ribbon. https://community.dynamics.com/crm/b/crmmusings/archive/2012/09/12/crm-2011-ribbon-workbench-getting-guids-from-selected-records-in-the-grid.aspx#.ueza-o3wwzq it working ru 12

Compass compile error on Sencha Touch 2.2.1, undefined $font-family value and mixin problems -

using this tutorial sencha touch 2.2.1, i'm not able compile project because of undefined $font-family variable: error application.scss (line 2 of _class.scss: undefined variable: "$font-family".) sass::syntaxerror on line ["2"] of /users/mac/sites/apps/myapp/touch/resources/themes/stylesheets/sencha- touch/default/src/_class.scss: undefined variable: "$font-family". does have idea how solve this? note: bug in previous version (sencha touch 2.2). application.scss 1 $base-color: #7a1e08; 2 $base-gradient: 'glossy'; 3 4 @import 'sencha-touch/default/all'; 5 6 @include sencha-panel; 7 @include sencha-buttons; 8 @include sencha-sheet; 9 @include sencha-picker; 10 @include sencha-toolbar-forms; 11 @include sencha-tabs; 12 @include sencha-toolbar; 13 @include sencha-carousel; 14 @include sencha-indexbar; 15 @include sencha-list; 16 @include sencha-layout; 17 @include sencha-form; 18

java - Array out of bound exception -

i have text file in computer reading form java program, want build criteria. here notepad file : #students #studentid studentkey yearlevel studentname token 358314 432731243 12 adrian afg56 358297 432730131 12 armstrong yuy89 358341 432737489 12 atkins jk671 #teachers #teacherid teacherkey yearlevel teachername token 358314 432731243 12 adrian n7acd 358297 432730131 12 armstrong ey2c 358341 432737489 12 atkins f4ngh while reading notepad below code array out of bound exception. while debugging "  #students" value strline.length(). can solve this? private static integer student_id_column = 0; private static integer student_key_column = 1; private static integer year_level_column = 2; private static integer studen

html - Isotope Images is not showing in internet explorer -

Image
the site have made @ http://opplev.olavsfestdagene.no it works intended in except ie. none of pictures showing. has idea of might wrong? it html markup failure, or isotope not working somehow? are getting following error in ie debugger sec7112: le script de http://raw.github.com/desandro/isotope/master/jquery.isotope.min.js été bloqué à cause d'une incompatibilité de type mime the script has been blocked due mime type mismatch you shouldn't linking directly raw.github.com. fortunately, there's rawgithub.com solve that! try http://rawgithub.com/desandro/isotope/master/jquery.isotope.min.js

.htaccess - URI not rewritten although it matches rewrite condition -

one of clients has multiple domains point 1 webspace. avoid duplicate content uris rewritten point 1 place. using code below works 2 of them. far can tell there nothing special them. sadly don't have administrative access domains, best of understanding .htaccess should enough. does have idea problem be? the rule: <ifmodule mod_rewrite.c> rewritecond %{https} !=on rewritecond %{http_host} !^example\.com$ [nc] rewriterule ^ http://example\.com%{request_uri} [r=301,l] </ifmodule>

c# - Extract one whole column from DataTable without using LINQ? -

i have datatable many columns in it. want extract entire 3rd column in, , put values in string array. , not want use linq i'm using .net 2.0 framework, default not support linq. so how can without linq ? string[] result = new string[datatable.rows.count]; int index = 0; foreach(datarow row in datatable.rows) { result[index] = row[2].tostring(); ++index; }

Android ImageView how to fit left-bottom such as setScaleType(ScaleType.FIT_END);, but not fit right-bottom -

i use below code set imageview's scaletype: iv.setscaletype(scaletype.fit_end); it fit right-bottom. want make picture fit left-bottom. how can it? try setting imageview's adjust view bound true , set align bottom parent , align left parent true. hope works :)

iphone - UIViewController in a UITabBarController without tab bar item -

Image
so have application have view controller (which want appear first when app starts) , tab bar controller. have other navigation bar controllers in tab bar controller. want place view controller on top of tab bar controller. making tab bar controller parent of view controller better though. but take note, not want tab bar item represent view controller , want tab bar appear along view controller. not , not want use storyboards as possible. how can achieve this? i guess simplest solution use screenshot of tabbar , put in homeviewcontroller button. in case use homeviewcontroller rootviewcontroller , in button action set tabbarcontroller rootviewcontroller . root = home + button --> root = tabbar perhaps need 4 buttons, if want correct tab selected.

android - ListFragment doesn't update data from CursorLoader -

i need show data server. there several fragments items can displayed, not easy mantain updates. decided cache data in db , use contentprovider access it. have strange issue. initially, there no data in database. create cursorloader , set cursoradapter adapter listfragment . receive server , insert several records. supposed loader automatically notified them , reload data. nothing happens, , listfragment stays empty. the other strange thing related. i've wrote code add actionbar menu fragment. in situation oncreateoptionsmenu not called (despite of sethasoptionsmenu(true) in oncreate ) , menu not added. when db has data, works normally. it seems broken inside fragment , there nothing in logs. think, doing wrong? here sample fragment, works this: import android.database.cursor; import android.os.bundle; import android.support.v4.app.listfragment; import android.support.v4.app.loadermanager; import android.support.v4.content.cursorloader; import android.support.v4.co

java - exception from simulation local variable type mismatch while converting jar to dex -

i trying apply aspect on constructor of class.i have created jar file of compiled class aspect. noq want convert jar file .dex file . while converting shows me exception: f:\sachin\tools\adt_bundle\adt-bundle-windows-x86\sdk\platform-tools>dx --dex -- output=classes.dex yepme_jar_with_aspect_on_settext.jar exception simulation: local variable type mismatch: attempt set or access value of type int using local variable of type pak.hookyepmeaspect. symptomatic of .class tra nsformation tools ignore local variable information. ...at bytecode offset 00000009 locals[0000]: locals[0001]: ljava/lang/string; locals[0002]: ljava/lang/string; locals[0003]: ljava/lang/string; locals[0004]: ljava/lang/string; locals[0005]: ljava/lang/string; locals[0006]: ljava/lang/string; locals[0007]: ljava/lang/string; locals[0008]: ljava/lang/string; locals[0009]: ljava/lang/string; locals[000a]: ljava/lang/string; locals[000b]: ljava/lang/string; locals[000c]: lorg/aspectj/runtime/internal/aroundc

Can't achieve jumping in Javascript Game -

i developing javascript game (almost based on tutorial yet, not worried of sharing code). the problem is, can't character jump after pressing space button. please, can @ code , me? // edit: sorry lack of information provided. thing - code written, game in state, character animated (=is running) , backgrounds moving. yesterday, tried implement basic controls, such jump pressing spacebar. thing is, player won't jump @ all, , browser console not giving me error statements. character defined player on line 5. , 321. in code provided below. the jumping defined in following examples: pressing space button var key_codes = { 32: 'space' }; var key_status = {}; (var code in key_codes) { if (key_codes.hasownproperty(code)) { key_status[key_codes[code]] = false; } } document.onkeydown = function(e) { var keycode = (e.keycode) ? e.keycode : e.charcode; if (key_codes[keycode]) { e.preventdefault(); key_status[key_c

java - Int to byteArray -

i having integer value.now first convert byte array of size 4 following logic : logic 1 byte[] tempbytes = new byte[4]; int y=1; for(i=3;i>=0;i--){ int sum=0; for(int j=0;j<8;j++){ int z=x & y; x=x>>1; sum=sum+power(2, j)*z; } tempbytes[i]=(byte)sum; } logic 2 : int sizeoffile; bytearrayoutputstream baos = new bytearrayoutputstream(); dataoutputstream dos = new dataoutputstream(baos); dos.writeint(sizeoffile); dos.close(); byte[] tempbytes = baos.tobytearray(); now array may contain negative values if int value 8401 corresponding byte array 0 0 32 -47 . i convert byte array string s doing : s=new string(temp); i convert string bytes using getbytes() . but result gives 0 0 32 -17.so when convert int gives wrong result. here sizefile bytearray after convert string bytes again. int sizeoffilerecieved = java.nio.bytebuffer.wrap(sizefile).getint(); what can problem here.please how sol

Intern.io Single Page Application Functional Testing -

i have single page application uses dojo navigate between pages. writing functional tests using intern , there niggly issues trying weed out. having trouble getting intern behave timeouts. none of timeouts seem have effect me. trying set initial load timeout using "setpageloadtimeout(30000)" seems ignored. call "setimplicitwaittimeout(10000)" again seems have no effect. the main problem have may take couple of seconds in test environment request sent , response parsed , injected dom. way have been able around explicitly calling "sleep(3000)" example can bit hit & miss , dom elements not ready time query them. (as mentioned setimplicitwaittimeout(10000) doesn't seem have effect me) with application fire event when dom has been updated. use dojo.subscribe hook in applictaion. possible use dojo.subscribe within intern control execution of tests? heres sample of code. should have mentioned use dijit there slight delay when response comes , wi

salesforce - Using two actions on a single checkbox event -

i having problems while trying render pageblocksection in visualforce. code have used given below. <apex:pageblocksection title="my content section" columns="2"> <apex:pageblocksectionitem> <apex:outputlabel value="account site"/> <apex:outputpanel> <apex:inputtext value="{!account.site}" id="account__site" onclick="changefont(this)"> <apex:actionsupport event="onclick" rerender="thepageblock" status="status"/> </apex:outputpanel> </apex:pageblocksectionitem> </apex:pageblocksection> here trying render page block , javascript function @ same time, i,e checking of checkbox(account site). problem here when try execute changefont(this) function in onclick of apex:inputtext , try render "thepageblock" in e

How to dynamically add a (HABTM) collection_select + associated text_field in a Rails form? -

for personal invoicing app in rails use advice on following: in new invoice form, how dynamically add new row consisting of collection_select products , associated text_field amount clicking add new product ? since 1 invoice has many products , product has many invoices, figured habtm relationship both ways. therefore have created tables invoices , products , , join table invoices_products . i invoices/new page have form user can use collection_select pick product (all products preloaded in products table) , fill in amount in text field behind it. user should able duplicate these 2 fields (collection_select , text_field) clicking add new product , railscast #403 dynamic forms 04:50 . now how go doing that? , in table put data amount text_field, since there multiple products per invoice multiple amounts? any answer in right direction appreciated! this depends on how many additional fields want a tutorial can found here ajax the right way add element dyn

windows - Downloading Microsofts knowledge base -

is there way download microsoft's current knowledge base? i'm running script trawls through kb numbers , grabbing page (which taking while, @ kb article 385538 lol), , i'm going collate relevent information database ... personal use, there's no copywrite infringements or ... need offline version :d

android - How to use ContextMenu on long click on the screen(on tablelayout for which parentlayout is scrollview)? -

how use contextmenu on long click on screen(on tablelayout parentlayout scrollview)? i have used scrollview within used tablelayout , on longclicking need display contextmenu. on longclick able display toast not contextmenu. within onlongclick() method not able implement oncreatecontextmenu() , oncreatecontextmenu() methods. can please me in regard??if thankful u...thanks !!! some code useful, guessing defining , onlongclicklistener inline this oncreate { tablelayout t = (tablelayout) this.findviewbyid(r.id.mytable) t.setonlongclicklistener(new onlongclicklistener() { void onlongclick(view v) { //here think you're trying make contextmenu } } } if i'm right, because you're trying make context menu inner class, need reference outer class. need call: [nameofyourclass].this.oncreatecontextmenu(.....)

join - Multiple queries are executed during fetch of an associated class - ruby on rails -

i want optimize code performance in such way instead of multiple queries; in single query can information database. my code this: i have class (called class:a) have sti (let type a1 , type a2). and 2 more class(let class b , class c) associated class a. something this... class < activerecord::base has_many :b has_many :c blahblah end class b < activerecord::base belongs_to :a blahblah end class c < activerecord::base belongs_to :a blahblah end class a1 < blahblah end class a2 < blahblah end now, when trying load a1 total 9 times queries executed... can optimize in a single query?? i trying excute this: @datas = a1.where("id" < 5 ) console output: a1 columns (1.0ms) show fields `a` a1 load (2.2ms) select * `a` (id < 5) , ( (`promotions`.`type` = 'a1' ) ) c load (0.4ms) select * `c` (`c`.a_id = 1) c columns (0.7ms) show fields `c` sql (0.1ms) set names '

How do I get filename and line count per file using powershell -

i have following powershell script count lines per file in given directory: dir -include *.csv -recurse | foreach{get-content $_ | measure-object -line} this giving me following output: lines words characters property ----- ----- ---------- -------- 27 90 11 95 449 ... the counts-per-file fine (i don't require words, characters, or property), don't know filename count for. the ideal output like: filename lines -------- ----- filename1.txt 27 filename1.txt 90 filename1.txt 11 filename1.txt 95 filename1.txt 449 ... how add filename output? try this: dir -include *.csv -recurse | % { $_ | select name, @{n="lines";e={ get-content $_ | measure-object -line | select -expa lines } } } | ft -autosize

c# - Efficient List Ordering -

i testing whats best algorithm order list key value. i have simple object (following code snippets c#) class basicobject { int key; } the key gets randomly set when constructing object. so have list of basicobject objects needs ordered key value in end. list<basicobject> basiclist = new list<basicobject>(); (int = 0; < someamount; i++) { basiclist.add(new basicobject()); } my idea was, make new list called orderedlist or so, , loop through every time, every basicobject , , check whether key higher current value or lower. that: list<basicobject> orderedlist = new list<basicobject>(); bool objectwasinserted = false; orderedlist.add(basiclist[0]); // inserting 1 object reference upcoming loop (int = 1; < someamount; i++) { objectwasinserted = false; (int c = 0; c < orderedlist.count; c++) { if (basiclist[i].key > orderedlist[c].key) // key of current object higher key of current object of ordered list { orderedlist.insert(c, basic

ruby - Problems when creating Compass project (EACCES on line ["891"]) -

i having problems when creating new compass project (windows 7). this: c:\>compass create create config.rb errno::eacces on line ["891"] of c: permission denied - (c:/a/config.rb20140321-6828-1g0ytlc, c:/a/config.rb) run --trace see full backtrace i have tried start cmd "run administrator", have tried delete compass, sass , ruby, , reinstalled without luck. else having problems or know solution irritating problem? i using latest version (21.03.2014) of compass v.0.12.4... downgraded v.0.12.2 worked fine! looks bug? to downgrade: $ gem uninstall compass $ gem uninstall sass $ gem install compass -v 0.12.2 $ gem install sass -v <rev>

ios - NSFetchedResultsController - how to handle changing Core Data source? -

i'm using core data magicalrecord , nsfetchedresultscontroller display data in table view. works fine, have change underlying sqlite-file underneath leads crash. i'm creating frc following way: nsfetchrequest *request = [nsfetchrequest fetchrequestwithentityname:@"cdperson"]; nssortdescriptor *sortbynamedescriptor = [nssortdescriptor sortdescriptorwithkey:@"lastname" ascending:yes]; request.sortdescriptors = @[sortbynamedescriptor]; _fetchedresultscontroller = [[nsfetchedresultscontroller alloc] initwithfetchrequest:request managedobjectcontext:[nsmanagedobjectcontext mr_contextforcurrentthread] sectionnamekeypath:nil cachename:nil]; _fetchedresultscontroller.delegate = self; [_fetchedresultscontroller performfetch:nil]; when changing sqlite-file, i'm doing: [magicalrecord cleanup]; // delete old sqlite file // copy new sqlite file [magicalrecord setupcoredatastackwithautomigratingsqlitestorenamed:sqlite_filename]; what have frc have take

git branch - How do I incorporate a new source code updates while keeping my existing modifications in Git? -

so far, i've been using git , it's tolerable simple pushes , merges, got curve ball thrown @ me. developers of source code using released new version release source tree. several files have been changed , having difficulty figuring out how incorporate new source such can keep old version of code modifications 1 branch, version 1.0, , new version of code same modifications branch, version 2.0. i'm 1 working on project, don't care rewriting history if have too. ideally, able continue making modifications , have them apply both versions. you can use submodule code of library using , able have 2 brunches in submodule (version 1.0 , version 2.0) , use master branch code. in such case when changes done able provide them both version 1.0 , version 2.0 switching branch in submodule code example cd /path/to/project/ mv lib /some/other/location/ git rm lib git commit -m'move lib submodule' cd /some/other/location/lib git init git add . git commit cd /p

android - Delay when drawer is being closed on loading a fragment with a lot of data -

on fragments not loading lot of data load , drawer closes quick. however when loading fragment lot of data there delay when drawer closed. i have setup progress bar on main layout show , put data loading view.post(new runnable() drawer still has delay when closing. maybe im not doing right? on fragments oncreateview method have this @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view view = inflater.inflate(r.layout.fragment_icon_request_list, container, false); if (view != null) { progressbar = (progressbar) getactivity().findviewbyid(r.id.base_progressspinner); progressbar.setvisibility(view.visible); view.post(new runnable() { @override public void run() { try { initcards(); } catch (ioexception e) { e.printstacktrace(); } catch (packagemanager.namenotfoundexception

java - Need help reading files -

i'm writing mock stock market in java, , want ability user view stocks purchased. decided easiest way write file. problem every time run program , attempt read file, outputs path took read it. information want correctly written file, isn't reading way want. here code used file reading section: if (amountofstocks1 >= 1) { scanner stocksbought1 = new scanner("stocksbought/stocksbought1.txt"); while (stocksbought1.hasnext()) { string fileread = stocksbought1.nextline(); system.out.println(fileread); } stocksbought1.close(); runmenu = 1; } there 7 of these amountofstocks if/else statements. i'm not sure if that's enough information. if it's not, tell me put on, , i'll that. if can me fix problem or if know easier way read , write files great! instead of: scanner stocksbought1 = new scanner("stocksbought/stocksbought1.txt"); try: scanner stocksbought1 = new scanner(new file("stocksbought/sto

Android, Java: Improve quality of Bitmap with getDrawingCache() -

i have dialog , convert bitmap . want send sharing intent: bitmap cs = null; v1.setdrawingcacheenabled(true); v1.builddrawingcache(true); cs = bitmap.createbitmap(v1.getdrawingcache()); canvas canvas = new canvas(cs); v1.draw(canvas); canvas.save(); v1.setdrawingcacheenabled(false); string path = images.media.insertimage(getcontext().getcontentresolver(), cs, "myimage", null); uri file = uri.parse(path); intent sharingintent = new intent(intent.action_send); sharingintent.settype("image/png"); sharingintent.putextra(intent.extra_stream, file); getcontext().startactivity(intent.createchooser(sharingintent,"share image using")); v1 parent of textview in dialog ( v1 want send). if send bitmap has bad quality. how can improve that?

php - How to acces one .phtml file in another .phtml file magento? -

in magento development how access 1 ".phtml" file in 1 or more other ".phtml" files? for example: in theme template folder there 1 folder info. contains info.phtml.this info.phtml display data database.i want use info.phtml in other .phtml files using getchildhtml() how this? try code in phtml file call phtml file <?php echo $this->getlayout()->createblock('core/template')->settemplate('test/test.phtml')->tohtml(); ?>