Sunday, 28 April 2019

vba - Create a conditional formating macro for text value on Excel

Very often I need to create conditional formating rules on my excel worksheets, not always on the same range, to format the text color depending on what's written.



The most common situation is turning all the cells in the range that have the text "Effective" green and bold, and "Not effective" red and bold.



I tried to create this macro using the Record Macro function on the Developer tab, but it didn't work, the code was blank.




As I have zero knowledge on VBA, I was wondering if somebody could give me a help creating this macro.



Definitions:




  • There's no fixed range, it needs to capture the selected range;

  • Format based on text, if "Effective" green and bold, if "Not effective" red and bold.

  • Only for one sheet.




[Solved]



Sub EffectiveNot()
'
' EffectiveNot Macro
'
Dim rStart As Range
Set rStart = Selection
Selection.FormatConditions.Add Type:=xlTextString, String:="Effective", _

TextOperator:=xlContains
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
.Color = -11489280
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Selection.FormatConditions.Add Type:=xlTextString, String:="Not effective", _

TextOperator:=xlContains
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
.Color = -16776961
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
End Sub

intel - Haswell microarchitecture don't have Stalled-cycles-backend in perf

I installed perf on Haswell CPU( Intel Core i7-4790 ). But the "perf list" does not include "stalled-cycles-frontend" nor "stalled-cycles-backend". I checked the http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html and not found the performance events relevant to stalled-cycles-backend from the Table 19-7( Non-Architectural Performance Events In the Processor Core of 4th Generation Intel Core Processors).



So my question is: how can I measure stalled-cycles-backend using perf or other tools in Haswell CPU cores. The kernel is 3.19 and perf version is also 3.19.



Thanks

java - Adding int to short





A colleague of mine asked this question to me and I am kind of confused.



int i = 123456;
short x = 12;


The statement



x += i;



Compiles fine however



x = x + i;


doesn't



What is Java doing here?


Answer




int i = 123456;
short x = 12;
x += i;


is actually



int i = 123456;
short x = 12;
x = (short)(x + i);



Whereas x = x + i is simply x = x + i. It does not automatically cast as a short and hence causes the error (x + i is of type int).







A compound assignment expression of the form E1 op= E2 is equivalent to E1 = (T)((E1) op (E2)), where T is the type of E1, except that E1 is evaluated only once.



- JLS §15.26.2




stargate - Why do you need 6 points to define a location in 3 dimensional space? - Movies & TV



Dr. Daniel Jackson is Stargate:





...seven points to outline a course to a position...to find a destination within any three dimensional space, you need six points to determine the exact location...but to chart a course, you need a point of origin




Why do you need 6? Shouldn't 3 suffice? Was this purely a plot device or the biggest blunder in the history of Hollywood? (I am leaving out the third possibility, that I am missing something entirely)


Answer



I'm sorry but most of the answers here are incorrect. The original observation made by the person asking the question is correct. In 3 dimensional space, only three unique co-ordinates are needed to describe an objects exact location relative to a known point of origin.



A good real-life example of this, which proves that point - is that GPS devices are designed to track your location with a minimum of three satellite signals in range. GPS co-ordinates do use more satellites than that to improve accuracy, but that is not because having more reference co-ordinates makes them more accurate, it is because having more RADIO signals reduces the impact of noise and other interference on the that distorts one of the signals it is tracking.



Imagine your assistant is sitting in the backseat on the passenger side of your car, and you need to tell him the exact location of a cup of coffee you left on your dash board. You could use the following reference co-ordinates:




Front Bumper (X axis coordinate)
Drivers side-view mirror (Y axis coordinate)
Windshield Wipers (Z axis coordinate)



Now, from the passenger side back seat if you were to move your hand towards all three of those object, without moving past any of them, you will arrive at a location that sits in front of you, at the height of the windshield wipers, in the direction of the driver's seat, and that would be the dashboard of the vehicle in the corner closest to the driver's window. Adding 3 more reference points would not make it any more accurate, because it doesn't matter how many directions you measure from, as long as you have enough reference points to choose from.



However, I think that 3 million possible address combinations and 38 reference points is accurate enough when you are talking about galactic travel. If more accurate was needed, they would have to use symbols on the gates, but the addresses would still only need 3 symbols and a point of origin to work!



