Scala, repeat a finite list infinitely

Very similar to @Eastsun’s, but a bit more intention revealing. Tested in Scala 2.8. scala> val l = List(1, 2, 3) l: List[Int] = List(1, 2, 3) scala> Stream.continually(l.toStream).flatten.take(10).toList res3: List[Int] = List(1, 2, 3, 1, 2, 3, 1, 2, 3, 1) Alternatively, with Scalaz: scala> import scalaz._ import scalaz._ scala> import Scalaz._ import Scalaz._ … Read more

How can I read an Http response stream twice in C#?

Copy it into a new MemoryStream first. Then you can re-read the MemoryStream as many times as you like: Stream responseStream = CopyAndClose(resp.GetResponseStream()); // Do something with the stream responseStream.Position = 0; // Do something with the stream again private static Stream CopyAndClose(Stream inputStream) { const int readSize = 256; byte[] buffer = new byte[readSize]; … Read more

DataContractSerializer – how can I output the xml to a string (as opposed to a file)

Something like this – put your output into a MemoryStream and then read that back in: public static string DataContractSerializeObject<T>(T objectToSerialize) { using(MemoryStream memStm = new MemoryStream()) { var serializer = new DataContractSerializer(typeof(T)); serializer.WriteObject(memStm, objectToSerialize); memStm.Seek(0, SeekOrigin.Begin); using(var streamReader = new StreamReader(memStm)) { string result = streamReader.ReadToEnd(); return result; } } }

What are the differences between readable and data event of process.stdin stream?

They are two different APIs that allow you to access the same stream of data blocks. The ‘readable’ API was introduced in Node 0.10.0 as part of “Streams 2”, so if you search for that, it should help. The core of the issue is that the ‘readable’ interface allows for much simpler managing and buffering … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)