|
{"instruction": "I'm trying to create an object that can be used in three different ways, and each time it's used it should return a different value. I want to use the same object to fulfill each condition. How can I do this?", "response": "If you take advantage of how == works, you could simply create an object with a custom ```toString``` (or ```valueOf```) function that changes what it returns each time it is used such that it satisfies all three conditions.\n```\nconst a = {\n i: 1,\n toString: function () {\n return a.i++;\n }\n}\n\nif(a == 1 && a == 2 && a == 3) {\n console.log('Hello World!');\n}\n```\n\nThe reason this works is due to the use of the loose equality operator. When using loose equality, if one of the operands is of a different type than the other, the engine will attempt to convert one to the other. In the case of an object on the left and a number on the right, it will attempt to convert the object to a number by first calling ```valueOf``` if it is callable, and failing that, it will call ```toString```. I used ```toString``` in this case simply because it's what came to mind, ```valueOf``` would make more sense. If I instead returned a string from ```toString```, the engine would have then attempted to convert the string to a number giving us the same end result, though with a slightly longer path.", "score": 5} |
|
{"instruction": "What is the purpose behind the novel structure of Moby-Dick?", "response": "There are multiple purposes behind the novel structure of Moby-Dick.\n\nIn the first instance the author was himself a whaleman, having spent 18 months as an ordinary seaman aboard the whaler Acushnet in 1841–42. In his experience the literature of the day, such as Miriam \n\nCoffin or The Whale-Fisherman by Joseph Hart, did not portray whaling accurately but rather sensationalised it. He wished to provide his readers with a more realistic account.\n\nIn doing so, he also gave the reader the information necessary to better understand and appreciate the passages of whaling described in the novel. With the reader forewarned, he is able to keep the narrative passages tense and exciting. It is interesting that, early in the novel, the Pequod meets virutally no whales and that the chases become longer and more involved as the story progresses. This may be because Melville felt he needed to give the reader more and more technical information before they could fully appreicate these encounters, but understood the science would need to be spaced out among the narrative.\n\nIn describing it to the reader, the science also serves another useful narrative function. It indicates that on whaling voyages, long periods of time pass when nothing much happens at all. By padding out of the story with scientific digressions serves as a useful narrative metaphor for waiting.\n\nThe level of detail provided also mirrors one of the novel's central themes: obsession. Although Ishmael is the narrator and Ahab the obvious obsessive, the amount of science indicates that Ishmael is also an obsessive. His obsession is the business of whaling itself.\n\nFinally, Melville made good use of these passages in serving as metaphors for other themes of the novel where he felt it appropriate. For example in the chapter The Line, which describes how the whale line is stored and used in the boat, it ends by using the line as a metaphor.\n\n \"All men live enveloped in whale-lines. All are born with halters round their necks; but it is only when caught in the swift, sudden turn of death, that mortals realize the silent, subtle, ever-present perils of life.\"", "score": 5} |
|
{"instruction": "I'm trying to run a python script on a mac. How do I tell the shell to run a python script?", "response": "In order to run the python script, we need to tell the shell three things:\n\n* That the file is a script\n* Which interpreter we want to execute the script\n* The path of said interpreter\n\nThe shebang ```#!``` accomplishes (1.). The shebang begins with a ```#``` because the ```#``` character is a comment marker in many scripting languages. The contents of the shebang line are therefore automatically ignored by the interpreter.\nThe ```env``` command accomplishes (2.) and (3.). To quote "grawity,"\n\n> A common use of the ```env``` command is to launch interpreters, by making use of the fact that env will search $PATH for the command it is told to launch. Since the shebang line requires an absolute path to be specified, and since the location of various interpreters (perl, bash, python) may vary a lot, it is common to use: ```#!/usr/bin/env perl``` instead of trying to guess whether it is /bin/perl, /usr/bin/perl, /usr/local/bin/perl, /usr/local/pkg/perl, /fileserver/usr/bin/perl, or /home/MrDaniel/usr/bin/perl on the user's system... \n\n> On the other hand, env is almost always in /usr/bin/env. (Except in cases when it isn't; some systems might use /bin/env, but that's a fairly rare occassion and only happens on non-Linux systems.)", "score": 5} |
|
{"instruction": "I have a repository with a lot of commits, but the author and committer are wrong. Is there a way to change all commits to have the correct author and committer?", "response": "Here is the solution, but be careful if you have a multi-user repository - this will change all commits to have the same (new) author and committer.\n```\ngit filter-branch -f --env-filter \"\n GIT_AUTHOR_NAME='Newname'\n GIT_AUTHOR_EMAIL='new@email'\n GIT_COMMITTER_NAME='Newname'\n GIT_COMMITTER_EMAIL='new@email'\n \" HEAD\n```\n\nChanging the author (or committer) would require rewriting all of the history. If you're okay with that and think it's worth it then you should check out git filter-branch. The manual page includes several examples to get you started. Also note that you can use environment variables to change the name of the author, committer, dates, etc. -- see the \"Environment Variables\" section of the git manual page.\n\nSpecifically, you can fix all the wrong author names and emails for all branches and tags with this command (source: GitHub help):\n```\n#!/bin/sh\n\ngit filter-branch --env-filter '\nOLD_EMAIL=\"[email protected]\"\nCORRECT_NAME=\"Your Correct Name\"\nCORRECT_EMAIL=\"[email protected]\"\nif [ \"$GIT_COMMITTER_EMAIL\" = \"$OLD_EMAIL\" ]\nthen\n export GIT_COMMITTER_NAME=\"$CORRECT_NAME\"\n export GIT_COMMITTER_EMAIL=\"$CORRECT_EMAIL\"\nfi\nif [ \"$GIT_AUTHOR_EMAIL\" = \"$OLD_EMAIL\" ]\nthen\n export GIT_AUTHOR_NAME=\"$CORRECT_NAME\"\n export GIT_AUTHOR_EMAIL=\"$CORRECT_EMAIL\"\nfi\n' --tag-name-filter cat -- --branches --tags\n```\nFor using alternative history filtering tool `git filter-repo`, you can first install it and construct a `git-mailmap` according to the format of `gitmailmap`.\n```\nProper Name <[email protected]> Commit Name <[email protected]>\n```\nAnd then run filter-repo with the created mailmap:\n```\ngit filter-repo --mailmap git-mailmap\n```", "score": 5} |
|
{"instruction": "What is the most fun thing to do in Minecraft?", "response": "The thing about Minecraft is, unlike most games you set your own goals. Here's a list of common (and uncommon!) things people have done with Minecraft:\n\n* Building a massive structure\n* Recreating real-world objects\n* Survival (Deleting map upon dying)\n* Making amusing videos\n* Creating an adventure map for others to play\n* Getting all the achievements\n* Proposing to your girlfriend\n* Achieving difficult things in the game through ingenuity\n* Computation\n* Blowing stuff up!\n\nThe mechanism that keeps the game going is your own desire to complete the goals you've set yourself, and pure, red-hot addiction.\n\nSome additional stuff people have done:\n\n* Walking and walking and walking (thanks SevenSidedDie)\n* Build an epic railway\n* Make music\n* Find the Far Lands\n\nMinecraft 1.9+\nIn Minecraft 1.9 and beyond, there are villages, strongholds, abandoned mineshafts and nether ruins to explore. In particular, strongholds will contain portals to The End, in which players can fight The Ender Dragon, a 'boss fights'. The second 'boss fight' has also been added, The Wither. This makes exploration a key part of the game, as well as combat. 'Hardcore Mode' (world deletion upon death) is also an option if you're after a challenge.\nA creative mode has also been added that allows players complete freedom in constructing large structures, compartmentalizing that aspect of gameplay.", "score": 5} |
|
{"instruction": "Why does China want to devalue their currency while Turkey doesn't? What is the difference in motivation between the two?", "response": "Trade surplus/deficit\nDevaluing one's currency means mostly one thing: It becomes more expensive to import products from abroad, while one's own products become comparably cheaper to buy on the world market. That means a country which exports lots of goods wants to devalue their currency while a country which imports lots of goods does not.\nIn 2016, Turkey imported goods worth US $186 billion and exported goods worth US $156 billion. That means they had a trade deficit of 19%.\nHowever, China only imported goods worth US $1.23 trillion and exported goods worth US $2.27 trillion in 2016. That means they had a trade surplus of 84%.\nWhich is why China wants to devalue their currency while Turkey does not.\nDebt management\nAnother reason to devalue one's currency is that it reduces any debts denoted in that currency. If a country has a problem of too much public and private debt, then an easy way to get rid of it is to cause a hyperinflation. \nChina happens to have a debt-to-gdp ratio of 47.6% while Turkey only has one of 28.3%. When you look at the private debt (debt of private citizens and companies in the country), you see the same picture. Private debit in Turkey was 170% of GDP, while China's is rumored to be over 300%.\nWhich is why reducing debt through causing inflation seems more attractive to China than to Turkey.\nForeign investor relations\nSo why don't all countries get rid of their debt by adding a few zeroes to their bank notes? Because inflating your currency is a surefire way to drive away any foreign investors. Nobody will invest money into your country when that money might be worth nothing in a few years. Investors want stable currencies. Again, we observe the same difference in motivation between Turkey and China here. Turkey is actively inviting foreign investors, but China is quite reluctant to allow foreign economic influence in their country.", "score": 5} |
|
{"instruction": "Can someone be arrested for something they admit to on video?", "response": "Unless the Youtube Video shows them committing a crime, then no, they couldn't be arrested and tried for a crime. Them saying it, not under oath, is just hearsay that has no evidentiary value unless there is already other evidence they have committed a crime. In that case, its an admission. But there must be other, either circumstantial, or actual physical evidence of a crime.\n\nPast intoxication is not a crime, either. Possession of drugs, if caught with them is. But saying you got high is not.\n\nPeople have walked into police stations and confessed to murders. But with no evidence, no body, no name of a missing person, they can't even be held after the holding period for investigatory purposes expires. \n\nIf the video shows them committing assault, or breaking and entering (there actually are idiots who post this stuff), the video is actual evidence of a crime and it is often used against them. The statements can be used to begin an investigation, but people don't usually confess to anything worth pursuing even an investigation. The fact that someone says they used to do something criminal is not enough. For all you ( meaning anyone ) knows, the statute of limitations has expired because they \"pirated games\" 10 years ago. Your comment is right on.", "score": 5} |
|
{"instruction": "What is a pixel shader?", "response": "Simple answer\nPixel shaders are tiny programs that can do operations on a single pixel on the screen, as opposed to geometry shaders and vertex shaders which work on the geometrical primitives (triangles) that make up everything you see on the screen. The most common use for pixel shaders is 'shading', approximation to real world lighting. Commonly used shading model is Phong.\nPixel shaders are executed on your video card, so your video card needs to support them. Each new version provides more capabilities, so an older video card will not run newer shaders. A new version of the pixel shader specification (e.g. Pixel Shader 3.0) is usually released for each new version of DirectX (more accurately, Direct3D).\nSoftware Requirements\nYou need to have the correct version of Direct3D (or OpenGL) installed in order to use the shaders. For example, Pixel Shader 4.0 requires at least Direct3D 10. Normally you don't have to worry about this, every game that uses Direct3D will install the correct version for you when you install the game. The only exceptions are Direct3D 10 and later, which will not run on Windows XP or earlier. You will need at least Windows Vista in order to play a game that uses Direct3D 10 or 11.\nWikipedia provides a nice list of Pixel Shader versions, the version of Direct3D you need, and the types of graphics cards that work with them.\n\nTechnical answer\nThe 'standard' stages of a 3D rendering pipeline are as follows (somewhat simplified):\n\n* Transformation (Moving, rotating and scaling all the objects in the scene)\n* Lighting\n* Projection ('Squashing' the 3D world into a 2D plane)\n* Clipping (Removing anything outside the field of view)\n* Rasterising (Converting the vector graphics (triangles, etc) into raster graphics (pixels))\n* Texturing\n* Display\n\nPixel Shaders are used as an alternative to the standard texturing phase. During rasterisation, each triangle is converted into pixels. These pixels do not have their final colour yet, but the do have a bunch of parameters associated with them. These include base colour, texture coordinates, lighting information, etc. The Pixel Shader is a small program that takes these parameters and uses them to calculate the final colour as it is displayed on the screen. The Pixel Shader has access to all texture data, and can use them to do interesting things such as blending two textures (to create a 'dirty' look), using a texture as a bump map (to simulate a relief), or to simulate reflections.\nHardware\nOn the hardware side, Pixel Shaders are executed on 'Shader Units', small processors on your GPU. Each Shader Unit is basically a very simple CPU, but a modern video card may contain thousands of these things (an AMD Radeon HD6990 contains over 3000). Older GPUs had different Shader Units for different tasks: Pixel Shaders were executed on different parts of the system than Vertex Shaders. Modern GPUs have so called 'unified shader units' which can perform all of these operations.", "score": 5} |
|
{"instruction": "Use a phone or tablet", "response": "## Use a phone or tablet\n\n1. Open your phone or tablet's app store. This is the App Store on iOS and Play Store on Android. Look for the app on your home screen or app menu and tap to open it.\n2. Search for Pure Flix. Tap the search bar and type \"pure flix\".\n3. Tap the Pure Flix App to open it. Check that the publisher is Pure Flix Digital. If you cannot find Pure Flix, you may be on an older software version that is unsupported. Check for a software update in your settings. Pure Flix requires iOS 10.0 or later for iPad, iPhone, iPod Touch, and Apple TV. Pure Flix requires Android 4.2 or higher on Android phones and tablets.\n4. Tap +Get or Install to download the app. You may need to confirm your credentials. The app will be added to your home screen or app menu when finished downloading.\n5. Open the app. Look for a blue icon that says \"Pure Flix\" on your home screen or app menu. Tap the app to open.\n6. Sign in with your Pure Flix username and password. If you do not have an account, sign up for a plan on the Pure Flix website: https://signup.pureflix.com/signup/plans\n\n\n## Use a computer\n\n1. Open a browser on your computer. This can be any standard modern browser, such as Chrome, Safari, Edge, Firefox, and IE11.\n2. Navigate to https://www.pureflix.com/. Type or copy the address in the address bar, or click the link.\n3. Click Sign In. This is in the top right corner of the screen.\n4. Enter your username and password and click Sign In. If you do not have an account, create one by clicking Create an Account.\n5. Use the navigation bar at the top to search or browse for movies and shows. Click on a show or movie to stream it. Cast your browser tab to a TV if you prefer to use a bigger screen by using Chromecast.\n\n\n## Use a smart tv\n\n1. Launch your Smart TV. This may be Apple TV, Amazon Fire, Roku, Samsung Smart TV, or another Smart TV.\n2. Open the app store on your Smart TV. This may be called something different for every Smart TV, but look for an app store on your main home screen.\n3. Search for Pure Flix. Use the app store's search bar and type in \"pure flix\".\n4. Download the Pure Flix app. Look for a button that says Download, Install, or Get.\n5. Launch the app and login. Find the app on your home screen with the other apps for your Smart TV.\n\n\n## Use an xbox one\n\n1. Launch the XBOX dashboard. Start your XBOX one and sign in if you are not already. The dashboard is the home screen that appears when you are signed in.\n2. Open the XBOX Store. Use the left analog stick or directional pad to select the Store tab on the right.\n3. Search for Pure Flix. Navigate down to the search bar and enter in \"pure flix\".\n4. Select the Pure Flix app and select Get. This will install the Pure Flix app on your XBOX One.\n5. Login to your account once installed. You can find this app on your dashboard in the future.", "score": 5} |
|
{"instruction": "Write an acknowledgements section for your thesis.", "response": "Acknowledgments\n\nThe PhD journey at Carnegie Mellon University has been an extremely challenging and yet rewarding experience for me. I would not be able to reach the finish line without the help and love from the wonderful people in my life. Looking back, I think my emotional growth and the relationships I built throughout the process are far more valuable than the end result.\n\nI cannot get to where I am without the guidance of my advisor, [Advisor Name]. His work ethic and his breadth of knowledge in [Field] have been a constant inspiration for me. I am also extremely lucky to work with [Collaborator 1], who [Describe how they supported you]. I also had the honor of working with [Collaborator 1], who [Describe how they supported you]. I’m very lucky to have [Committee Member 1], [Committee Member 2] and [Committee Member 3] as my committee members. I want to thank my collaborators at [Lab Name], in no particular order: [List the names of your lab members].\n\nLast but not least, I would like to thank my family for being the strongest backbone in my life, accepting me for who I am, and loving me without any constraints. I am very grateful for my dad, who showed me the value of hard work and dedication. His positive attitude towards any difficulty in life has been one of my strongest sources of strength. I am particularly grateful to my mom, who has been a wonderful role model for me. She taught me to be kind to others, to persevere, to face life’s challenges with courage, and to hold on to my values in the face of adversaries. This thesis is dedicated to you both.", "score": 5} |
|
{"instruction": "Explain the difference in multitasking between Windows 3.1 and MS-DOS.", "response": "For Win16 programs, Windows implemented co-operative multitasking. Its implementation was based upon the "message loop" architecture of every Windows program.\n\nThe duty of every program was to endlessly run in a loop in which a call to the ```GetMessage``` function was performed. This function call looks whether a message to this process is in the queue. If there is one, it is retrieved (```GetMessage```), optionally translated (```TranslateMessage```, done to convert keyboard shortcuts into menu actions) and finally, passed to the window procedure (```DispatchMessage```).\n\nIf there is no message available in the queue, Windows suspends the current task and gives the CPU to another task. This task will try to retrieve a message from its queue as well, yielding the CPU to another task if no message is present and so on.\n\nIf a program needed to perform background tasks while there were no pending messages in its queue, it would call ```PeekMessage``` instead of ```GetMessage```. This didn't make the task relinquish the CPU, as ```PeekMessage``` would immediately return to the caller task to inform it whether a message is available or not. This was used to time-multiplex message processing with another time-consuming task (think of a 3D program rendering but letting the user cancel that render by pressing a "Cancel" button).\n\nIf this time-consuming task was actually very time-consuming, a well-behaved program should call the ```Yield``` function from time to time, to relinquish the CPU and let other tasks run. A badly-behaved program could easily hog the CPU by not retrieving messages too often or by spending too much time in a window procedure function.\n\nThe situation was quite different for MS-DOS boxes. They ran using the V8086 mode of the 80386 (if Windows was running in enhanced mode). Windows-aware programs ran in the so-called System VM (Virtual Machine 1). DOS boxes ran from VM 2 upwards. DOS programs usually were badly-behaved programs, so Windows assigned each DOS box a different virtual machine. Virtual machines used pre-emptive multitasking in Windows 3.1, so each DOS box could run concurrently to others and to any Windows-aware program.", "score": 5} |
|
|