Java: String concat vs StringBuilder – optimised, so what should I do?

I think the use of StringBuilder vs + really depends on the context you are using it in. Generally using JDK 1.6 and above the compiler will automatically join strings together using StringBuilder. String one = “abc”; String two = “xyz”; String three = one + two; This will compile String three as: String three … Read more

Golang concurrency: how to append to the same slice from different goroutines

There is nothing wrong with guarding the MySlice = append(MySlice, &OneOfMyStructs) with a sync.Mutex. But of course you can have a result channel with buffer size len(params) all goroutines send their answers and once your work is finished you collect from this result channel. If your params has a fixed size: MySlice = make([]*MyStruct, len(params)) … Read more

jQuery append text

The proper way to append text (constrast with appending HTML) would be: var someText = “Hello, World!”; $(‘#msg’).append(document.createTextNode(someText)); If someText is coming from user input or anything else, it will be properly HTML-escaped. Which should prevent JavaScript injection, the 3rd most common web security vulnerability in the world. From https://stackoverflow.com/a/944456/122441

Getting access to a jquery element that was just appended to the DOM

You can do this: var el = $(‘<a href=”#”>test</a>’); $(“#div_element”).append(el); el.click(function(){alert(“test”)}); // or preferrably: el.on(‘click’, function(){alert(“test”)}); The append function accepts two types of arguments: a string or a jQuery element. In case a string is passed in, it will create a jQuery element internally and append it to the parent element. In this case, you … Read more

C# Append byte array to existing file

One way would be to create a FileStream with the FileMode.Append creation mode. Opens the file if it exists and seeks to the end of the file, or creates a new file. This would look something like: public static void AppendAllBytes(string path, byte[] bytes) { //argument-checking here. using (var stream = new FileStream(path, FileMode.Append)) { … Read more