How to iterate the List in Reflection

You just need to cast it: var collection = (List<Student>) studentPro.GetValue(studentObj,null); The value returned to you and stored in var is of type object. So you need to cast it to List<Student> first, before trying looping through it. RANT That is why I personally do not like var, it hides the type – unless in … Read more

Python equivalent to perl -pe?

Yes, you can use Python from the command line. python -c <stuff> will run <stuff> as Python code. Example: python -c “import sys; print sys.path” There isn’t a direct equivalent to the -p option for Perl (the automatic input/output line-by-line processing), but that’s mostly because Python doesn’t use the same concept of $_ and whatnot … Read more

String formatting [str.format()] with a dictionary key which is a str() of a number

No. According to the documentation: Because arg_name is not quote-delimited, it is not possible to specify arbitrary dictionary keys (e.g., the strings ’10’ or ‘:-]’) within a format string. So you can’t use strings consisting of numbers as dictionary keys in format strings. Note that your key isn’t numeric, and it’s not trying to use … Read more

How to detect if a process is running using Python on Win and MAC

psutil is a cross-platform library that retrieves information about running processes and system utilization. import psutil pythons_psutil = [] for p in psutil.process_iter(): try: if p.name() == ‘python.exe’: pythons_psutil.append(p) except psutil.Error: pass >>> pythons_psutil [<psutil.Process(pid=16988, name=”python.exe”) at 25793424>] >>> print(*sorted(pythons_psutil[0].as_dict()), sep=’\n’) cmdline connections cpu_affinity cpu_percent cpu_times create_time cwd exe io_counters ionice memory_info memory_info_ex memory_maps memory_percent … Read more

VBA, Combine PDFs into one PDF file

You need to have adobe acrobat installed / operational. I used this resource re method references https://wwwimages2.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/iac_api_reference.pdf EDIT: Swapping the array for auto generated (mostly, the primary pdf still set by user) list of pathways to pdfs that you want to insert into the primary pdf) You can use something like below to generate the … Read more

ActionController::ParameterMissing (param is missing or the value is empty: film):

I have got this problem too when I use Angular JS form to send data to backend Rails 4. When I did not fill anything in angular js form, the error will show ActionController::ParameterMissing (param is missing or the value is empty:. I fix it by adding params.fetch(:film, {}) the strong parameter into: params.fetch(:film, {}).permit(:name, … Read more

pyodbc.connect() works, but not sqlalchemy.create_engine().connect()

A Pass through exact Pyodbc string works for me: import pandas as pd from sqlalchemy import create_engine from sqlalchemy.engine import URL connection_string = ( r”Driver=ODBC Driver 17 for SQL Server;” r”Server=(local)\SQLEXPRESS;” r”Database=myDb;” r”Trusted_Connection=yes;” ) connection_url = URL.create( “mssql+pyodbc”, query={“odbc_connect”: connection_string} ) engine = create_engine(connection_url) df = pd.DataFrame([(1, “foo”)], columns=[“id”, “txt”]) pd.to_sql(“test_table”, engine, if_exists=”replace”, index=False)

Server-Side XML Validation with CXF Webservice

You can override validation error messages, inserting a line number, by using a custom ValidationEventHandler: package example; import javax.xml.bind.ValidationEvent; import javax.xml.bind.helpers.DefaultValidationEventHandler; public class MyValidationEventHandler extends DefaultValidationEventHandler { @Override public boolean handleEvent(ValidationEvent event) { if (event.getSeverity() == ValidationEvent.WARNING) { return super.handleEvent(event); } else { throw new RuntimeException(event.getMessage() + ” [line:”+event.getLocator().getLineNumber()+”]”); } } } If you configure … Read more