Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Friday, January 3, 2020

running simple django application in aws


By default, only SSH has been enabled in the security for the fresh server in AWS


Change the security group








Add another rule for port 8000



Viola


Installing Supervisor
sudo apt-get install -y supervisor

in /etc/supervisor/conf.d create gunicorn.conf file

sudo mkdir /var/log/gunicorn
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl status

in /etc/nginx/sites-available create django-simple.conf file



sudo nginx -t
sudo ln django-simple.conf /etc/nginx/sites-enabled/



static files and image were not loaded properly



add this line



sudo systemctl nginx reload

creating new python environment using venv

sudo apt-get install python3-venv
python3 -m venv env
apt-get install python3-venv

Wednesday, September 25, 2019

django commands


create new django project
$ django-admin startproject mynewproject

run the server
$ python manage.py runserver

create app
$ python manage.py startapp myapptwo

Saturday, April 6, 2019

devco trial


Bubbles.py

from collections import OrderedDict

def nonrepeating(orig):

input = orig.lower()

dict=OrderedDict.fromkeys(input,0)

# traverse
for ch in input:
dict[ch]+=1

# nonrepeat
nonRepeatDict = [key for (key,value) in dict.iteritems() if value==1]
print nonRepeatDict

repeatStr = []
for tx in list(orig):
if tx not in nonRepeatDict:
repeatStr.append(tx)

makeitastring = ''.join(map(str, nonRepeatDict + repeatStr))
print makeitastring

if __name__ == "__main__":
orig = "Bubble"
nonrepeating(orig)



# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
    # write your code in Python 3.6
    ret = '+'
    flag = '+'
    for i in range(1, N):
        if flag == '+':
            ret += '-'
            flag = '-'
        else:
            ret += '+'
            flag = '+'
    return ret

Monday, January 28, 2019

installing anaconda and jupyter in digitalocean

I have been frustrated lately trying to learn data science in my office (in my spare time) because of the SSL certificate issue. Every time I execute a command the error just popping up and I get a less patient and I say "Arrrrrr" and suddenly just pop in my mind, what if I will run anaconda and jupyter in my external server which my personal from digital ocean. and then the quest begins....


1. install the anaconda
https://www.digitalocean.com/community/tutorials/how-to-install-anaconda-on-ubuntu-18-04-quickstart

2. configure and run jupyter
https://www.digitalocean.com/community/tutorials/how-to-install-run-connect-to-jupyter-notebook-on-remote-server

ohhh, i'm invincible its only 2 steps.

 


Eureka!!!!!

Wednesday, January 23, 2019

python text to speech and this is awesome

pip install pyttsx3
pip install pypiwin32

the code:

import pyttsx3;
engine = pyttsx3.init();
engine.say("My wife is Sheryl and my two son's are Kiefer and Jairus");
engine.runAndWait() ;

that's it, eureka!

Tuesday, January 22, 2019

speech recognition

its 11pm and I found something interesting, this time I tried to implement speech recognition.

actually, its very easy

1. pip install SpeechRecognition
2. conda install -c anaconda pyaudio
3. the code

import speech_recognition as sr

r = sr.Recognizer()

with sr.Microphone() as source:
print('Speak anything:')
audio = r.listen(source)

try:
text = r.recognize_google(audio)
print('you said: {}'.format(text))
except:
print('sorry could not recognize your voice...')


4. run it! so simple. Eureka!


reference:
https://www.youtube.com/watch?v=K_WbsFrPUCk
https://realpython.com/python-speech-recognition/

Thursday, January 17, 2019

check the install python modules

python

import pip
installed_packages = pip.get_installed_distributions()
installed_packages_list = sorted(["%s==%s" % (i.key, i.version)
     for i in installed_packages])
print(installed_packages_list)


Thursday, January 3, 2019

SSL error

error:





solution:

conda config --set ssl_verify False

(better approach)
conda config --set ssl_verify C:\Users\lynard\AppData\Local\Continuum\anaconda3\Library\ssl\Fortinet_CA_SSL.pem

Install and manage anaconda in windows



conda commands

list of environment
conda info --envs

create environment
conda create --name py36 python=3.6 pip numpy
activate py36
conda install matplotlib

to show packages installed
conda list --explicit
conda list --explicit > py36_reqs.txt
conda create --name py36_v2 -- file py36_reqs.txt

to remove environment
conda env remove --name pyside

to clone environment
conda create --name myclone --clone myenv


reference:
https://docs.conda.io/projects/conda/en/4.6.0/_downloads/52a95608c49671267e40c689e0bc00ca/conda-cheatsheet.pdf
https://kapeli.com/cheat_sheets/Conda.docset/Contents/Resources/Documents/index (new)
https://www.youtube.com/watch?v=9Sfs7Fbvtdk














Sunday, December 30, 2018

Monday, March 26, 2018

Install Python 3 in Ubuntu


if add-apt is not found,

sudo: add-apt-repository: command not found
sudo apt-get install software-properties-common python-software-properties
sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update


sudo add-apt-repository ppa:jonathonf/python-3.6



I don't know my previous post above if its totally working on how to install python 3.6.
But here, I just tested it and obviously it works.

sudo add-apt-repository ppa:jonathonf/python-3.6
sudo apt-get update
sudo apt-get install python3.6

Tuesday, December 19, 2017

Python libraries

Running API from python code needs this libraries.


installing in centos
curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
python get-pip.py

sudo pip install web.py
sudo pip install pyt
sudo pip install python-dateutil
sudo pip install tzlocal
sudo pip install pyyaml



installing in ubuntu, need to install the pip first.
$ sudo apt-get install python-pip python-dev build-essential
$ sudo pip install --upgrade pip
$ sudo pip install --upgrade virtualenv



