I have a large buffer of strings (basically 12GB) from a C app.  I would like to create PyString objects in C for an embedded Python interpreter without copying the strings. Is this possible?
I have embedded a Python interpreter in a C program.  Suppose the C program reads some bytes from a file into a char array and learns (somehow) that the bytes represent text with a certain encoding (e.g., ISO 8859-1, Windows-1252, or UTF-8).  How do I decode the contents of this char array into a Python string?  The Python string should in general be of type unicode—for instance, a 0x93 in Windows-1252 encoded input becomes a u'\u0201c'.  I have attempted to use PyString_Decode, but it always fails when there are non-ASCII characters in the string.  Here is an example that fails:  #include &lt;Python.h&gt; #include &lt;stdio.h&gt;  int main(int argc, char *argv[]) {      char c_string[] = { (char)0x93, 0 };      PyObject *py_string;       Py_Initialize();       py_string = PyString_Decode(c_string, 1, "windows_1252", "replace");      if (!py_string) {           PyErr_Print();           return 1;      }      return 0; }   The error message is UnicodeEncodeError: 'ascii' codec can't encode character u'\u201c' in position 0: ordinal not in range(128), which indicates that the ascii encoding is used even though we specify windows_1252 in the call to PyString_Decode.  The following code works around the problem by using PyString_FromString to create a Python string of the undecoded bytes, then calling its decode method:  #include &lt;Python.h&gt; #include &lt;stdio.h&gt;  int main(int argc, char *argv[]) {      char c_string[] = { (char)0x93, 0 };      PyObject *raw, *decoded;       Py_Initialize();       raw = PyString_FromString(c_string);      printf("Undecoded: ");      PyObject_Print(raw, stdout, 0);      printf("\n");      decoded = PyObject_CallMethod(raw, "decode", "s", "windows_1252");      Py_DECREF(raw);      printf("Decoded: ");      PyObject_Print(decoded, stdout, 0);      printf("\n");      return 0; }
Given a sphere of radius $r$ with two spherical caps on it defined by the radii ($a_1$ and $a_2$) of the bases of the spherical caps, given a separation of the two spherical caps by angle $\theta$, how do you calculate the surface area of that intersection?   To clarify, the area is that of the curved surface on the sphere defined by the intersection. At the extreme where both $a_1,a_2 = r$, we would be describing a spherical lune.   Alternatively define the spherical caps by the angles  $\Phi_1 = \arcsin(a_1/r)$ and $\Phi_2 = \arcsin(a_2/r)$. If the imaginary part of an entire function is never zero, the function is constant Let $f : \mathbb{C} \to \{z\in\mathbb{C}:\Im(z)\neq0\} $ entire . Show that $f$ is constant.  I took $g(z)=\frac{1}{f(z)}$ and I think that g is bounded, therefore it is constant (due to Louville's theorem) but how do I prove it? Is $|g(z)|=\frac{1}{|f(z)|}=\frac{1}{u^2+v^2}\le M$ valid? Monitor hard drive changes to files Several months ago I saw someone using an application that showed him files on the computer being modified in real time.  Basically there was an application that wasn't working correctly, so he installed the program, ran the application, and saw all the various files that the application either read from or wrote to.  He found out the application was writing a large debugging file it shouldn't be, which ended up being the problem.  I don't remember the application or the name of the person who used it, but I believe it's a freeware application.  Does anyone know what this program might be? Seven-sided dice from five-sided dice with finite rolls I have a 5-sided dice, and I want to use it to simulate a 7-sided dice. Is there a way to do this with a finite number of rolls? I've somehow lost my id_rsa.pub file. I still have my id_rsa file. How do I recover the public key from the private key?  (This question came up after ssh-copy-id was reporting "ERROR: No identities found" while ssh-keygen reported "/root/.ssh/id_rsa already exists". ls ~/.ssh pointed out the problem was having id_rsa but not id_rsa.pub. I found the solution, but it was buried at the bottom of a long post on an Ubuntu support forum.) How do you show monotonicity of the $\ell^p$ norms? I can't seem to work out the inequality $(\sum |x_n|^q)^{1/q} \leq (\sum |x_n|^p)^{1/p}$ for $p \leq q$ (which I'm assuming is the way to go about it). I'm looking for the title of a short story by Ursula Le Guin about a scientist (?) who is given a drug that slows the timescale of his perception enormously, so that he can perceive that an alien (?) forest is actually behaving as a sentient being, reacting to current events, but at an enormously slow (from a normal human point of view) timescale. It might be in , but I don't remember the title (and it doesn't jump out at me from the list of titles) and don't have access to that collection right now. It is not &quot;The Word for World is Forest&quot;, nor &quot;Direction of the Road&quot; (from ), nor &quot;Vaster than Empires and More Slow&quot;, the latter two of which look at similar plant perception/time-scale issues. Update: it turns out that the description was right, but I had most of the details wrong: not Le Guin, not alien, not a scientist ... I'm trying to identify fantasy book series I encountered some time ago. Here are things I remember:   it was a fantasy setting but with some s-f elements; with many worlds and possibility to travel between them; resembling  setting a little, the two main races were non-human and probably hostile to each other,  a labyrinth (?), which somehow played an important role in the plot, a protagonist was some kind of emissary and was sent on a mission to another worlds  time period: 80s - 90s    Does anyone know what it is the name of the series? I have a couple of illustrations done in Illustrator and I am planing to animate it for a website that I am working on, I've heard of  toolkit with flash, but is it the best way to go or is there another "better" way of doing it?  Here's an example of the kind of animations I am aiming for: Finding specific users by their location and a tag score What is the correct way of installing BOINC software? Can we define flat connection on any given smooth manifold? For example, a sphere $S^2$ in $\mathbf{R}^3$ is apparently not flat with respect to the Euclidean connection, but can we define a flat connection and thus with affine charts on $S^2$? How to fix the weird surface in fluid object I want to prove that $xe^{-x}$ is bounded by some constant for all the $x \in [0, \infty)$. So I take derivative of this guy, and found that on $x \in [0, \infty)$, its derivative is positive from $[0, 1)$, $0$ at $x=1$, and negative from (1, in infinity). So  $xe^{-x}$ achieves its maximum in $[0, \infty)$ at $x=1$, which is $1/e$. However, to prove that it's bounded by $1/e$, I need to prove that as $x$ goes to infinity, $xe^{-x}$ converges to $0$. Because otherwise, if it went to some value below $(-1/e)$, $xe^{-x}$ would not be bounded by $1/e$. How can I prove that $xe^{-x}$ converges to $0$? I mean, as $x$ goes to infinity, $e^{-x}$ converges to zero, but at the same time, x diverges to infinity. How can I formally prove that the product term converges to $0$? Do I need to use the epsilon definition of convergence to prove it?  Could you just show me the formal proof of $xe^{-x}$ converges to $0$? Or is there's any other way to approach this question? My professor suggested that I should use the power series for $e^{-x}$...?   Your help is greatly appreciated! Thank you so much!  I hope you enjoy your Saturday! Font corruption: lines through characters I have a problem where a one-pixel high white line is displayed through certain letters of text. Almost always only a single character type is affected at once, and only in one font size (though that size can change over time). Most of the time things are fine, but this happens several times a day. It happens frequently in Firefox, but system dialogs, menus, etc. can also be affected. It's been happening ever since I upgraded to 10.10. Only restarting seems to fix it.  Two examples (in the first, only the larger "r" is corrupted):     Any help would be appreciated, thanks.  Edit: I've since noticed that I can (sometimes) make the fonts appear correctly by zooming in/out all the way and returning to the default in Firefox (one or two steps, then going back, does nothing) seems to make the problem go away temporarily.  Edit 2: I figure it's worth noting that the solution below doesn't fully work for me any longer (I'm now using Ubuntu 11.10). It does significantly reduce the frequency of this problem occurring.  Edit 3: Still around in 12.04. The fix provided by Vanni works perfectly now for me, but apparently doesn't for some.  Edit 4: This seems to be an xorg problem, with Vanni's answer fixing it for many Intel video cards. I've had this occasionally happen with AMD graphics cards in 13.10 and 14.04, but very rarely (only two or three times). Can truesight see through a druid's Wild Shape? The rules for truesight state:     A creature with truesight can (..) perceive the original form of a shapechanger or a creature that is transformed by magic   A druid player argued that since the druid is still a "humanoid" (not a "shapechanger"), and since , a creature with truesight should not see through it.  As the DM, I ruled against it because I believed the intent of truesight is to see through all kinds of shapechanging effects but I was still left wondering if I missed anything. I couldn't find anything about this in the errata either.  So, going by strict RAW, should a creature with truesight be able to see the druid's true form while a druid is using wild shape? back-up: which patitions to back-up before upgrading/reinstalling I have Ubuntu13.04 on my laptop. I have to upgrade it to the next release or else I would install a fresh release after deleting my current system.  I have already installed and configured my current system a lot and I can't take the burden of doing it all over again if I install the next release. Now I would like to know that what all back-ups are required to be taken beforehand so that I would recover all my files/installations/configurations etc. In other words I should have everything on my new system (simply by restoring from back-ups) that I possess currently.  My current system has /, /boot, /home &amp; swap partitions which were created by me when I had freshly installed the O.S. Combining the second elements of a set of ordered pairs based on their first element Prove that the set of palindromes are not regular languages using the pumping lemma. Firstly I pick a language $xyz$ where $x = \epsilon$, $y = (abb)^{k}$, $z = (bba)^{k}$ where $|y| \ge$ the number of states in the automaton representing my language. Then $xyz = (abb)^k(bba)^k$ is a palindrome.  Now I split $y$ into $uvw$, where $v \ne \epsilon$ contains a state visited more  than once. If the language is regular then $xuv^iwz$ is within the language $\forall i \ge 0$.  I choose $i = 2$, then $uv^2w = (abb)^n$ where $n &gt; k$.  Then $xuv^2wz = (abb)^n(bba)^k$ where $n &gt; k$, which is not a palindrome.   Firstly, is my reasoning for this particular proof correct?  I'm unsure about how to properly apply the pumping lemma to this problem. And secondly the question asks me to state a proof for palindromes in general, whereas I only attempted to prove it for a single case. Is there an example I can choose which proves the conjecture for all palindromes? I assume not, seeing as I can't think of how that could be represented using regular expressions. Why am I still getting a password prompt with ssh with public key authentication?