SQLAlchemy + SQL Injection

tldr: Avoid raw SQL as much as possible. The accepted answer is lazy and incorrect. The filter method accepts raw SQL, and if used in that way, is fully susceptible to SQL injection attacks. For instance, if you were to accept a value from a url and combine it with raw sql in the filter, … Read more

How can I create an utility class? [duplicate]

For a completely stateless utility class in Java, I suggest the class be declared public and final, and have a private constructor to prevent instantiation. The final keyword prevents sub-classing and can improve efficiency at runtime. The class should contain all static methods and should not be declared abstract (as that would imply the class … Read more

Speeding up pandas.DataFrame.to_sql with fast_executemany of pyODBC

EDIT (2019-03-08): Gord Thompson commented below with good news from the update logs of sqlalchemy: Since SQLAlchemy 1.3.0, released 2019-03-04, sqlalchemy now supports engine = create_engine(sqlalchemy_url, fast_executemany=True) for the mssql+pyodbc dialect. I.e., it is no longer necessary to define a function and use @event.listens_for(engine, ‘before_cursor_execute’) Meaning the below function can be removed and only the … Read more

How to disable “just my code” setting in VSCode debugger?

Just adding “justMyCode”: false to launch.json doesn’t work. You need to add a separate config in launch.json like below. FYI each {} represents a config. “configurations”: [ { …. # existing config }, { “name”: “Debug Unit Test”, “type”: “python”, “request”: “test”, “justMyCode”: false, } ] As pointed out in here

Convert 4 bytes to int

ByteBuffer has this capability, and is able to work with both little and big endian integers. Consider this example: // read the file into a byte array File file = new File(“file.bin”); FileInputStream fis = new FileInputStream(file); byte [] arr = new byte[(int)file.length()]; fis.read(arr); // create a byte buffer and wrap the array ByteBuffer bb … Read more

onSharedPreferenceChanged not fired if change occurs in separate activity?

The OnSharedPreferenceChangeListener gets garbage collected in your case if you use an anonymous class. To solve that problem use the following code in PreferenceActivity to register and unregister a change listener: public class MyActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener { @Override protected void onResume() { super.onResume(); // Set up a listener whenever a key changes getPreferenceScreen().getSharedPreferences() … Read more

Xcode 4 + iOS 4.3: “No Packager exists for the type of archive”

you may have some linked projects (like librairies) inside your main project. Go to the Build settings of those projects and set the setting “Skip install” (Deployement category) to “Yes”, but leave the “Skip install” of the main project to “No”. Build, archive, and you should be able to select the ipa package.

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