How do I generate a constructor from class fields using Visual Studio (and/or ReSharper)?

In Visual Studio 2015 Update3 I have this feature. Just by highlighting properties and then press Ctrl + . and then press Generate Constructor. For example, if you’ve highlighted two properties it will suggest you to create a constructor with two parameters and if you’ve selected three it will suggest one with three parameters and so on. … Read more

What is the correct way to write HTML using Javascript?

document.write() will only work while the page is being originally parsed and the DOM is being created. Once the browser gets to the closing </body> tag and the DOM is ready, you can’t use document.write() anymore. I wouldn’t say using document.write() is correct or incorrect, it just depends on your situation. In some cases you … Read more

Is it possible to programmatically compile java source code in memory only?

To start, look at the JavaCompiler API. Basically: Create the Java class in a string. Put the string into class that extends SimpleJavaFileObject. Compile using a JavaCompiler instance. Finally, call the methods the new class. Here is an example that works with JDK6+: import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.lang.reflect.InvocationTargetException; import java.net.URI; import java.util.Arrays; … Read more

Rails migration for has_and_belongs_to_many join table

Where: class Teacher < ActiveRecord::Base has_and_belongs_to_many :students end and class Student < ActiveRecord::Base has_and_belongs_to_many :teachers end for rails 4: rails generate migration CreateJoinTableStudentTeacher student teacher for rails 3: rails generate migration students_teachers student_id:integer teacher_id:integer for rails < 3 script/generate migration students_teachers student_id:integer teacher_id:integer (note the table name lists both join tables in alphabetical order) and … Read more