Skip to content

Instantly share code, notes, and snippets.

View khchine5's full-sized avatar
🗺️
World citizen

Hamza Khchine khchine5

🗺️
World citizen
View GitHub Profile
@khchine5
khchine5 / Virtualenv with Python3
Last active January 22, 2016 04:25
Installing and using virtualenv with Python3
Update the server
$ apt-get update
Install pip3
$ sudo apt-get install pip3
Install virtualenv via pip
$ pip3 install virtualenv
Create a virtualenvs directory
@khchine5
khchine5 / setting.py
Created August 6, 2016 22:47
djangocms text ckeditor: Active all options of ckeditor as Font selection , image insertion.
CKEDITOR_SETTINGS = {
'language': '{{ language }}',
'skin': 'moono',
'toolbar_HTMLField': [
['Source', '-', 'Save', 'NewPage', 'DocProps', 'Preview', 'Print', '-', 'Templates'],
['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo'],
['Find', 'Replace', '-', 'SelectAll', '-', 'SpellChecker', 'Scayt'],
['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton',
'HiddenField'],
['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat'],
@khchine5
khchine5 / setting.py
Last active August 6, 2016 23:11
djangocms text ckeditor: Active all options of ckeditor as Font selection , image insertion, lineheight ...
CKEDITOR_SETTINGS = {
'language': '{{ language }}',
'skin': 'moono',
'toolbar_HTMLField': [
['Source', '-', 'Save', 'NewPage', 'DocProps', 'Preview', 'Print', '-', 'Templates'],
['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo'],
['Find', 'Replace', '-', 'SelectAll', '-', 'SpellChecker', 'Scayt'],
['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton',
'HiddenField'],
['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat'],
PdfFile = PdfFileReader(f)
if PdfFile.isEncrypted:
try:
PdfFile.decrypt('')
print 'File Decrypted (PyPDF2)'
except:
import os
command = "cp " + f.name + " /tmp/temp.pdf; qpdf --password='' --decrypt /tmp/temp.pdf " + f.name + "_new"
os.system(command)
print 'File Decrypted (qpdf)'
@khchine5
khchine5 / gunicorn_start.bash
Created July 28, 2017 09:32 — forked from postrational/gunicorn_start.bash
Example of how to set up Django on Nginx with Gunicorn and supervisordhttp://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/
#!/bin/bash
NAME="hello_app" # Name of the application
DJANGODIR=/webapps/hello_django/hello # Django project directory
SOCKFILE=/webapps/hello_django/run/gunicorn.sock # we will communicte using this unix socket
USER=hello # the user to run as
GROUP=webapps # the group to run as
NUM_WORKERS=3 # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=hello.settings # which settings file should Django use
DJANGO_WSGI_MODULE=hello.wsgi # WSGI module name
@khchine5
khchine5 / odoo.conf
Created July 24, 2018 13:14 — forked from ryanc-me/odoo.conf
Sample Odoo/Nginx Config (with dbfilter_from_header support)
# Author: Ryan Cole
# Website: https://ryanc.me
# GitHub: https://github.com/MGinshe
# Usage:
# Place this file in /etc/nginx/sites-enabled/
# Make sure you edit the DOMAIN_HERE and SSL_CERTIFICATE, and DB_FILTER sections
#
# Note: This config file is designed to be used with the Odoo dbfilter_from_header module
# https://apps.openerp.com/apps/modules/9.0/dbfilter_from_header/
@khchine5
khchine5 / gist:300cba43271836c0312232f728b9fedb
Created November 8, 2019 09:38
login to a dokcer image
docker run -v $(pwd):/src -it getlino
@khchine5
khchine5 / pg_backup_all.sh
Created March 30, 2020 20:28 — forked from powellc/pg_backup_all.sh
Bash script to backup all postgresql databases on a server, run with cron once a day or 5 times a day, whatever. Just updated it so it ignores your postgres db, and also bzips the backups and adds a symlink to a latest directory. Sweet.
#!/bin/bash
# Location to place backups.
backup_dir="/var/backups/databases/"
nightly_dir="/var/backups/databases/latest/"
#String to append to the name of the backup files
backup_date=`date +%d-%m-%Y`
#Numbers of days you want to keep copie of your databases
number_of_days=15
databases=`psql -l -t | cut -d'|' -f1 | sed -e 's/ //g' -e '/^$/d'`
for i in $databases; do if [ "$i" != "postgres" ] && [ "$i" != "template0" ] && [ "$i" != "template1" ] && [ "$i" != "template_postgis" ]; then

Python Modules for Scraping:

Scraping and Parsing

  • selectolax
  • AdvancedHTMLParser
  • grequests
  • parsel
  • mechanicalsoup
  • beautifulsoup4
@khchine5
khchine5 / remove_duplicates.py
Created June 9, 2020 22:41 — forked from victorono/remove_duplicates.py
Django - remove duplicate objects where there is more than one field to compare
from django.db.models import Count, Max
unique_fields = ['field_1', 'field_2']
duplicates = (
MyModel.objects.values(*unique_fields)
.order_by()
.annotate(max_id=Max('id'), count_id=Count('id'))
.filter(count_id__gt=1)
)