Makefile to put object files from source files different directories into a single, separate directory?

There’s more than one way to do it, but this is a pretty good one (I really should have that hotkeyed). vpath %.cpp ../src src = Foo.cpp Bar.cpp test_src = Main.cpp FooTest.cpp BarTest.cpp objects = $(patsubst %.cpp,obj/%.o,$(src)) test_objects = $(patsubst %.cpp,obj/%.o,$(test_src)) $(objects): | obj obj: @mkdir -p $@ obj/%.o : %.cpp @echo $< @$(CXX) $(CXXFLAGS) … Read more

Using JavaScript what’s the quickest way to recursively remove properties and values from an object?

A simple self-calling function can do it. function removeMeta(obj) { for(prop in obj) { if (prop === ‘$meta’) delete obj[prop]; else if (typeof obj[prop] === ‘object’) removeMeta(obj[prop]); } } var myObj = { “part_one”: { “name”: “My Name”, “something”: “123”, “$meta”: { “test”: “test123” } }, “part_two”: [ { “name”: “name”, “dob”: “dob”, “$meta”: { … Read more

Find object having maximum value for the `id` property in an array of objects

The question states that he wants to find the object with the greatest id, not just the greatest id… var myArray = [{‘id’:’73’,’foo’:’bar’},{‘id’:’45’,’foo’:’bar’}]; var max = myArray.reduce(function(prev, current) { if (+current.id > +prev.id) { return current; } else { return prev; } }); // max == {‘id’:’73’,’foo’:’bar’}

Comparing Integer objects [duplicate]

For reference types, == checks whether the references are equal, i.e. whether they point to the same object. For primitive types, == checks whether the values are equal. java.lang.Integer is a reference type. int is a primitive type. Edit: If one operand is of primitive type, and the other of a reference type that unboxes … Read more

C#: System.Object vs Generics

Always use generics! Using object’s results in cast operations and boxing/unboxing of value-types. Because of these reasons generics are faster and more elegant (no casting). And – the main reason – you won’t get InvalidCastExceptions using generics. So, generics are faster and errors are visible at compile-time. System.Object means runtime exceptions and casting which in … Read more