What's the best way to trim std::string?

What's the best way to trim std::string?

I'm currently using the following code to right-trim all the std::strings in my programs:std::string s;s.erase(s.find_last_not_of(" \n\r\t")+1);It works fine, but I wonder if there are some end-cases where it might fail?Of course, answers w

Strangest language feature

Strangest language feature

What is, in your opinion, the most surprising, weird, strange or really "WTF" language feature you have encountered?Please only one feature per answer. 1:In C, arrays can be indexed like so:a[10]which is very common.However, the lesser k

java.util.NoSuchElementException - Scanner reading user input

java.util.NoSuchElementException - Scanner reading user input

I'm new to using Java, but I have some previous experience with C#. The issue I'm having comes with reading user input from console.I'm running into the "java.util.NoSuchElementException" error with this portion of code:payment = sc.next();

What is the difference between JSF, Servlet and JSP?

What is the difference between JSF, Servlet and JSP?

How are JSP and Servlet related to each other? Is JSP some kind of Servlet? How are JSP and JSF related to each other? Is JSF some kind of prebuild UI based JSP like ASP.NET-MVC? 1:JSP (JavaServer Pages)JSP is a Java view technology runn

Command not found error in Bash variable assignment

Command not found error in Bash variable assignment

I have this script called test.sh:#!/bin/bashSTR = "Hello World"echo $STRwhen I run sh test.sh I get this:test.sh: line 2: STR: command not foundWhat am I doing wrong? I look at extremely basic/beginners bash scripting tutorials online and

How to pass objects to functions in C++?

How to pass objects to functions in C++?

I am new to C++ programming, but I have experience in Java. I need guidance on how to pass objects to functions in C++.Do I need to pass pointers, references, or non-pointer and non-reference values? I remember in Java there are no such iss

Why is the gets function so dangerous that it should not be used?

Why is the gets function so dangerous that it should not be used?

When I try to compile C code that uses the gets() function with GCC,I get thiswarning: (.text+0x34): warning: the `gets' function is dangerous and should not be used.I remember this has something to do with stack protection and security,

commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated

commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated

Sometimes, when using , or , the action, actionListener or listener method associated with the tag are simply not being invoked. Or, the bean properties are not updated with submitted UIInput values.

Anonymous variables in Erlang

Anonymous variables in Erlang

What are the exact differences between underscore variables and a named variable that starts with underscore from the Erlang compiler point of view (apart from adding readability to the code)?For example are _ and _Var different? 1:The d

Check whether one number equals another number in bash

Check whether one number equals another number in bash

I've been trying to compare whether two numbers in Bash are equal (and print a message if they are equal), but I'm getting some strange error messages for this simple program:#!/bin/bashfun2 (){ $x = 3 //#prog.sh: line 4: =: command n

objective C underscore property vs self

objective C underscore property vs self

I'm was playing around with the standard sample split view that gets created when you select a split view application in Xcode, and after adding a few fields i needed to add a few fields to display them in the detail view.and something inte

Generic vs not-generic performance in C#

Generic vs not-generic performance in C#

I've written two equivalent methods:static bool F(T a, T b) where T : class{ return a == b;}static bool F2(A a, A b){ return a == b;}Time difference: 00:00:00.0380022 00:00:00.0170009Code for testing:var a = new A();for (int i = 0; i

profiling a method of a class in Python using cProfile?

profiling a method of a class in Python using cProfile?

I'd like to profile a method of a function in Python, using cProfile. I tried the following:import cProfile as profile# inside class method...profile.run("self.myMethod()", "output_file")but it does not work. How can I call a self.method w

Angular JS $watch vs $on

Angular JS $watch vs $on

I want to execute a function inside a directive, whenever there is a state change in the parent scope.The obvious way to achieve this is to use event broadcasts ($broadcast) and listeners ($on).I am curious if using a $watch is an alternati

reinterpret_cast cast cost

reinterpret_cast cast cost

My understanding is that C++ reinterpret_cast and C pointer cast is a justa compile-time functionality and that it has no performance cost at all.Is this true? 1:It's a good assumption to start with. However, the optimizer may be restric

Tuning MySQL for speedy column/index creation during development

Tuning MySQL for speedy column/index creation during development

Assume a MySQL MyISAM table with one gigabyte of data and one gigabyte of indexes.Furthermore, assume that during development columns and indexes will be added and removed from/to the table quite frequently. Due to the size of the database

How do I source environment variables for a command shell in a Ruby script?

How do I source environment variables for a command shell in a Ruby script?

I'm trying to run some third party bash scripts from within my ruby program. Before I can run them they require me to source a file. On the command line it all works fine but within Ruby it doesn't work. I've found out that system commands

Use environment variables in Rake task

Use environment variables in Rake task

task :some_task, :environment do |t, args| puts Rails.env #=> development, production, etc puts ENV #=> {}endI set some environment variables (either via a local .env, or via Heroku Config via Herokusan), such as which AWS bucket to use,

PHP, HTML: Submit form automatically [closed]

PHP, HTML: Submit form automatically [closed]

I have a PHP page with an HTML form on it. If some variables are set in the URL I would like to automatically submit the form on the page.IE:if (isset($_GET['var'])){ // SUBMIT FORM}else{ // leave the page alone}EDIT:Here is what I have u

PHP Variable vs Array vs Object

PHP Variable vs Array vs Object

This is probably considered a really silly question, but I'm in the process of putting together a simple template system for a website and am trying to keep track of my variable usage and keep everything neat and tidy.Can you tell me if the

Commenting Conventions

Commenting Conventions

I want to know what are some guidelines for commenting? I am coding in Java for class. I want to have readable code. In another question I was told "how" comments should be reserved for difficult sections of code. I was told that my code co

Cannot load any more object with static TLS

Cannot load any more object with static TLS

I have an application that use dlopen() to load additional modules. The application and modules are built on Ubuntu 12.04 x86_64 using gcc 4.6 but for i386 arch. The binaries are then copied to another machine with exactly same OS and work

XSL: passing variables between templates

XSL: passing variables between templates

Is it possible to pass a variable from one parent template to its child element ? this template will match: You see I wanna use var as var1 in the matched template.How can I make this work?edit:the structure is like this:

Dojo AMD: Can't call a function inside a require

Dojo AMD: Can't call a function inside a require

I am really a newbie to dojo but as i started developing a new application with dojo version 1.7.2 i also wanted to use the new AMD syntax for functions. Unfortunately i don't seem to get it. :-( What annoys me most is that i can't simply

Generate a random UIColor

Generate a random UIColor

I try to get a random colors for UILabel...- (UIColor *)randomColor{ int red = arc4random() % 255 / 255.0; int green = arc4random() % 255 / 255.0; int blue = arc4random() % 255 / 255.0; UIColor *color = [UIColor colorWithRed:red