Saturday, August 31, 2019

Unlocking bitlocker from my hard drive

I was using my hard drive to copy some movies from a friend's laptop. When I inserted the hard drive in my laptop, a prompt message will say that the device is bitlocker protected. I have no idea what bitlocker was. I don't even know why it prompted. I did not even purchase bitlocker.



My problem now is how to unlock it. I have the key as it is shown in that prompt message but I do not know where to get my password. Its not even in my control panel system.




How can I remove the bitlocker from my hard drive? I cannot access my files. All my back up files are there. I hope someone can help me on this. I'm not exactly technology savvy especially when it comes to this kind of software. I hope someone can enlighten me on this one.

c++ - Structure of arrays and array of structures - performance difference



I have a class like this:



//Array of Structures
class Unit
{
public:
float v;

float u;
//And similarly many other variables of float type, upto 10-12 of them.
void update()
{
v+=u;
v=v*i*t;
//And many other equations
}
};



I create an array of objects of Unit type. And call update on them.



int NUM_UNITS = 10000;
void ProcessUpdate()
{
Unit *units = new Unit[NUM_UNITS];
for(int i = 0; i < NUM_UNITS; i++)
{
units[i].update();

}
}


In order to speed up things, and possibly autovectorize the loop, I converted AoS to structure of arrays.



//Structure of Arrays:
class Unit
{
public:

Unit(int NUM_UNITS)
{
v = new float[NUM_UNITS];
}
float *v;
float *u;
//Mnay other variables
void update()
{
for(int i = 0; i < NUM_UNITS; i++)

{
v[i]+=u[i];
//Many other equations
}
}
};


When the loop fails to autovectorize, i am getting a very bad performance for structure of arrays. For 50 units, SoA's update is slightly faster than AoS.But then from 100 units onwards, SoA is slower than AoS. At 300 units, SoA is almost twice as worse. At 100K units, SoA is 4x slower than AoS. While cache might be an issue for SoA, i didnt expect the performance difference to be this high. Profiling on cachegrind shows similar number of misses for both approach. Size of a Unit object is 48 bytes. L1 cache is 256K, L2 is 1MB and L3 is 8MB. What am i missing here? Is this really a cache issue?




Edit:
I am using gcc 4.5.2. Compiler options are -o3 -msse4 -ftree-vectorize.



I did another experiment in SoA. Instead of dynamically allocating the arrays, i allocated "v" and "u" in compile time. When there are 100K units, this gives a performance which is 10x faster than the SoA with dynamically allocated arrays. Whats happening here? Why is there such a performance difference between static and dynamically allocated memory?


Answer



Structure of arrays is not cache friendly in this case.



You use both u and v together, but in case of 2 different arrays for them they will not be loaded simultaneously into one cache line and cache misses will cost huge performance penalty.



_mm_prefetch can be used to make AoS representation even faster.



java - What is the proper way to navigate between windows?





I am trying to make a simple Customer tracking program.It stars with a window with 4 buttons and you choose a task to do.



I need to navigate between different windows
-Home Menu
-New Customer
-Customer

-Reports



What i do is creating different Jframes for each task but i don't know if it is the right way to do.



So my question is What is the proper way to navigate between windows on Java?


Answer



Please do not create multiple JFrames unless absolutely necessary.



Why?





  • There's multiple icons in the taskbar (on Windows and Linux).

  • Switching windows is an added burden to the user.

  • It raises issues with, e.g., the close button (do they all close if any close? is there one master?), etc.



Instead:



Consider using a JTabbedPane.





To create a tabbed pane, instantiate JTabbedPane, create the components you wish it to display, and then add the components to the tabbed pane using the addTab method.




For example:



JTabbedPane tabbedPane = new JTabbedPane();

JComponent someComponent = ...
tabbedPane.addTab("Tab 1", someComponent);


JComponent anotherComponent = ...
tabbedPane.addTab("Tab 2", anotherComponent);





Alternatively, you could use a CardLayout if you only want your users to see one view at a time.





The CardLayout class manages two or more components (usually JPanel instances) that share the same display space. Conceptually, each component that a CardLayout manages is like a playing card or trading card in a stack, where only the top card is visible at any time.



c++ - shared_ptr magic :)




Mr. Lidström and I had an argument :)



Mr. Lidström's claim is that a construct shared_ptr p(new Derived); doesn't require Base to have a virtual destructor:




Armen Tsirunyan: "Really? Will the shared_ptr clean up correctly? Could you please in this case demonstrate how that effect could be implemented?"



Daniel Lidström: "The shared_ptr uses its own destructor to delete the Concrete instance. This is known as RAII within the C++ community. My advice is that you learn all you can about RAII. It will make your C++ coding so much easier when you use RAII in all situations."



Armen Tsirunyan: "I know about RAII, and I also know that eventually the shared_ptr destructor may delete the stored px when pn reaches 0. But if px had static type pointer to Base and dynamic type pointer to Derived, then unless Base has a virtual destructor, this will result in undefined behavior. Correct me if I am wrong."




