Stack Overflow

Subscribe to Stack Overflow feed
most recent 30 from 2017-11-22T13:16:57Z
Updated: 9 hours 3 min ago

eclipse does't execute java projects since installing maven

Sun, 11/19/2017 - 11:15

I have a few Java projects that I ran them several times correctly in eclipse. Now after I installed Maven in eclipse, when I want to run them via run configuration and searching each one's name in type filter text field, it doesn't show the project to choose.

Trim the names in the list using Groovy

Sun, 11/19/2017 - 11:09

I have a list in Groovy which contains the names in the below format:

  • My_name_is_Jack
  • My_name_is_Rock
  • My_name_is_Sunn

How can I trim the list and get only the last part of it; i.e. Names - Jack, Rock and Sunn. (Please note that the names are only 4 characters long)

typescript method override does not work

Sun, 11/19/2017 - 10:54

I have a baseclass A and an extended class B that overrides A's fetch method. However when I call B.fetch() it logs 'baseclass'. Why doesn't it call the method definition defined in B?

class A { protected apiPath: string = '' static async fetch (id = null, Model = this, apiPath = this.apiPath): Promise<any> { console.log('basefetch') let url = apiPath if(id) url += '/' + id let { data } = await axios.get(url) let item: any = new Model(data) return item } } class B extends A { static async fetch(id = null, Model = this, apiPath = this.apiPath): Promise<Data> { console.log('childfetch') let {data} = await axios.get(apiPath) if (typeof data.challenge.participating == 'undefined') { data.challenge.participating = null } if (typeof data.challenge.progress == 'undefined') { data.challenge.progress = null } return new Model(data) } let b: B = B.fetch()

Are there any implicit converters 'out of the box' with C# .Net?

Sun, 11/19/2017 - 10:42

As per title, does C# .Net offer any implicit converters or are the only implicit converters available the ones that we developers define?

I thought maybe the following would've been a good use-case, for example:

var myObject = new object(); String myString = myObject;

Or, in fact, most types being assigned to a string.

Draw a text with orientation is upright and mode is vertical-rl in canvas html5

Sun, 11/19/2017 - 10:31

I have a text in html with below css:

.overlay-imageOrientation-left { font-size: 20px; text-orientation: upright; writing-mode: vertical-rl; color: #ffffff; position: absolute; top: 45%; left: 3px; }

How can i draw this text in canvas html5 with text-orientation: upright and writing-mode: vertical-rl ?

How do you gradually accelerate an object based on button press (Ogre3D)?

Sun, 11/19/2017 - 06:40

I currently have an object that I want to gradually accelerate. The longer you hold down on a certain key, the faster it goes. I managed to get it to work fine for one key (when it moves right) however, it does not seem to work for the other directions.

The code I have right now is:

if (mKeyboard->isKeyDown(OIS::KC_NUMPAD8)) { mSpeed += mAcceleration*evt.timeSinceLastFrame; movement.z -= mSpeed*evt.timeSinceLastFrame; mAcceleration++; } if (mKeyboard->isKeyDown(OIS::KC_NUMPAD4)) { mSpeed += mAcceleration*evt.timeSinceLastFrame; movement.x -= mSpeed*evt.timeSinceLastFrame; mAcceleration++; } if (mKeyboard->isKeyDown(OIS::KC_NUMPAD5)) { mSpeed += mAcceleration*evt.timeSinceLastFrame; movement.z += mSpeed*evt.timeSinceLastFrame; mAcceleration++; } if (mKeyboard->isKeyDown(OIS::KC_NUMPAD6)) { mSpeed += mAcceleration*evt.timeSinceLastFrame; movement.x += mSpeed*evt.timeSinceLastFrame; mAcceleration++; }

And the statement that works fine is the last one. The rest just move normally, without any acceleration.

I was wondering how I can get the object to gradually accelerate at the other directions as well.

P.S Just in case anyone is wondering as well, I cannot change the "if"s to "while". The program does not run at all when I change it.

P.P.S The object works (gradually accelerates in all directions) when I change the others to "else if" however, I can no longer move diagonally which is also my problem. I have tried doing something such as

else if (mKeyboard->isKeyDown(OIS::KC_I) && mKeyboard->isKeyDown(OIS::KC_J)) { mSpeed += mAcceleration *evt.timeSinceLastFrame; movement.z -= mSpeed*evt.timeSinceLastFrame; movement.x -= mSpeed*evt.timeSinceLastFrame; mAcceleration++; }

but it still does not move diagonally.

How to moves Divs using Jquery?

Sat, 11/18/2017 - 23:56

$(document).ready(function() { $("button.primary").click(function() { $("div.hero1").animate({ left: '550px', opacity: '0.5', height: '150px', width: '150px' }); }); }); body{ background-image: url(; } h1 .title { z-index: 101; color: white; bottom: 200px; } .character { position: absolute; z-index: 90; color: white; top: 230px; } .hero1{ width: 230px; height: 170px; background-color: blue; float: left; display: inline-block; font-size: 20px; position: relative; } div img{ width: 100%; height: auto; } .skywalker { z-index:100; position:absolute; color:white; font-size:24px; font-weight:bold; top: 130px; left: 40px; background-color: black; width: auto; } .r2 { z-index:100; position:absolute; color:white; font-size:24px; font-weight:bold; top: 130px; left: 310px; background-color: black; width: auto; } .hero2{ width: 230px; height: 170px; background-color: red; float: left; display: inline-block; overflow: hidden; } .r2d2 { margin-top: -20px; } .hero3{ width: 230px; height: 170px; background-color: blue; float: left; display: inline-block; overflow: hidden; } .storm{ margin-top: -12px; } .stormtrooper{ z-index:100; position:absolute; color:white; font-size:24px; font-weight:bold; top: 130px; left: 515px; background-color: black; width: auto; } .hero4{ width: 230px; height: 170px; background-color: red; float: left; display: inline-block; overflow: hidden; } .palpatine { z-index:100; position:absolute; color:white; font-size:24px; font-weight:bold; top: 130px; left: 740px; background-color: black; width: auto; } .darth{ margin-top: -25px; } .primary { position: absolute; z-index: 101; bottom: 550px; left: 10px; } <!doctype html> <html> <head> <link rel="stylesheet" type="text/css" href="starwars.css"> <link rel="stylesheet" href="" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous"> </head> <body> <h1><span class="badge badge-secondary title">Star Wars RPG!</span></h1> <div class="wrapper"> <h2 class="character">Your Character</h2> <div class="hero1"> <img src="file:///Users/vitamind/Desktop/Bootcamp/Starwars/Assets/Images/luke%20(1).jpg"> <h2 class="skywalker">Luke Skywalker</h2> </div> <div class="hero2"> <img class="r2d2" src="file:///Users/vitamind/Desktop/Bootcamp/Starwars/Assets/Images/ivok_r2d2_popcorn_maker_inuse.jpg"> <h2 class="r2">R2D2?</h2> </div> <div class="hero3"> <img class="storm" src="file:///Users/vitamind/Desktop/Bootcamp/Starwars/Assets/Images/13353670_Alt02.jpeg"> <h2 class="stormtrooper">Storm Trooper</h2> </div> <div class="hero4"> <img class="darth" src="file:///Users/vitamind/Desktop/Bootcamp/Starwars/Assets/Images/emperor-palpatine-star-wars-battlefront-iii-73.5.jpg"> <h2 class="palpatine">Darth Sidious</h2> </div> <button type="button" class="btn btn-primary primary">Attack</button> </div> <script src="starwars.js"></script> </body> </html>

Hello, does anyone know why my div boxes are not moving with the Jquery animation? I am not sure if I need to add the position tag in my css, I have tried to mess with the position tag but I am not sure. When I click on the button nothing happens. I am tagging the button and the div through their respective classes.

Getting nullpointer exception sending data from activity to fragment onCreate

Sat, 11/18/2017 - 23:56

I've been trying to send a string of data from my activity to a fragment using bundle but when I try to access it, it gives a nullpointerexception.

The oncreate method in the activity looks like this

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_chart); // Setup toolbar and title Toolbar toolbar = (Toolbar) findViewById(; setSupportActionBar(toolbar); readDb(); printChart(); printTop10(); Bundle bundle = new Bundle(); bundle.putString("edttext", myString); // set Fragmentclass Arguments ToolbarFragment fragobj = new ToolbarFragment(); fragobj.setArguments(bundle); }

and the fragment on the onCreateView looks like this

@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { String strtext = getArguments().getString("edttext"); // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_toolbar, container, false); }

any help to get rid of the nullpointer would be appreciated, I'm trying to send data to the fragment so it can use the share button and share the data

Alogrithm to find the next earliest time

Sat, 11/18/2017 - 23:56

You have a watch that displays the current time in 24 hr format. You look at the digits used to display the time and wonder what is the next earliest time that can be displayed using the same subset of digits?

Write a function that given a non-empty string S in "HH:MM" the function should return a string T in the same format specifying the time after the current minute that can be represented by a subset of the digits of S.

Ex given "11:00" your function should return "11:01", for "23:59" the result should be "22:22".

Bootstrap list items with multiple columns. Weird behaviour (includes JSBIN)

Sat, 11/18/2017 - 23:56

I'm try to list some items in multiple columns. Bootstrap keeps making weird formatting.

Here's the JSBin:,css,output

<div class="row"> <div class="col-xs-12"> <div class="well"> <strong>Checkbox list:</strong> <div class="row checklist"> <div class="checkbox col-xs-6 col-sm-4 col-md-3 col-lg-2"> <label style="white-space: nowrap;"><input type="checkbox">Check box 1</label> </div> more checkboxes.... </div> </div>

How to click on a Cell object?

Sat, 11/18/2017 - 23:55

I'm using Javascript, p5.js, and Daniel Shiffman's tutorial to create a visual representation of an A* search algorithm.

An image of an example grid looks like this: example grid

Is it possible to click on any cell of the grid, in order to print out it's attributes? Based on Daniel Shiffman's other tutorial on how to click on objects, I understand I have to create 2 functions that activate and execute respectively. I understand how to do this with a circle because a circle has a radius.

But, I don't understand how to do this with a cell because I only have it's coordinates. I can't see how to use coordinates as a metric to calculate length.

I'd appreciate any guidance to my thinking. Thank you so much in advance.

Estimation of adjusted risk difference Complex Survey data

Sat, 11/18/2017 - 23:55

I wish to estimate adjusted risk difference (instead of adjusted Odds Ratio) for complex survey data. Need syntax (either Stata or R)

Removing element that was already used from array in JavaScript

Sat, 11/18/2017 - 23:54

I want my program to flip cards until I get a Spade. And it's working, but some of array value's are logging again. I tried indexOf() and splice() method for removing used cards from deck, but it is not working. Maybe somebody can help me with that or suggest other method?

let cards = ['2 Diamond', '2 Spade', '2 Heart', '2 Club', '3 Diamond', '3 Spade', '3 Heart', '3 Club', '3 Diamond', '3 Spade', '3 Heart', '3 Club']; // deck of cards let currentCard = cards[Math.floor(Math.random() * cards.length)]; while (!currentCard.includes('Spade')) { console.log(currentCard); let idx = cards.indexOf(currentCard); // trying to get index of current card cards.splice(idx, 1); // splice is not removing used card currentCard = cards[Math.floor(Math.random() * cards.length)]; } console.log('Spade!');

Issues converting image to base64 with Swift 3

Sat, 11/18/2017 - 23:54

I am attempting to upload an image to imgur and hoping to get a url of the image back. Imgur requires and incoming images to be either a binary file, base64 data, or a URL for an image. I am converting an image to base64 and am getting an error stating that it is an invalid file type.

Here is my code:

let imageData = UIImagePNGRepresentation(checkView.image!) let base64Image = imageData?.base64EncodedString(options: .lineLength64Characters) let urlPath = "" let url = URL(string:urlPath) var request = URLRequest(url: url!) request.setValue("Client-ID 850d2551cd2cdaa", forHTTPHeaderField: "Authorization") request.httpMethod = "POST" // create post string with username and password let postString = "image=" + base64Image! request.httpBody = .utf8) let task = URLSession.shared.dataTask(with: request) { data, response, error in guard let data = data, error == nil else { // check for fundamental networking error print("Data empty or error=\(String(describing: error))") return } if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode != 405 { // check for http errors print("statusCode should be 200, but is \(httpStatus.statusCode)") print("response from status code = \(String(describing: response))") } // store data let json = try? JSONSerialization.jsonObject(with: data, options: []) as! [String:Any] let responseString = NSString(data: data, encoding: String.Encoding.utf8.rawValue) // printing feedback print("responseString = \(responseString)") print("--------------------------------") print(json) print("--------------------------------") } task.resume() }

and the response I'm getting:

statusCode should be 200, but is 415 response from status code = Optional(<NSHTTPURLResponse: 0x1c0225280> { URL: } { Status Code: 415, Headers { "Access-Control-Allow-Origin" = ( "*" ); "Cache-Control" = ( "no-store, no-cache, must-revalidate, post-check=0, pre-check=0" ); "Content-Length" = ( 174 ); "Content-Type" = ( "application/json" ); Date = ( "Sat, 18 Nov 2017 23:14:27 GMT" ); Server = ( nginx ); "access-control-allow-headers" = ( "Authorization, Content-Type, Accept, X-Mashape-Authorization, IMGURPLATFORM, IMGURUIDJAFO, SESSIONCOUNT, IMGURMWBETA, IMGURMWBETAOPTIN" ); "access-control-allow-methods" = ( "GET, PUT, POST, DELETE, OPTIONS" ); "access-control-expose-headers" = ( "X-RateLimit-ClientLimit, X-RateLimit-ClientRemaining, X-RateLimit-UserLimit, X-RateLimit-UserRemaining, X-RateLimit-UserReset" ); "x-post-rate-limit-limit" = ( 1250 ); "x-post-rate-limit-remaining" = ( 1246 ); "x-post-rate-limit-reset" = ( 3039 ); } }) responseString = Optional({"data":{"error":{"code":1003,"message":"File type invalid (2)","type":"ImgurException","exception":{}},"request":"\/3\/upload","method":"POST"},"success":false,"status":415}) Optional(["status": 415, "data": { error = { code = 1003; exception = { }; message = "File type invalid (2)"; type = ImgurException; }; method = POST; request = "/3/upload"; }, "success": 0]) -------------------------------- nil --------------------------------

How to select the records from one table which is not matching with the other two tables

Sat, 11/18/2017 - 23:54

I have one master table emp1 table with 3 columns and 3 rows as you can see below

empid empname empsal 1 a 100 2 b 300 3 c 500

second table emp2 with 3 columns and 1 row

empid empname empsal 1 a 100

suppose, if I have to pick the records which are only available in the first table but not in second table then I can use the below query

select * FROM emp1 b LEFT JOIN emp2 f ON f.empid = b.empid WHERE IS NULL

but here I have third table emp3 with 3 columns and 1 row

empid empname empsal 2 b 300

if I have to pick the records which are available in the first table only, but not in second and third table, what could be the best solution?

Please answer this questions if anyone knows, thanks in advance!!

If you have any questions please let me know

Bug with recording and playing recorded audio live into headphones simultaneously in iOS

Sat, 11/18/2017 - 23:50

I am facing a problem when trying to record and play that same audio live simultaneously (so essentially you will hear yourself talking immediately)...

This feature is specifically found and works in apple's aurio touch sample app, but I cannot make heads or tails out of it.

I have found this code online, but it doesn't seem to work, but I can't figure out what is wrong with it.

Thank you so much for your help in advance.

import UIKit import AVFoundation extension String { func stringByAppendingPathComponent(path: String) -> String { let nsSt = self as NSString return nsSt.stringByAppendingPathComponent(path) } } class ViewController: UIViewController, AVAudioPlayerDelegate, AVAudioRecorderDelegate{ var audioPlayer : AVAudioPlayer! var audioRecorder : AVAudioRecorder! @IBOutlet var recordButton : UIButton! @IBOutlet var playButton : UIButton! @IBOutlet var stopButton : UIButton! override func viewDidLoad() { super.viewDidLoad() self.recordButton.enabled = true self.playButton.enabled = false self.stopButton.enabled = false } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } //MARK: UIButton action methods @IBAction func playButtonClicked(sender : AnyObject){ let dispatchQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) dispatch_async(dispatchQueue, { if let data = NSData(contentsOfFile: self.audioFilePath()) { do{ self.audioPlayer = try AVAudioPlayer(data: data) self.audioPlayer.delegate = self self.audioPlayer.prepareToPlay() } catch{ print("\(error)") } } }); } @IBAction func stopButtonClicked(sender : AnyObject){ if let player = self.audioPlayer{ player.stop() } if let record = self.audioRecorder{ record.stop() let session = AVAudioSession.sharedInstance() do{ try session.setActive(false) } catch{ print("\(error)") } } } @IBAction func recordButtonClicked(sender : AnyObject){ let session = AVAudioSession.sharedInstance() do{ try session.setCategory(AVAudioSessionCategoryPlayAndRecord) try session.setActive(true) session.requestRecordPermission({ (allowed : Bool) -> Void in if allowed { self.startRecording() } else{ print("We don't have request permission for recording.") } }) } catch{ print("\(error)") } } func startRecording(){ self.playButton.enabled = false self.recordButton.enabled = false self.stopButton.enabled = true do{ let fileURL = NSURL(string: self.audioFilePath())! self.audioRecorder = try AVAudioRecorder(URL: fileURL, settings: self.audioRecorderSettings() as! [String : AnyObject]) if let recorder = self.audioRecorder{ recorder.delegate = self if recorder.record() && recorder.prepareToRecord(){ print("Audio recording started successfully") } } } catch{ print("\(error)") } } func audioFilePath() -> String{ let path = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)[0] let filePath = path.stringByAppendingPathComponent("test.caf") as String return filePath } func audioRecorderSettings() -> NSDictionary{ let settings = [AVFormatIDKey : NSNumber(int: Int32(kAudioFormatMPEG4AAC)), AVSampleRateKey : NSNumber(float: Float(16000.0)), AVNumberOfChannelsKey : NSNumber(int: 1), AVEncoderAudioQualityKey : NSNumber(int: Int32(AVAudioQuality.Medium.rawValue))] return settings } //MARK: AVAudioPlayerDelegate methods func audioPlayerDidFinishPlaying(player: AVAudioPlayer, successfully flag: Bool) { if flag == true{ print("Player stops playing successfully") } else{ print("Player interrupted") } self.recordButton.enabled = true self.playButton.enabled = false self.stopButton.enabled = false } //MARK: AVAudioRecorderDelegate methods func audioRecorderDidFinishRecording(recorder: AVAudioRecorder, successfully flag: Bool) { if flag == true{ print("Recording stops successfully") } else{ print("Stopping recording failed") } self.playButton.enabled = true self.recordButton.enabled = false self.stopButton.enabled = false } }

escaping the greater than and less than symbols in javascript [duplicate]

Sat, 11/18/2017 - 23:44

This question already has an answer here:

The code I have currently produces a html page with with "ac" on it, what I want is to have literally what the value of the string is (I would type it out here but I'm having the same problem). In words, what I want is "a" then the less than symbol then "b" then the greater than symbol then "c".


<!DOCTYPE html> <html> <body> <p id="output"></p> <script> document.getElementById("output").innerHTML = "a<b>c" </script> </body> </html>

Apply custom function in Pandas, passing values multiple columns

Sat, 11/18/2017 - 23:42

I am having trouble "applying" a custom function in Pandas. When I test the function, directly passing the values it works and correctly returns the response. However, when I attempt to pass the column values, I receive the error "The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()."

def feez (rides, plan): pmt4 = 200 inc4 = 50 #number rides included min_rate4 = 4 if plan == "4 Plan": if rides > inc4: fee = ((rides - inc4) * min_rate4) + pmt4 else: fee = pmt4 return (fee) else: return 0.1 df['fee'].apply(feez(df.total_rides, df.plan_name))

Passing the values directly works, i.e. feez (800, "4 Plan"), returns 3200

However, I receive errors when I try to apply the function above.

I am a newbie and suspect my syntax is poorly written. Any ideas much appreciated. TIA. Eli

Parity of a number (Assembly)

Sat, 11/18/2017 - 23:39

So I'm trying to separate an octet by parity and I don't quite understand how the conditional jumps work(I tried it separately and I don't understand how it works it)

Here is what I came up with:

bits 32 global start extern exit,printf import exit msvcrt.dll import printf msvcrt.dll segment data use32 class=data s db '1', '2', '3', '4','5','7','8','9' ; declararea sirului initial s l equ $-s ; stabilirea lungimea sirului initial l d1 times l db 0 d2 times 1 db 0 format db "%s", 0 segment code use32 class=code start: mov ecx, l mov esi, 0 jecxz Sfarsit Repeta: ;loop so it gets all the elements from s mov al, [s+esi] mov bl,al sub bl,'0' cmp bl,2; if is even adds it to d1 JP et2 mov [d1+esi], al inc esi et2: mov bl,al sub bl,'0' cmp bl,2; if is odd adds it to d2 JP et1 mov [d2+esi], al inc esi et1: loop Repeta Sfarsit: ;terminarea programului ;Daca dorim si afisarea sirului d, avem urmatoarele: push dword d1 ; punem parametrii pe stiva de la dreapta la stanga push dword format call [printf] ;apelam functia printf add esp, 4 * 2 ; eliberam parametrii de pe stiva ; exit(0) push dword d2 ; punem parametrii pe stiva de la dreapta la stanga push dword format call [printf] ;apelam functia printf add esp, 4 * 2 ; eliberam parametrii de pe stiva ; exit(0) push dword 0 ; push the parameter for exit onto the stack call [exit] ; call exit to terminate the program

I think the problem is the JP but I'm not completely sure.

Negative values while converting hex color in rgba (JavaScript)

Sat, 11/18/2017 - 23:33

My problem is to convert a hexadecimal color string, with alpha value, and obtain the four channels R G B A. The lenght of the string is 8 (for example: 4faabbaa)

I've tried the following code, with bitwise operators, to convert the string and obtain the rgba.

var hex = "4faabbaa"; //In this case R is correct (79) var hexint = parseInt(hex, 16); var r = hexint >> 24; var g = (hexint & 0x00FF0000) >> 16; var b = (hexint & 0x0000FF00) >> 8; var a = hexint & 0x000000FF;

The code works for all values of G B and A channels but, for some R values, returns negative values.

For example if I use:

var hex = "ccaabbaa"; //In this case returns a negative R (-52)

Returns a negative value for R