How to rename all files in a folder using Python

let's assume the folder is user_data, relative to the current working directory (where the Python script is in). The code below was tested on Windows. import os for filename in os.listdir("./user_data"):     # print(filename)     cwd = os.path.dirname(os.path.abspath(__file__)) + '\\user_data\\'     if filename.split('.')[1] == 'jpg':         new_filename = filename.split('.')[0] + '_search' + '.jpg'         print(new_filename) … Continue reading How to rename all files in a folder using Python

define_method in Ruby

define_method is a (private) method of the object Class. You are calling it from an instance. define_method(:my_method) do |foo, bar| # or even |*args| # do something end or, you could even use string interpolation in the method name, such as define_method("#{attribute}=") do |unencrypted_password| if unencrypted_password.nil? self.send("#{attribute}_digest=", nil) elsif !unencrypted_password.empty? instance_variable_set("@#{attribute}", unencrypted_password) cost = ActiveModel::SecurePassword.min_cost … Continue reading define_method in Ruby

new update about has_secure_password in Rails 5.2

has_secure_password takes an attribute For many years has_secure_password only allowed a default password attribute. But now you can stash whatever you want in there. Source code Allows configurable attribute name for #has_secure_password. This still defaults to an attribute named 'password', causing no breaking change. Also includes a convenience method #<strong><span style="color:#008000;">regenerate_XXX</span></strong> where +XXX+ is the name … Continue reading new update about has_secure_password in Rails 5.2