Posts

Showing posts from 2010

java - Find an a specific instance, what is the best approach -

so imagine have 2 instances of class: public class myclass { public void sayhello() { system.out.println("hello"); } } = new myclass(); b = new myclass(); now add object, such as: public class otherclass { private arraylist<myclass> myclslist = new arraylist<>(); public void add(myclass obj) { myclslist.add(obj); } public void remove(myclass obj) { // ???? } } c = new otherclass(); c.add(a); c.add(b); now want remove 1 specific instance e.g c.remove(a); could iterate on them , test equality, mean should theoretically work, since 2 instances have distinct "internal pointers"? i guess using hashmap based approach more efficient, can use key there (suppose can't add unique instance ids or something). edit: there confusion i'd know. key here i'd know if there way of removing specific instance c's arraylist or whatever aggregator object might use, providing respecti...

if statement - Is there a shortened method to loop through conditions in IF in VB.NET -

so making program needs check if file of video / audio format. have code (song system.io.fileinfo ): if song.extension.toupper = ".mp4" or song.extension = ".avi" or song.extension = ".mp3" or song.extension = ".aa" or song.extension = ".m4a" or song.extension = ".aiff" or song.extension = ".wav" or song.extension = ".m4v" or song.extension = ".aac" or song.extension = ".vob" the problem checks first 2 conditions. need split separate if s or there way test conditions in 1 line? you can make set extensions in it: dim extensions new hashset(of string) { ".mp4", ".avi", ".mp3", ".aa", ".m4a", ".aiff", ".wav", ".m4v", ".aac", ".vob" } and check if value in contains : if extensions.contains(song.extension.tolower()) ⋮ end if

android - Keep view the same on all devices -

how can change activities xml file view stays same regardless of size of screen. mean location in buttons or text is. want stay relatively same distance , everything. how that? relative layout work or there else have in order view same on devices? xml file: <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.constraintlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.navjeevenmann.mytycoon.mainactivity"> <android.support.v7.widget.toolbar android:id="@+id/toolbar2" android:layout_width="0dp" android:layout_height="59dp" android:background="#2c3aad" android:minheight="?attr/actionbarsize" ...

Android: Communication between Fragment and another Fragment directly on top of it -

as understand, if want communicate between 2 fragments, on underlying activity. however, 2 fragments not on same hierarchy level, because 1 fragment gets opened within/on top of fragment. if click button on overlaying fragment, there way communicate directly holding fragment, without going detour on activity? because messy. a button click on fragment 1 opens fragment 2 in framelayout in fragment 1. sounds big detour send fragment 2 interaction underlying activity , fragment 1. if understand correctly, mlistener activity, not fragment holds 2nd fragment @override public void onattach(context context) { super.onattach(context); if (context instanceof onfragmentinteractionlistener) { mlistener = (onfragmentinteractionlistener) context; } else { throw new runtimeexception(context.tostring() + " must implement onfragmentinteractionlistener"); } } personally, i'd send through activity. but, use message bus in...

github api - Is it possible to create a PushEvent with more than one commit? -

i'm using code snippet create commits via github api using go-github, , it's not working planned. i'm trying create single push event contains 26 commits, instead it's creating 26 push events, each of contains single commit. if you're wondering "why?", it's because i'm trying recreate particular scenario validate behavior. is limitation due "connected/online" nature of github api? need have local github repo checkout , commits , pushes via "git commit" , "git push"? (either cli or libgit bindings)

scala - Apache Zeppelin cannot deserialize dataset: "NoSuchMethodError" -

i trying use apache zeppelin (0.7.2, net install running locally on mac) explore data loaded s3 bucket. data seems load fine, command: val p = spark.read.textfile("s3a://sparkcookbook/person") gives result: p: org.apache.spark.sql.dataset[string] = [value: string] however, when try call methods on object p , error. example: p.take(1) results in: java.lang.noclassdeffounderror: not initialize class org.apache.spark.rdd.rddoperationscope$ @ org.apache.spark.sql.execution.sparkplan.executequery(sparkplan.scala:132) @ org.apache.spark.sql.execution.sparkplan.execute(sparkplan.scala:113) @ org.apache.spark.sql.execution.sparkplan.getbytearrayrdd(sparkplan.scala:225) @ org.apache.spark.sql.execution.sparkplan.executetake(sparkplan.scala:308) @ org.apache.spark.sql.execution.collectlimitexec.executecollect(limit.scala:38) @ org.apache.spark.sql.dataset$$anonfun$org$apache$spark$sql$dataset$$execute$1$1.apply(dataset.scala:2371) @ org.apache.spark.sql....

Threadscope's gettext.sh file interferes with git on Windows -

when run git commands, i'm noticing strange messages wrt totally unrelated program, namely threadscope, use obtaining information on parallel haskell programs. git stash ': not valid identifier/threadscope-0.2.2/bin/gettext.sh: line 90: export: `dashless ': not valid identifier/threadscope-0.2.2/bin/gettext.sh: line 90: export: `usage ': not valid identifier/threadscope-0.2.2/bin/gettext.sh: line 90: export: `stash_msg i'm not sure causing this. seems benign, bit annoying. seems related program 'gettext.exe' unable find information online on does. the line 90 in question in gettext.sh is eval_gettext () { gettext "$1" | (export path `envsubst --variables "$1"`; envsubst "$1") } could me getting rid of these messages in right way? i'm using window 10. installed threadscope downloading binaries https://wiki.haskell.org/threadscope#installing_threadscope , placing them in program files folder. try s...

c# - Unity, how to get Camera angle Width -

i'm making game must set target number on enemy on screen. fail find function isinsidecameraview(gameobject) now i'm trying scan area camera looks. this, need camera angle width, angle hight. as described in emage (my reputation not enough show image directly) my question similer question, how angles value of perspective camera in three.js? unity. if know how calculate camera width&height (following screen size when unity starts)or there funtions isinsidecameraview(camera, gameobject) answers welcomed. [untested. javascript] can use renderer.isvisible determine if object within camera frustum.

vue.js - how to get the component instance within an @click event? -

i have button in vue component <el-button class='range-right' @click='deleteitem(item)'>delete</el-button> within it's handler want invoke other methods of component. however, though can call deleteitem component method, cannot @ actual component other methods. is there way pass $component param @click event? methods { deleteitem: (item, obj) => { let api = '/api/train/deleteitem?_id=' + item._id let resource = vue.resource(api) let vm = // not component window.delitem = console.log('deleteitem.this', this) resource.delete(api) .then(items => { console.log('deleted') vm.methods.load() //<< fails }) }, i think problem arrow function commented see example here using function : https://jsfiddle.net/rvp6fvwp/ arrow function bound parent context said here https://vuejs.org/v2/guide/instance.html#properties-and-methods don’t use arrow functio...

java - My delete method to remove a specific Node with X age value will not work -

this code, please reference main method , delete method, other methods included show full program. have heard java takes method arguments pass value, issue, , object's properties pass-by-reference. so change node.age , since age property, cannot make node equal node = node.next ? have been @ while, trying learn how different operations , have been stuck on this. if-statement went through, headnode did not equate headnode.next wanted to: public class node { int age; node next; node previous; public static void main (string [] args) { node firstnode = new node(18); node t = firstnode; node randomfatnode = new node(); for(int = 0; < 30; += 3) { node tempnode = new node(i + 21); firstnode.next = tempnode; tempnode.previous = firstnode; firstnode = tempnode; } node tailnode = firstnode; firstnode = t; traverseforward(firstnode); //pr...

Angular 2 | TypeScript | Converting circular structure to JSON -

Image
below code in trying create single object having key value pair. here calling service method hitting api.the error coming @ this._addressservice.setaddressdatafirebase(this.addressobj).subscribe(); how can solve it? please share!

c# - Create deck of card using multiple enums -

this question has answer here: best way represent game card class in c# 7 answers what best way have score value cards in deck 3 answers i have made following code create deck of cards using 2 enums , switch statement. not think switch statement elegant solution. question is, therefore: possible avoid switch statement looping through enum? the variable value31 used stored value cards have in game of "31". namespace cardgame31 { public enum suitpossiblevalues { clubs, diamonds, hearts, spades }; public enum rankpossiblevalues { two, three, four, five, six, seven, eight, nine, ten, jack, queen, king, ace }; class program { static void main(string[] args) { carddeck mycarddeck = new carddeck(); } } class carddeck { list<card> carddeckl...

ecmascript 6 - is there a syntax in javascript new features where i can extract object values into new object with same key and values? -

this question has answer here: one-liner take properties object in es 6 6 answers let obj = { a: 1, b:2, c:3} i can do let {a,b,c} = obj but want object 'a' , 'b' key , same value in obj do have syntax one it filtering out keys have succint syntax 1 because do let test = { a: obj.a, b: obj.b } how let n = ({a,b} = obj) && {a,b} ?

css - How to make negative margin element responsive -

Image
currently, have html structure here current css code @media screen , (max-width: 1000px) { #main-banner span{ left:55%; } #case_tagline{ width:100%; font-size:35px; margin-top:0; margin-bottom:-11%; padding-top:0; padding-bottom:0; padding:10px 20px 15px 15px; margin-top:-5.5%; margin-bottom:-5%; } #case_tagline span{ display:block; } #case_tagline span.big{ font-size:100%; } #case_study_slider{ margin:0px 0px 0px 0px !important; padding-top:0; padding-bottom:0; } #case_study_slider .ms-container{ width:100%; } #case_study_slider .empty_case{ height:0; padding-bottom:10%; width:100%; } #case_study_slider .ms-nav-prev{ top:127px; /*left:-35%;*/ } #case_study_slider .ms-nav-next{ top:127px; /*right:32%;*/ } section....

hadoop - search a given word in a text File using MapReduce in JAVA in ubuntu 16.04 -

i have make project find given word (string). string inputted user. find occurrence of word in particular text file stored in hdfs. output should tell presence of word string. package stringsearchjob; import java.io.ioexception; import java.util.scanner; import org.apache.hadoop.conf.configuration; import org.apache.hadoop.fs.path; import org.apache.hadoop.io.intwritable; import org.apache.hadoop.io.longwritable; import org.apache.hadoop.io.text; import org.apache.hadoop.mapred.jobclient; import org.apache.hadoop.mapred.jobconf; import org.apache.hadoop.mapreduce.job; import org.apache.hadoop.mapreduce.mapper; import org.apache.hadoop.mapreduce.lib.input.fileinputformat; import org.apache.hadoop.mapreduce.lib.output.fileoutputformat; public class stringsearch{ public static void main(string argv[]) throws exception { try { if (argv.length<3) { system.err.println("give input/ output/ keyword!"); return; ...

Select row from a DataFrame based on values in a column in pandas -

df.loc[df['column_name'] == some_value] selects data row or rows in dataframe given specified column. what equivalent if need specify 'row name' ? if understand correctly, can pass index directly loc : example: df b group abc 6 9 abc 3 12 abc 5 56 def 8 32 gfd 4 65 uio 2 87 def 1 31 poi 8 2 fgb 3 3 df.loc['abc'] b group abc 6 9 abc 3 12 abc 5 56

javascript - setInterval function without arrow function -

i learning react components following documentation https://facebook.github.io/react/docs/state-and-lifecycle.html why need use arrow function here: this.timerid = setinterval(() => this.tick(), 1000); why can't (obviously doesn't work) this.timerid = setinterval(this.tick(), 1000); the first argument setinterval of type function . if write this: this.timerid = setinterval(this.tick(), 1000); …then don't pass function, instead execute function this.tick , pass value returned function call argument. you could write this: this.timerid = setinterval(this.tick, 1000); if omit parentheses, pass reference this.tick function, executed setinterval after 1000 milliseconds.

shell - Reset DHCP lease time through CLI -

probably because of many changes made on last few years windows system drops local network connections after 30 minutes. other systems in same network don't have problem assume it's not router. i found few commands like set-dhcpserverv4scope -scopeid 192.168.0.1 –leaseduration (new-timespan -hours 12) or netsh dhcp server scope 192.168.0.1 set optionvalue 000 neither powershell nor command prompt recognizing them valid commands. how set dhcp settings default through powershell, cmd or registry? [neither] powershell nor command prompt recognizing them valid commands. you'll need enable dhcp tools, either appwiz.cpl (programs/features) or with: enable-windowsoptionalfeature -featurename rsatclient-roles-dhcp -online this enable both dhcp administration mmc snap-ins, dhcp server powershell module , netsh dhcp context. assuming you're on client os, you'll need download , install appropriate version of remote server administrati...

android - Getting Google Cast v3 to work on unsupported devices -

the cast v3 framework has features try make possible run on devices without google play services required work, ran issues when testing. on kindle google api returns service_invalid isuserresolvable() true. on devices onactivityresult returning connectionresult.success after upgrade, castcontext.getsharedinstance() can throw runtimeerror . as side-effect of 2), xml inflate of items containing minicontrollerfragment fail. some errors found were java.lang.runtimeexception: unable start activity componentinfo{##########.mainactivity}: android.view.inflateexception: binary xml file line #42: error inflating class fragment caused by: java.lang.runtimeexception: com.google.android.gms.dynamite.dynamitemodule$zzc: remote load failed. no local fallback found. @ com.google.android.gms.internal.zzauj.zzan(unknown source) @ com.google.android.gms.internal.zzauj.zza(unknown source) @ com.google.android.gms.cast.framework.castcontext.<init>(unknown source) ...

javascript - jQuery detect element in viewport - calc causing issues -

i trying detect when element out of viewport, have far... /* pause video if out of viewport */ jquery(function($) { //this function runs every time scrolling $(window).scroll(function() { var top_of_element = $(".element").offset().top; var bottom_of_element = $(".element").offset().top + $(".element").outerheight(); var bottom_of_screen = $(window).scrolltop() + $(window).height(); if((bottom_of_screen > top_of_element) && (bottom_of_screen < bottom_of_element)){ // element visible, console.log('visible'); } else { console.log('not visible'); // element not visible, else } }); }) html, body { padding:0; margin:0; } .header { background:blue; position:fixed; height:100px; width:100%; color:white; text-align:center; z-index:9999; } .element { height:calc(100vh - 100px); background:wheat; } } ...

Android Realm one to many relationship, query -

i have 2 classes: public class employee extends realmobject { @primarykey long id; string name department department; //getters setters etc. } public class department extends realmobject { @primarykey int id; string name; //getters setters etc. } it 1 many relationship. 1 department can have multiple employees. i've tried make queries. realm.where(employee.class).equalto("department.name", "deptname").findall() realm.where(department.class).equalto("employee.name", "empname").findall() the first 1 working, second 1 has error: invalid query: employee not refer class. how make second 1 work? must make realmlist of employees in department class? i wanted in query fetch departments have employee specified name. realm 3.5.0+: public class employee extends realmobject { @primarykey long id; string name department department; //getters setters etc. } public cla...

php - Consecutive find/replace with regexp -

this question has answer here: how replace occurrences of 2 substrings str_replace()? 3 answers say want erase quote string, , replace spaces '&', in php. 2 consecutive preg_replace or like, how in 1 passage? " columns="4" link="file" ids="280,281,282,283,284,285,286,287,288"" to: columns=4&link=file&ids=280,281,282,283,284,285,286,287,288 you don't need regex that. str_replace() should work fine: $string = 'columns="4" link="file" ids="280,281,282,283,284,285,286,287,288"'; $replaced = str_replace([' ', '"'], ['&', ''], $string); demo: https://3v4l.org/ghhmp

javascript - Angular Add/Remove class on mouseOvered from the .ts file -

i using angular 4 , have div on html template: <div [class.mycssclass]="mouseovered" (mouseout)="mouseovered=false" (mouseover)="mouseovered=true">hover me</div> this works great same thing .ts component file instead. how can .ts component file? according me, best way use hostlistener. for component listen on on mouse events can use: @component({ selector: 'my-component' template: '<div [class.mycssclass]="mouseover"' }) class mycomponent { mouseover:boolean; @hostlistener('mouseover') onmouseover() { this.mouseover = true; } @hostlistener('mouseout') onmouseout() { this.mouseover = false; } }

reactjs - .simulate('click') only working when done twice on the same component, through ID and Class -

i have gone through existing issues , not find 1 similar this. i have button element so, sits within <contact/> component testing: <div> ... <button id="contact-button-submit" classname="btn btn-primary btn-lg" onclick={this.handlesubmit}>submit</button> ... </div> and here test: it('calls handlesubmit when submit button clicked', () => { let wrapper = shallow(<contact {...mockprops} />); wrapper.instance().handlesubmit = jest.fn(); let { handlesubmit } = wrapper.instance(); expect(handlesubmit).tohavebeencalledtimes(0); wrapper.find('#contact-button-submit').simulate('click'); // simulate click want wrapper.find('.btn-primary').simulate('click'); // simulate click had add expect(handlesubmit).tohavebeencalledtimes(1); }); the funny thing that, when include first simulate click (the id one), test fails @ last expect. onclick function (handlesubmi...

c++ - 2D vector sort using pointer arithmetics -

new c++, need sort 2d vector std::vector<std::vector<char>> text2d32; where char in question std::vector<char>wap(32); but std::sort(text2d32.begin(), text2d32.end()); is slow. suggested use pointer arithmetics, don't know how. have working code or function can copy?

using normal requests for telegram API -

i have used telegram bot api. api easy. send request(as json) server , server respond our request json , process json. want use telegram api (not bot) , read many topics api on telegram site still don't know how use api's method. example in bot api sending message make curl request address below: api.telegram.org/bot{toke}/sendmessage?chat_id=45654&text=hello but don't know how use main api. presented list of methods , gave me 2 ip address don't know how use methods. tl language used in api? how can use it? why can't use normal requests? how should start using telegram api? how can test telegram api? simple method.

PHP, button to control display image in an array -

i have php-code, reading images folder array. need display images, 1 one, controlled button. past part of php, displaying 1 of images, test code working. need code display 1 of images @ time, stop each image-displayed, , continue when next-button clicked. loop of kind, button controll displaying of images. can show me how done ? the code this: <!doctype html> <html> <body> <?php // open directory $mydirectory = opendir("images"); // each entry while($entryname = readdir($mydirectory)) { $dirarray[] = $entryname; sort($dirarray); } // close directory closedir($mydirectory); // count elements in array $indexcount = count($dirarray); ?> <?php $index = 7; echo '<li><img src='.$dirarray[$index].' '; ?> </body> </html>

python - ipyparallel's LoadBalancedView bloats memory, how can I avoid that? -

this issue may related https://github.com/ipython/ipyparallel/issues/207 not marked solved, yet. opened issue here https://github.com/ipython/ipyparallel/issues/286 i want execute multiple tasks in parallel using python , ipyparallel in jupyter notebook , using 4 local engines executing ipcluster start in local console. besides 1 can use directview , use loadbalancedview map set of tasks. each task takes around 0.2 seconds (can vary though) , each task mysql query loads data , processes it. working ~45000 tasks works fine, however, memory grows high. bad because want run experiment on 660000 tasks can't run anymore because bloats memory limit of 16 gb , memory swapping on local drive starts. however, when using directview memory grows relatively small , never full. need loadbalancedview . when running minimal working example without database query happens (see below). i not familiar ipyparallel library i've read logs , caches ipcontroler may cause this. still no...

spring boot - Embedded tomcat not launching -

i wanted upgrade spring boot 1.5.6 boot 1.4.3. created simple web project using spring initializer , added simple controller class. pom.xml <parent> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-parent</artifactid> <version>1.5.6.release</version> <relativepath/> <!-- lookup parent repository --> </parent> <properties> <project.build.sourceencoding>utf-8</project.build.sourceencoding> <project.reporting.outputencoding>utf-8</project.reporting.outputencoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</artifactid> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>...