Java system properties and environment variables

System properties are set on the Java command line using the -Dpropertyname=value syntax. They can also be added at runtime using System.setProperty(String key, String value) or via the various System.getProperties().load() methods. To get a specific system property you can use System.getProperty(String key) or System.getProperty(String key, String def). Environment variables are set in the OS, e.g. … Read more

What’s the use/meaning of the @ character in variable names in C#?

Straight from the C# Language Specification, Identifiers (C#) : The prefix “@” enables the use of keywords as identifiers, which is useful when interfacing with other programming languages. The character @ is not actually part of the identifier, so the identifier might be seen in other languages as a normal identifier, without the prefix. An … Read more

Difference between declaring variables before or in loop?

Which is better, a or b? From a performance perspective, you’d have to measure it. (And in my opinion, if you can measure a difference, the compiler isn’t very good). From a maintenance perspective, b is better. Declare and initialize variables in the same place, in the narrowest scope possible. Don’t leave a gaping hole … Read more

@ variables in Ruby on Rails

title is a local variable. They only exists within its scope (current block) @title is an instance variable – and is available to all methods within the class. You can read more here: http://strugglingwithruby.blogspot.dk/2010/03/variables.html In Ruby on Rails – declaring your variables in your controller as instance variables (@title) makes them available to your view.

How do I put a variable’s value inside a string (interpolate it into the string)?

Using f-strings: plot.savefig(f’hanning{num}.pdf’) This was added in 3.6 and is the new preferred way. Using str.format(): plot.savefig(‘hanning{0}.pdf’.format(num)) String concatenation: plot.savefig(‘hanning’ + str(num) + ‘.pdf’) Conversion Specifier: plot.savefig(‘hanning%s.pdf’ % num) Using local variable names (neat trick): plot.savefig(‘hanning%(num)s.pdf’ % locals()) Using string.Template: plot.savefig(string.Template(‘hanning${num}.pdf’).substitute(locals())) See also: Fancier Output Formatting – The Python Tutorial Python 3’s f-Strings: An Improved … Read more

Getting the name of a variable as a string

With Python 3.8 one can simply use f-string debugging feature: >>> foo = dict() >>> f'{foo=}’.split(‘=’)[0] ‘foo’ One drawback of this method is that in order to get ‘foo’ printed you have to add f'{foo=}’ yourself. In other words, you already have to know the name of the variable. In other words, the above code … Read more

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