For those of you who believe the other answers that argue that 6 points plus a point of reference is logical; I can understand why you might come to that conclusion but you are over thinking it... and you are wrong. If you were to eliminate the point of origin from the equation, then you would need to 6 coordinates, just because you would need 3 coordinates for each point (one set for your point of origin and one set for your destination). Hollywood obviously did not understand the math, and misinterpreted how coordinates work in three dimension space.




Another way you can see how illogical that would be, would be to take a two dimensional map and mark two points... then figure out how to describe the position of one point relative to the other. According to Stargate logic, you would need one coordinate for your point of origin, and then four points for the destination (one point on each side of the destination forming a square, instead of the cube they used in the movie for 3 dimensional space). I promise, when you are done, you will feel pretty stupid. It won't take you more than a couple seconds to realize that finding four reference points to describe one location on a 2 Dimensional map is completely stupid.



And for those of you who are die-hard over thinkers, you do not need an agreed center or universal axis, or reference orientation to make this work using one coordinate per dimension, plus your point of origin; as long as you ensure that every destination has at least three reference points around it which are all further away from the destination than they are to the point of origin (I won't get into the math or explain that part in detail, but the reason is that you need to draw three separate vectors going all the way past the destination from three different angles, so that the distance between the object remains equal to the distance between the point of origin and the intersection of the three points).


Saturday, 27 April 2019

overriding 'virtual void ' c++ error

The following code gives me an error.




Error: overriding 'virtual void Animal::getClass()', where it says virtual void getClass() { cout << "I'm an animal" << endl; }




Error: conflicting return type specified for 'virtual int Dog::getClass()', where it says getClass(){ cout << "I'm a dog" << endl; }




Also, it says:




Class 'Dog' has virtual method 'getClass' but non-virtual destructor





#include 
#include
#include
#include
#include
#include // srand, rand
#include

using namespace std;


class Animal{

public:
void getFamily(){ cout << "We are animals " << endl;}

virtual void getClass() { cout << "I'm an animal" << endl; }
};

class Dog : public Animal{


public:
getClass(){ cout << "I'm a dog" << endl; }

};

void whatClassAreYou(Animal *animal){

animal -> getClass();

}


int main(){

Animal *animal = new Animal;
Dog *dog = new Dog;

animal->getClass();
dog->getClass();

whatClassAreYou(animal);

whatClassAreYou(dog);


return 0;
}

java - what's a simple and elegant way to print arraylist elements separated by comma?

Hi I'm writing code to print all elements from an ArrayList separated by comma, the folllowing is the method I wrote. It works. But i'm wondering if it can be simplified? And is there a more elegant way to print all elements from an ArrayList separated by some delimiter? (e.g. a method that prints an ArrayList of Strings get "Tom, Sherlock, Jack")




Thanks everyone!



public String printMyArrayList() {
if(mylist.size() == 0)return "";
else if(mylist.size() == 1)return mylist.get(0).toString();
else {
String returnStr = "";
for (int i = 0; i < mylist.size() ; i++) {
if(i == 0)returnStr = mylist.get(i).toString();
else {

returnStr = returnStr + ", " + mylist.get(i).toString();
}
}
return returnStr;
}
}

identify this movie - Sci-fi film: American teen science project brings people and dinosaurs into present - Movies & TV






I'm hoping someone can help me identify the following film that I would have seen in the early 90's or late 80's. It is a film in the era of Weird Science, Flight of the Navigator and Explorers.



All I really remember is that some American teens build a science project which seems to be able to control time or manipulate time. Different characters from different time periods are brought into their own.



One scene I remember which I think is towards the end of the film involves the teens going into their school or university to where this device is located. When they get to the main hall the area has been transformed into a Jurassic jungle environment complete with dinosaurs.



One other very random clip I remember is a scene whereby a bunch of Hells Angels style bikers arrive or are summoned by this device ( I'm hoping this isn't bleed-through from another film...)



Any ideas?


Answer




My Science Project (1985)




... After Michael and his friends plug it into a power source, it
begins to materialize objects from other times and dimensions.



When
his science teacher (Dennis Hopper) experiments by plugging the orb
directly into the power grid, it starts a chain reaction that warp the
dimensions and time around it. Past, present and future collide in a

whirling vortex which engulfs the school and only Michael and his
friends can stop it.





From a YouTube clip:




Dinosaur



php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...