Tuesday, October 3, 2017

Tuesday, September 5, 2017

Python Rocks!

I have a transfer knowledge today with my colleague as he will be leaving soon. While listening to him I look at his code on how to write the INI file in python. I was wondering how he did it. I know in Java before and I can't really remember the code. So to make it short, I google it and try to learn by my self.

I found this site and it's really straight forward.
https://martin-thoma.com/configuration-files-in-python/

you can create a variety not only INI file but also JSON,YAML and XML. wow, that's great!

Friday, March 31, 2017

My first sms project using TWILIO , PYTHON and DOCKER

I just found out this cool app called twilio and I really interested how it works. My main objective is to create a mass sms sending app but its too far at this point.

First, I found this youtube from cleverprogramming website. https://www.youtube.com/watch?v=uzBRycRYsqw. The tutorial is very straight forward. I can follow his steps but I want something different in my setup. I want to use docker instead installing in my development pc which I'm working in the office now. Hopefully no ones knows what I'm doing. haha

But anyway, so first I'm struggling how to mount the volume from my python image. So this is what I did.

1. run docker pull python
this will pull the latest images which i think python 3.6

2. create a dockerfile
FROM python
RUN pip install twilio
VOLUME ["/mnt/python_file"]

from script above, I creating a python base image and install twilio app and specify the volume. Isn't that easy. But the hardest part, is that I don't know if its working exactly what I wanted.

3. run docker build -t python-twilio

i have already my custom image, next will run this to create a container.

4. run docker run -v /c/Users/DEFAULT.DEFAULT-PC/volumes:/mnt/python_file python-twilio python /mnt/python_file/send_sms.py

previously, i didn't add '/mnt/python_files/' from send_sms.py which giving me error that the file is not found. So that's it, i received the sms message to my phone, Eureka!

btw, I have so much to improve my code. we will see next time to achieve my goal to build an app. Viola!



UPDATED:
The new command below is changing the volume from c: drive to d:.
d_drive name is the same which I configure in the Oracle VM virtualbox.

ex1:
docker run -v /d_drive/Lynard/development/personal/twilio_tutorial:/mnt/python_file twilio1 python /mnt/python_file/send_sms.py

ex2:
docker run -v /d_drive/Lynard/development/personal/twilio_tutorial:/mnt/codes ls/twilio python /mnt/codes/send_sms.py

So now, I can do and save my code in my drive D: isn't that great! Eureka!!!!

Wednesday, March 29, 2017

Odoo 9 Installation guideline

First thing of advice, when running odoo in vmware where ubuntu is installed as operating system. Configure the harddisk around 40gb and the memory at 3gb to get most optimize one. 

#apply any patches and make sure your Ubuntu server is accessing the Internet

sudo apt-get update
sudo apt-get dist-upgrade

#reboot your server

sudo reboot

#install postgres

sudo apt-get install postgresql

#change over to the postgresql to set permissions on our development user

sudo su - postgres
createuser --createdb --username postgres --no-createrole --pwprompt devlynard

#python dependencies

sudo apt-get install python-cups python-dateutil python-decorator python-docutils python-feedparser
sudo apt-get install python-gdata python-geoip python-gevent python-imaging python-jinja2 python-ldap
sudo apt-get install python-libxslt1 python-lxml python-mako python-mock python-openid python-passlib
sudo apt-get install python-psutil python-psycopg2 python-pybabel python-pychart python-pydot python-pyparsing
sudo apt-get install python-pypdf python-reportlab python-requests python-simplejson python-tz python-unicodecsv
sudo apt-get install python-unittest2 python-vatnumber python-vobject
sudo apt-get install python-werkzeug python-xlwt python-yaml wkhtmltopdf
sudo apt-get install python-pip python-dev libevent-dev gcc libxml2-dev libxslt-dev node-less geoip-database-contrib
sudo apt-get install python-pip git-core
sudo pip install pika

#install git

sudo apt-get install git

#download odoo framework

git clone https://www.github.com/odoo/odoo --depth 1 --branch 9.0 --single-branch .

#Linux file sharing services compatible with Microsoft

sudo apt-get install samba samba-common-bin
sudo smbpasswd -a odoo
sudo nano /etc/samba/smb.conf

[homes]
comment = Home Directories
browseable = yes
read only = no
create mask = 0640
directory mask = 0750

sudo /etc/init.d/smbd restart


#Install subversion on Ubuntu

sudo apt-get install subversion
svn co --username <username> svn://172.18.6.230/repo2
sudo dpkg -l|grep subversion
svn –version
svn update

#to install rabbitvcs

sudo add-apt-repository ppa:rabbitvcs/ppa
sudo apt-get update
sudo apt-get install rabbitvcs-nautilus3



#installing PIP And PyPDF2 To Read PDF File With Python On Ubuntu Linux

sudo apt-get update
sudo apt-get -y install python-pip
pip --help
sudo pip install PyPDF2



#install pycharm in ubuntu

Download Pycharm
https://www.jetbrains.com/pycharm/download/#section=linux

Copy the pycharm-*.tar.gz to an empty directory
(make sure you have rw permissions for that directory)

Unpack the pycharm-*.tar.gz using the following command:

tar xfz pycharm-*.tar.gz

Remove the pycharm-*.tar.gz to save disk space (optional)
Run pycharm.sh from the bin subdirectory

NOTE: PyCharm on Linux doesn't need special installation or running any installation script. It runs out of the pycharm-*.tar.gz




#additional libraries

sudo apt-get install python-pip

sudo apt-get install python-yaml
pip install pytz
sudo pip install python-dateutil
sudo pip install tzlocal   


free online comma separating tool

https://delim.co/#