Posts

Install bcrypt on Mac OSX

 Basically One can do it wih homebrew. About the App App name : bcrypt App description : Cross platform file encryption utility using blowfish App website :  http://bcrypt.sourceforge.net Install the homebrew package manager Open  Terminal  and press  enter/return  key. Copy and paste the following command in Terminal app: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" and press  enter/return  key. Wait for the command to finish. If you are prompted to enter a password, please type your Mac user's login password and press ENTER. Mind you, as you type your password, it won't be visible on your Terminal (for security reasons), but rest assured it will work. Now, copy/paste and run this command to make  brew  command available inside the Terminal:  echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile Install the bcrypt lib Copy and paste the following command: brew install bcrypt Done! Y

Writing nice prompts for stable diffusion and like neural networks

Image
Request: new york city, synthwave, cinematic, dramatic, composition, sunny sky, brutalist, hyper realistic, epic scale, sense of awe, hypermaximalist, insane level of details, artstation HQ Playing with neural models is really fun. Let's try to make our best at writing good requests. That's the key! So thst's how: Diffusion prompts are statements or questions that are designed to help individuals think more deeply about a topic or concept and draw their own conclusions. They are often used in discussions or debates to encourage critical thinking and encourage participants to consider different perspectives. Here are some tips for writing good, stable diffusion prompts: Make sure the prompt is clear and concise: Avoid using jargon or complex language that may be confusing to readers. Keep the prompt brief and to the point, so that it is easy for readers to understand and respond to. Focus on a specific topic or concept: Choose a specific topic or concept to focus on, and m

Running tasks with Celery on Heroku guide

Image
An example project and a basic guide showing how to run Django/Celery on Heroku. Basic requirements First of all, let's actually set up a typical Django project for this. We would need virtualenvwrapper   for that. One could use any other particular method. I prefer this one. $ cd dev $ mkvirtualenv dch ( dch ) $ pip install django ( dch ) $ django-admin startproject djheroku ( dch ) $ cd djheroku # Make sure is working: ( dch ) $ ./manage.py runserver From now I will consider working on a terminal with this (dch) environment on. Heroku hosting setup We would need our project set up for heroku python server. The docs live HERE , as for moment of this guide writing. One would need to follow and setup a basic heroku project. I will not stop here rewriting official guide as it is good enough. Installing celery Assuming we have a basic django dyno at heroku here we will continue. Now let's install Celery and add it to our requirements list (as we had just sta

SQLAlchemy (Flask) count model instances by unique values

One comes to a task that has to do with counting items in a database. We will describe the right approach here. Despite being so obvious I did not find much of the docs for junior developers to watch and learn. Here is a sample task and solution: Let's assume we have a model like so: class Cycle (db.Model): id = db.Column(db.Integer, primary_key= True ) object_id = db.Column(db.String, nullable= False ) Sample date populated into it will be: { id : 1 , object_id: 'unique1' }, { id : 2 , object_id: 'unique1' }, { id : 3 , object_id: 'unique2' }, { id : 4 , object_id: 'unique2' }, { id : 5 , object_id: 'unique2' }, { id : 6 , object_id: 'unique3' } We need to count unique model instances with same  object_id . To achieve this relatively simple task one would go straightforward. E.g. Fetch all the Cycle instances with a simple query and then

PostgreSQL DB with pgAdmin4 access through SSH tunnel

Image
Despite using console most of the time I have a preference to edit PostgreSQL databases through UI. Especially when it comes to remote side. Usually one can access this through  $ psql  command. However this tends to writing raw SQL queries and a lot of typing in overall. Here is a way to do it with UI. First one needs to make a tunnel.Command is fairly simple: ssh - fNg - L 5555 : localhost : 5432 { username } @ { host . com } One has a tunnel afterwards. This command opens a SSH connection in the background mapping your local port 5555 to your server’s port 5432 (Postgres’ default port). To understand one can observe the meaning of the flags via  $ man ssh  to see what each of these flags doing.  It can be accessed via localhost tools like pgAdmin4 at localhost and port 5555 DB config would look like so:

Run Flask with Debug in PyCharm

Image
I have gotten to setting UP a Flask environment for a project recently. Was completely puzzled by how to run this. I have used to running Django project with python manage.py script. This means pointing out a PyCharm interpreter into a certain point of entry, that is also a .py file also. In flask way of starting things there is another approach however. Here it is in Flask Docs. It states to set a variable FLASK_APP and then run a flask run command. This will confuse running a python script way of a project being run. Thus to fix this one needs to set a path to flask binary file. It usually is within a virtual environment binary directory, place where your python interpreter resides. So to set debugging one needs to set path to script binary one needs: Script: /path/to/env/bin/flask Script parameters: run   Environment variable  FLASK_APP=app.py Environment variable FLASK_DEBUG=True Set working directory back to your app path (It changes automatically according to script

Promise -fication of JS calls.

Image
Found a new pattern to use recently that is called Promise. I really like the way ES6/7 brings new thinking patterns into life nowdays. Here is Promise used instead of old pattern. It was to give JS method a callback function. This splitting code and making a lot of possibilities for error to come out in this place. One would write old times according to MDN : function greeting ( name ) { alert ( 'Hello ' + name ); } function processUserInput ( callback ) { var name = prompt ( 'Please enter your name.' ); callback ( name ); } processUserInput ( greeting ); And now it is made with Promise pattern like so: let promise = new Promise (( resolve , reject ) => { resolve ( prompt ( 'Please enter your name.' )); }); promise . then (( name ) => { alert ( 'Hello ' + name ); }); In general and briefly this now helps to avoid 'callback hell' with functions passed as arguments and write as