Daniel Lidström: "The shared_ptr knows the static type is Concrete. It knows this since I passed it in its constructor! Seems a bit like magic, but I can assure you it is by design and extremely nice."




So, judge us. How is it possible (if it is) to implement shared_ptr without requiring polymorphic classes to have virtual destructor?
Thanks in advance


Answer



Yes, it is possible to implement shared_ptr that way. Boost does and the C++11 standard also requires this behaviour. As an added flexibility shared_ptr manages more than just a reference counter. A so-called deleter is usually put into the same memory block that also contains the reference counters. But the fun part is that the type of this deleter is not part of the shared_ptr type. This is called "type erasure" and is basically the same technique used for implementing the "polymorphic functions" boost::function or std::function for hiding the actual functor's type. To make your example work, we need a templated constructor:



template

class shared_ptr
{
public:
...
template
explicit shared_ptr(Y* p);
...
};



So, if you use this with your classes Base and Derived ...



class Base {};
class Derived : public Base {};

int main() {
shared_ptr sp (new Derived);
}



... the templated constructor with Y=Derived is used to construct the shared_ptr object. The constructor has thus the chance to create the appropriate deleter object and reference counters and stores a pointer to this control block as a data member. If the reference counter reaches zero, the previously created and Derived-aware deleter will be used to dispose of the object.



The C++11 standard has the following to say about this constructor (20.7.2.2.1):




Requires: p must be convertible to T*. Y shall be a complete type. The expression delete p shall be well formed, shall have well defined behaviour and shall not throw exceptions.



Effects: Constructs a shared_ptr object that owns the pointer p.



…





And for the destructor (20.7.2.2.2):




Effects: If *this is empty or shares ownership with another shared_ptr instance (use_count() > 1), there are no side effects.
Otherwise, if *this owns an object p and a deleter d, d(p) is called.
Otherwise, if *this owns a pointer p, and delete p is called.





(emphasis using bold font is mine).


indian cinema - Why do Bollywood movies have song and dance sequences?

Unlike Hollywood movies, Bollywood movies are quite different, because they're usually mixed with masala i.e dance, song and love sequences. This is the case in most films which are released in various languages in India.


Can someone explain, Why do Bollywood movies have song and dance sequences?


Answer


There may be quite a few reasons for this



  • There are not many bands that perform music on a large scale, at least not till recently

  • Peer Pressure, everybody is doing it

  • Pressure from Producers / Distributors

  • If Songs become a huge hit and even if the movie is not that great it can still fetch the producers and distributors enough money (Eg The movie 3).

  • The legacy left over from the 1950s, it just refuses to go away .


c# - The name 'ViewBag' does not exist in the current context - Visual Studio 2015



I'm starting to develop in ASP.NET again and I ran into a small error within Visual Studio. My .cshtml files show errors when using a few razor functions. For example "The name 'ViewBag' does not exist in the current context". Here is a picture:




screenshot of problem in visual studio 2015



I am using a demo project. You can find the project here: https://github.com/Wintellect/Angular-MVC-Cookbook/tree/master/BasicProject



I have looked through several other threads and most suggest to update the web.config file(s). These 2 config files are already present and since it's a pretty popular demo I assume it has all the required configuration in it. I have of course looked through these config files and they do indeed include the suggested solutions.



Other details:





  • I have already used clean & rebuild on the solution but that changed nothing.

  • When I create a completely new MVC project it does work

  • My friend has the same problem and we both use VS 2015 and Windows 10

  • I can still run the application and it does work.



Thanks in advance.


Answer



I had this issue despite having all the correct configuration.




It turned out to be some bad files in the Component Cache, preventing the Razor views from recognising ViewBag, Model, and HtmlHelpers. Deleting these files solved the problem (good versions of these files were created next time I opened Visual Studio).



The files are located here:



%LOCALAPPDATA%\Microsoft\VisualStudio\14.0\ComponentModelCache


Delete all four files:





  • Microsoft.VisualStudio.Default.cache

  • Microsoft.VisualStudio.Default.catalogs

  • Microsoft.VisualStudio.Default.err

  • Microsoft.VisualStudio.Default.external



I have subsequently seen the same issue on several other developer machines and this fix quickly solves it.


linux - sed - how to do regex groups using sed



Is there anyway you can do regex match group using sed like java regex pattern/match/group?




if i have string like



test-artifact-201251-balbal-0.1-SNAPSHOT.jar


how do I use sed just to get the result like:



test-artifact-0.1-SNASHOT.jar



I am wondering does sed allow you to do something like java regex, you define the pattern like:



([a-z]*-[a-z]*-)([0-9]*-)([a-z]*-)([.]*SNAPSHOT.jar)


and then you can get the results as an array like:



test-artifact-
201251-

balbal-
0.1-SNAPSHOT.jar

Answer



You have to escape parentheses to group expressions:



\([a-z]*-[a-z]*-\)\([0-9]*-\)\([a-z]*-\)\([.]*SNAPSHOT.jar\)


And use them with \1, \2, etc.







EDIT: Also note just before SNAPSHOT that [.] will not match. Inside brackets . is literal. It should be [0-9.-]*


hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...