Ruby API - JSON Parsing - Writing to file I  get the REST response data from a URL. I then write it to a JSON file, however, it's put it on one line in a long string, and I need to have it in readable format in the JSON file.  My code is:  require 'rubygems' require 'json' require 'rest-client'  class Rest    def self.getData      response = RestClient.get 'http://jsonplaceholder.typicode.com/posts'     response = JSON.parse(response)      File.open('/Users/robertreed/RubymineProjects/draft/posts.json', 'w') do |f|       f.write(response.to_json)     end        puts response      end    getData  end   It's printing to the console and writing to the JSON file on one line:  [{"userId"=&gt;10, "id"=&gt;100, "title"=&gt;"at nam consequatur ea labore ea harum", "body"=&gt;"cupiditate quo est a modi nesciunt}]   Any suggestions on how I could achieve this?
How to "pretty" format JSON output in Ruby on Rails I would like my JSON output in Ruby on Rails to be "pretty" or nicely formatted.   Right now, I call to_json and my JSON is all on one line.  At times this can be difficult to see if there is a problem in the JSON output stream.  Is there way to configure to make my JSON "pretty" or nicely formatted in Rails?
Dual boot Ubuntu (14.04) with Windows 10 In a simple battery + resistor circuit, what form of energy is lost from the electrons upon exiting the resistor? I will give this question a little context. Firstly, as I understand it, as soon as I "close the switch" on a circuit, electric current pretty quickly establishes a steady state where, at any given cross section along a wire, the average kinetic energy of that slice is both constant and equal anywhere along the wire. (Please correct me if I am misunderstanding).   If the average kinetic energy is constant anywhere throughout the wire in the circuit (which confuses me, as I would think that the electrons should all accelerate after exiting the resistor since they are no longer being impeded as much), that means that the average velocity is constant. So, in the example of a simple circuit with a battery of v Volts and a resistor of o Ohms, my question is the following:  Because a 'voltage drop' is known to occur across the resistor, what type energy is being "traded" to generate the heat that radiates from the resistor? I would think that the reflexive answer is "electrical energy"...hence the VOLTAGE drop (the sacrificed energy is clearly not kinetic, as the velocity is constant everywhere). However, I find this confusing. Does this mean that if I had a positive test charge, it would be easier for me to bring it to the beginning of the resistor as compared to bringing it to the end of the resister?     Further, if the correct answer IS "electrical energy", why exactly DOES electrical energy get "dissipated" as the electrons pass through the resistor? I always here the comment Oh! It's because all the electrons are running into densely packed crap which impedes their flow but that to me sounds like a reason for their KINETIC energy to be reduced. However, clearly that's not the case. So, ultimately, I guess the real question is:  **What goes on in the resistor that is literally removing electrical energy **. I am sure that this is a quantum mechanics question, but my quantum mechanics knowledge is not terribly strong. If I could get an answer that is devoid of crazy wave function equations, I would greatly appreciate it. Thanks! How to change XML Attribute How can I change an attribute of an element in an XML file, using C#? If $x_1=5$, $x_{n+1}=x_n^2-2$, find $\lim x_{n+1}/(x_1\cdots x_n)$ The formula for a one sample t-test, as given by  is  $t = \dfrac{\bar{x} - \mu_0}{s\big/\sqrt{n}}$  However, in this equation, if the sample standard deviation, $s$, is zero, $t$ will be undefined. Is there any reasonable way to get a $t$ value in this case? How can I tell if sheet a exists in a workbook? I have the following code that's not working as expected:  If Sheets("a") &lt;&gt; "" Then MsgBox ("sheet a exists")   How can I tell if sheet a exists in the workbook? How to set textbox value in jQuery? MySQL Insert query doesn't work with WHERE clause What's wrong with this query: INSERT INTO Users( weight, desiredWeight ) VALUES ( 160, 145 ) WHERE id = 1;  It works without the WHERE clause. I've seemed to have forgot my SQL. How can I send mail from an iPhone application How do you connect to multiple MySQL databases on a single webpage? I have information spread out across a few databases and want to put all the information onto one webpage using PHP.  I was wondering how I can connect to multiple databases on a single PHP webpage.  I know how to connect to a single database using:  $dbh = mysql_connect($hostname, $username, $password)          or die("Unable to connect to MySQL");   However, can I just use multiple "mysql_connect" commands to open the other databases, and how would PHP know what database I want the information pulled from if I do have multiple databases connected. How to distinguish between American Indians and Indian Indians in native English (language) parlance? How to distinguish between American Indians and Indian Indians in native English (language) parlance?  Can I say Indian Indian to say Indian from Asia compared to the Native Americans? Can I override the Javascript Function object to log all function calls? Permission Denied To Delete File First of all, I'm not looking for an answer on how to remove the files. I am looking for a reason why this doesn't work - and a suggestion on how to remove the files without sudo.  I have a directory in my Desktop that has a few inner directories (don't judge the naming - I just extract what I need from files I'm given) and after getting the files I try and remove the files with rm -rf Bengal\ Tiger\ Creative/, I am surprised to see the following warning for each image.     rm: cannot remove ‘Bengal Tiger Creative/Bengal Tiger Creative/images/customer-services-landscape.jpg’: Permission denied   Below is some code outputs.  tree  nathan@nathan-pc:~/Desktop$ tree . ├── Bengal Tiger Creative │   └── Bengal Tiger Creative │       └── images │           ├── awards.jpg │           ├── blank.gif │           ├── bullet1-light-green.gif │           ├── bullet2-light-green.gif │           ├── bullet3-light-green.gif │           ├── bullet4-light-green.gif │           ├── customer-services-landscape.jpg │           ├── desktop.ini │           ├── header-img1.jpg │           ├── header-img2.jpg │           ├── header-img4.jpg │           ├── header-img5.jpg │           ├── softhr.gif │           ├── Thumbs.db │           ├── tiger_main-img1.jpg │           ├── tiger_main-img2.jpg │           ├── tiger_main-img3.jpg │           ├── tiger_main-img4.jpg │           ├── Vanquis-benefits-icons_iphone-green.gif │           └── white-arrow-green.gif   ls -laR  nathan@nathan-pc:~/Desktop$ ls -laR Bengal* Bengal Tiger Creative: total 12 drwxrwxr-x 3 nathan nathan 4096 Aug 10 11:30 . drwxr-xr-x 6 nathan nathan 4096 Aug 10 11:34 .. drwxrwxr-x 3 nathan nathan 4096 Aug 10 11:34 Bengal Tiger Creative  Bengal Tiger Creative/Bengal Tiger Creative: total 12 drwxrwxr-x 3 nathan nathan 4096 Aug 10 11:34 . drwxrwxr-x 3 nathan nathan 4096 Aug 10 11:30 .. dr-xr-xr-x 2 nathan nathan 4096 Aug 10 11:36 images  Bengal Tiger Creative/Bengal Tiger Creative/images: total 356 dr-xr-xr-x 2 nathan nathan   4096 Aug 10 11:36 . drwxrwxr-x 3 nathan nathan   4096 Aug 10 11:34 .. -rwxrwxrwx 1 nathan nathan  14910 Mar 18 12:29 awards.jpg -rw-rw-r-- 1 nathan nathan   1093 Mar 21  2014 blank.gif -rw-rw-r-- 1 nathan nathan   1978 May  8  2014 bullet1-light-green.gif -rw-rw-r-- 1 nathan nathan   1969 May  8  2014 bullet2-light-green.gif -rw-rw-r-- 1 nathan nathan   2416 May  8  2014 bullet3-light-green.gif -rw-rw-r-- 1 nathan nathan   2449 May  8  2014 bullet4-light-green.gif -rw-rw-r-- 1 nathan nathan 113138 Apr 14  2014 customer-services-landscape.jpg -r--r--r-- 1 nathan nathan    142 Mar 25 11:58 desktop.ini -rw-rw-r-- 1 nathan nathan  14312 Mar 23 11:39 header-img1.jpg -rw-rw-r-- 1 nathan nathan   1480 Mar 23 11:41 header-img2.jpg -rw-rw-r-- 1 nathan nathan   1278 Mar 23 11:41 header-img4.jpg -rw-rw-r-- 1 nathan nathan   1168 Mar 23 11:41 header-img5.jpg -rw-rw-r-- 1 nathan nathan   1703 Mar 21  2014 softhr.gif -rw-rw-r-- 1 nathan nathan  88064 Aug  4 10:39 Thumbs.db -rw-rw-r-- 1 nathan nathan  23607 Mar 23 11:56 tiger_main-img1.jpg -rw-rw-r-- 1 nathan nathan  23400 Mar 23 11:56 tiger_main-img2.jpg -rw-rw-r-- 1 nathan nathan   6970 Mar 23 11:56 tiger_main-img3.jpg -rw-rw-r-- 1 nathan nathan   8996 Mar 23 11:57 tiger_main-img4.jpg -rw-rw-r-- 1 nathan nathan    275 Jul 31  2014 Vanquis-benefits-icons_iphone-green.gif -rw-rw-r-- 1 nathan nathan   1821 Jul  9  2014 white-arrow-green.gif   Doing chmod 777 and then delete does not work.  Doing rm -rf * inside the directory does not work.  Doing sudo rm file does work.   I can easily remove these files using sudo, however, I cannot see why they cannot be removed without sudo. As a relatively new Ubuntu user, I would like to learn why.  Thanks in advance, Nathan Centering figure captions in IEEEtran I am working on a paper using the IEEEtran template in LyX.  I have run into a problem: While the contents (in this case, a table) of the figure float are centered, the caption is aligned to the left (see screenshot below). How can I center the caption as well?    This is generated by the following LyX document:    What I've tried:   Center the table (the table is centered) Center all the contents in the float (only the table is centered) Select the caption and center it (no effect)   Technical details:   LyX 2.0.5.1 Mac OS X 10.7.5 (Lion) All centering was performed by Right Click>Paragraph Settings>Align: Center Often, TeX outputs underfull hbox and vbox warnings when running and in the generated log file. What are these and how can I get rid of them? Unbiased estimator of a uniform distribution How to sort Wrapper list? I have a wrapper class which contains a list of sobjects, i want to have th sorting on the fields of these objects in the wrapper list: The apex code is as follows:  Class jobsWrapper {     public JobSuite__Job__c job { get; set; }     public JobSuite__Job_Task__c jobTasks { get; set; }      public JobsWrapper(JobSuite__Job__c objjobs, JobSuite__Job_Task__c objjobTasks) {         // if(jobTasks== NULL){jobTasks = new List&lt;Job_Task__c&gt;();}         job = objjobs;         jobTasks = objjobTasks;      }      public JobsWrapper() {         if(jobTasks== NULL) {             jobTasks = new JobSuite__Job_Task__c();         }          if(job == NULL) {             job = new JobSuite__Job__c();         }             } }   I want to allow sorting the wrapper list by the fields in the job - like client, jobname, jobnumber etc and fields from the task object as taskname, reviseddue dateetc.  How can I do this? Please help, thanks in advance. So a company decides to raise money by selling shares of its stock. The stock is offered at an initial price of their determination. The stock is then traded in a market where forces of supply and demand, as well as speculation, affect its price.  When a company performs well (or makes decisions that will likely increase the company's earnings in the future), more people want to buy that stock than do people wanting to sell it. This creates demand for that stock which causes its sell/bid prices rise. When a company performs poorly, the opposite occurs; more people want to sell the stock than want to buy. This creates a surplus that causes sell/bid prices to fall.  Understanding this, people speculate over company performance to determine the future behavior of a stock, and attempt to "buy low, sell high" or "borrow high, return low" in order to make a profit.  But my question is regarding the first part of that process. What is it about company performance that causes the perceived value of its stock to rise? This is especially perplexing since I would guess that most people don't exercise their voting rights, and many stocks don't pay dividends.  It's not like a shareholder has any direct financial gains from increased company earnings (speculative stock pricing notwithstanding).  What is the intrinsic value of the stock?  It seems to me that all participants in a stock market tacitly agree that stock price will have a direct correlation with company performance. So another way of asking the question is, would an opposite agreement hold? What financially (this isn't a question about logistics, communication, or feasibility) stops all participants in a market from agreeing to value a particular company's stock inversely with respect to the company's performance?  Since I feel like I can't quite nail down my question, another form of it would be, why is stock market behavior driven by company performance? Sum of indepedent random variables and a constant Let $X_1$ and $X_2$ be independent Normal random variables with mean $\mu_1$ and $\mu_2$, and variances $\sigma_1$ and $\sigma_2$. Let $Y = X_2-X_1 + c$, where $c$ is a constant. For notational simplicity, let $Y = X' + c$, where $X' = X_2-X_1$ The moment generating function of a Normal random variable $X_n\sim N(μ_n,σ_n^2)$ is $$M_{X_n } (t)=\text{exp}\Big(μ_n t+\frac{σ_n^2 t^2}{2}\Big)$$ Then, $$M_{X'} (t)=\text{exp}\Big[t(\mu_1+\mu_2)+\frac{t^2}{2}(\sigma^2_1+\sigma^2_2)\Big]$$ Thus, by the uniqueness property of moment generating function, $X'$ is said to follow a Normal distribution with mean $(\mu_1+\mu_2)$ and variance $(\sigma^2_1+\sigma^2_2)$. How do I proceed from here to derive the following:  First, I want to establish that $Y$ is also a Normal random variable using the moment generating function. The constant $c$ bugs me, but I cannot ignore it. As per my understanding, $Y\sim N\big(c+\mu_1+\mu_2,\sigma^2_1+\sigma^2_2\big)$ (and I could be completely wrong). But I don't understand how to apply the moment generating function to prove that.  Secondly, I want to derive $P(Y \leq a)$, where $a$ is a constant. If I am not mistaken, $P(Y \leq a)$ can be written as $$P(Y \leq a)=\Phi\Bigg(\frac{a-X_2-X_1 + c}{\sqrt{2(\sigma^2_1+\sigma^2_2)}}\Bigg).$$ But how do I arrive at that.   Any help is high solicited and appreciated. How to edit 'etc/hosts' file in non-rooted phone?