Sunday, December 31, 2023

mac laptop copy paste to iphone not working

 Here are the steps:


  • Open the Terminal app on your Mac (Applications > Utilities)


  • Now, we will first delete Clipboard sharing and then enable it again. Here is how:
defaults delete ~/Library/Preferences/com.apple.coreservices.useractivityd.plist ClipboardSharingEnabled


  • Now, copy and paste this code and hit Enter:
defaults write ~/Library/Preferences/com.apple.coreservices.useractivityd.plist ClipboardSharingEnabled 1


  • Now check if copy and paste is working.



https://discussions.apple.com/thread/254811288?sortBy=best


Friday, October 2, 2020

Wednesday, September 16, 2020

Serve Django3 Applications with Apache2.4 and mod_wsgi on Ubuntu 20

Software versions: here are my application versions:

Python 3.8.2
Django 3.1.1 
Apache/2.4.41 (Ubuntu)
Ubuntu 20.04.1 LTS

Installation:

Step 1: Install apache 2,  Django and other packages

sudo apt-get install libapache2-mod-wsgi-py3
sudo apt-get install python3-pip
sudo pip3 install Django
sudo pip3 install mysql-python
sudo apt-get install python3-mysqldb

Step 2: create Django project - I create project under /var/www, but you may put anywhere, it's up to you

django-admin.py startproject myproject

You will see these files and folder under /var/www/myproject
myproject/
django.wsgi*
manage.py*

Step 3: Create apache vhost file 

cat /etc/apache2/sites-available/xxxx.com.conf

<VirtualHost *:80>

    #My site Name

    ServerName xxxx.com

    DocumentRoot /var/www/myproject

    WSGIDaemonProcess xxxx.com processes=2 threads=5 display-name=%{GROUP} python-path=/usr/local/lib/python3.8

    #Pointing wsgi script to config file

    WSGIScriptAlias / /var/www/myproject/myproject/wsgi.py

    WSGIProcessGroup xxxx.com


    #Your static files location

    Alias /static/ "//var/www/myproject/static/"

    <Location "/media">

        SetHandler None

    </Location>

    <LocationMatch "\.(jpg|gif|png|js|css)$">

        SetHandler None

    </LocationMatch>

    <Directory /var/www/myproject >

        AllowOverride all

        Require all granted

        Options FollowSymlinks

    </Directory>

</VirtualHost>

Step 4: modify this file /var/www/myproject/myproject/wsgi.py

cat /var/www/myproject/myproject/wsgi.py

import os

import time

import traceback

import signal

import sys

from django.core.wsgi import get_wsgi_application

sys.path.append('/var/www/myproject')

sys.path.append('/usr/local/lib/python3.8/dist-packages')


os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'CVE.settings')


try:

    application = get_wsgi_application()

except Exception:

    # Error loading applications

    if 'mod_wsgi' in sys.modules:

        traceback.print_exc()

        os.kill(os.getpid(), signal.SIGINT)

        time.sleep(2.5)

Step 5: enable wsgi mod and enable site

sudo a2enmod wsgi
sudo a2ensite xxxx.com

Summary: you may see these errors, please check RED part

mod_wsgi (pid=1059622): Failed to exec Python script file '/var/www/myproject/django.wsgi'.
 mod_wsgi (pid=1059622): Exception occurred processing WSGI script '/var/www/myproject/django.wsgi'.
 Traceback (most recent call last):
   File "/var/www/myproject/django.wsgi", line 12, in <module>
     application = django.core.handlers.wsgi.WSGIHandler()
   File "/usr/local/lib/python3.8/dist-packages/django/core/handlers/wsgi.py", line 127, in 
     self.load_middleware()
   File "/usr/local/lib/python3.8/dist-packages/django/core/handlers/base.py", line 40, in 
     middleware = import_string(middleware_path)
   File "/usr/local/lib/python3.8/dist-packages/django/utils/module_loading.py", line 17, in 
     module = import_module(module_path)
   File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
     return _bootstrap._gcd_import(name[level:], package, level)
   File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
   File "<frozen importlib._bootstrap>", line 991, in _find_and_load
   File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
   File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
   File "<frozen importlib._bootstrap_external>", line 783, in exec_module
   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
   File "/usr/local/lib/python3.8/dist-packages/django/contrib/auth/middleware.py", line 3, in <
     from django.contrib.auth.backends import RemoteUserBackend
   File "/usr/local/lib/python3.8/dist-packages/django/contrib/auth/backends.py", line 2, in <
     from django.contrib.auth.models import Permission
   File "/usr/local/lib/python3.8/dist-packages/django/contrib/auth/models.py", line 2, in <
     from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
   File "/usr/local/lib/python3.8/dist-packages/django/contrib/auth/base_user.py", line 48, in <
     class AbstractBaseUser(models.Model):
   File "/usr/local/lib/python3.8/dist-packages/django/db/models/base.py", line 108, in __new__
     app_config = apps.get_containing_app_config(module)
   File "/usr/local/lib/python3.8/dist-packages/django/apps/registry.py", line 252, in 
     self.check_apps_ready()
   File "/usr/local/lib/python3.8/dist-packages/django/apps/registry.py", line 135, in 
     raise AppRegistryNotReady("Apps aren't loaded yet.")
 django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.



Thursday, March 1, 2018

less /var/lib/logrotate/logrotate.status


less /var/lib/logrotate/logrotate.status

Monday, February 19, 2018

MAC "fatal error: 'openssl/opensslconf.h' file not found"


Run these two command to fix it

export CPPFLAGS=-I/usr/local/opt/openssl/include
export LDFLAGS=-L/usr/local/opt/openssl/lib

Thursday, October 12, 2017

corenlp


step 1: tokenize

  java -cp "stanford-corenlp-full-2017-06-09/*" edu.stanford.nlp.process.PTBTokenizer 2-malware.txt > 2-malware.tok

  less 2-malware.tok

Step 2: mark:
  perl -ne 'chomp; print "$_\tO\n"' 2-malware.tok > 2-malware.tsv

Step 3: generate tsv file using customized KEYWORD file

generate final.tsv

Step 4: generate customized NER using malware.prop: => will create malware-ner-model.ser.gz

 java -cp "stanford-corenlp-full-2017-06-09/*" edu.stanford.nlp.ie.crf.CRFClassifier -prop malware.prop

Step 5: using custom NER to detect text

java -cp "stanford-corenlp-full-2017-06-09/*" edu.stanford.nlp.ie.crf.CRFClassifier -loadClassifier  malware-ner-model.ser.gz -testFile sample.tsv.ini


--------------------------------------
java -cp "stanford-corenlp-full-2017-06-09/*" edu.stanford.nlp.process.PTBTokenizer jane-austen-emma-ch1.txt > jane-austen-emma-ch1.tok

java -mx15g -cp "stanford-corenlp-full-2017-06-09/*" edu.stanford.nlp.pipeline.StanfordCoreNLP -outputFormat json -file jane-austen-emma-ch1.txt