mercredi 18 août 2021

Xbox Wireless Headset on Ubuntu

If the Xbox headset (bluetooth) constantly disconnects/reconnects.


Follow the steps described here : https://github.com/pipewire-debian/pipewire-debian/wiki to install PipeWire.

And configure the Sound settings as below.

When playing music (just headset output needed, good output quality), set :
  • output 
    • device "Portable - Xbox Wireless Headset"
    • configuration "High Fidelity Playback (A2DP Sink)"
  • input
    • device "Microphone - Built-in Audio"




When meeting (headset output and headset mic needed, but very bad output quality), set :
  • output 
    • device "Portable - Xbox Wireless Headset"
    • configuration "Headset Head Unit (HSP/HFP, codec mSBC)"
  • input
    • device "Portable - Xbox Wireless Headset"
    • configuration "Headset Head Unit (HSP/HFP, codec mSBC)"



As we can see, we must switch manually, depending on if 
  • we want to enable the mic (with a bad output quality) for a meeting
  • or if we want to mainly listen music (better output quality).
We cannot use A2DP (good output quality) with the mic enabled.
Why we cannot use A2DP when mic is enabled ?


The workaround is to create a script to switch easily between A2DP<->mSBC (music or meeting):

The script is here : 





jeudi 20 juin 2019

[Python] Singleton


Multiple ways :
  • Way 1

class MyClass:
  def __init__(self):
    pass


  @classmethod
  def get(cls):
    try:
      return cls.instance
    except AttributeError:
      cls.instance = MyClass()
      return cls.instance


  • Way 2
import sys

this = sys.modules[__name__]

class MyClass:
  def __init__(self):
    pass


def get_my_singleton():
  try:
    return this.my_singleton
  except AttributeError:
    this.my_singleton = MyClass()
    return this.my_singleton

More details about this way: https://stackoverflow.com/a/35904211

lundi 10 juin 2019

[Python] Difference between package and module

A module is a file :-) Modules are used to keep logically related code functions/classes together.


A package is a folder containing a set of modules.

A package may contain sub-packages.

A package must have a __init__.py at the root of the directory. When a package is imported, this __init__.py file is implicitly executed. https://docs.python.org/3/reference/import.html#regular-packages

Packaging help you to keep logically related set of modules together just as modules are used to keep logically related code functions/classes together.

With Python 3.3 and later, a package is called a regular package, and a new type of package appears : namspace package. https://docs.python.org/3/reference/import.html#namespace-packages

vendredi 29 mars 2019

[Git] difference upstream / origin

upstream generally refers to the original repo that you have forked
origin is your fork: your own repo on GitHub, clone of the original repo of GitHub

git : reset your branch to the upstream branch

git checkout yourbranch
git remote add upstream https://.......
git fetch upstream
git reset --hard upstream/master
# take care, this will delete all your changes on your forked yourbranch
git push origin yourbranch --force

https://stackoverflow.com/a/42332860

git : adding an upstream

git remote add upstream https://....

git : how to do a local rebase

git clone <origin>
git checkout <featbranch>
git pull
git remote add upstream https://.....
git fetch upstream
git rebase upstream/development
git push 

git : remove a submodule

git submodule deinit -f -- a/submodule    
rm -rf .git/modules/a/submodule
git rm -f a/submodule

Source : https://stackoverflow.com/questions/1260748/how-do-i-remove-a-submodule

git clone : server certificate verification failed

Solution:

export GIT_SSL_NO_VERIFY=1
or
git config --global http.sslverify false

jeudi 9 août 2018

git submodule update -> already exists and is not an empty directory

When typing this :
git submodule update

Having this error :
fatal: destination path 'xxx' already exists and is not an empty directory. 
fatal: clone of 'git@bitbucket.org:xxxxx/your-repo.git' into submodule path 'xxx' failed

Solution
git submodule deinit --force . 
git submodule init 
git submodule update --recursive

mardi 17 octobre 2017

File upload with Tornado

Demonstrates a server that receives a multipart-form-encoded set of files in an HTTP POST, or streams in the raw data of a single file in an HTTP PUT.

AND

Demonstrates uploading files to a server, without concurrency. It can either POST a multipart-form-encoded request containing one or more files, or PUT a single file without encoding.

https://github.com/tornadoweb/tornado/tree/master/demos/file_upload

mardi 28 juin 2016

[Pip] Packaging and distributing project with git and pip

1- make the project "pip compatible"

in your project directory: nano setup.py

from setuptools import setup
setup( 
   name='testapp', 
   version='0.1', 
   description='A test application !', 
   author='an_author', 
   author_email='author@author', 
   license='MIT', 
   packages=['xyz'], 
   install_requires=['cherrypy'], 
   zip_safe=False
)

mkdir xyz (the package)

cd xyz

nano utils.py

def print_hello(): 
   print("print_hello called")

nano __init__.py
#empty file

2- how to install our project with pip from our private repository

retrieve project with pip: 
pip install https://github.com/user/repository/archive/branch.zip 

which becomes for django master: 
pip install https://github.com/django/django/archive/master.zip 

for django stable/1.7.x: 
pip install https://github.com/django/django/archive/stable/1.7.x.zip 

With BitBucket it's about the same predictable pattern: 
pip install https://bitbucket.org/izi/django-admin-tools/get/default.zip

for a private Bitbucket repository:
pip install git+https://bitbucket.org/<bitbucket_username>/<repo_name>.git

Source : http://stackoverflow.com/questions/20101834/pip-install-from-github-repo-branch
Source : http://stackoverflow.com/questions/4830856/is-it-possible-to-use-pip-to-install-a-package-from-a-private-github-repository

Source : https://packaging.python.org/en/latest/distributing/
Source : https://python-packaging.readthedocs.io/en/latest/minimal.html

[Git] init local project for bitbucket and first commit

1- create your repository on bitbucket


2- init local project:

mkdir /path/to/your/project
cd /path/to/your/project
git init 
git remote add origin https://<bitbucket_username>@bitbucket.org/<bitbucket_username>/<repository_in_lower_case>.git

3- first commit:

echo "James Bond" >> contributors.txt
git add contributors.txt
git commit -m 'Initial commit with contributors'
git push -u origin master

mercredi 20 avril 2016

[Linux] How to reinstall shutdown / reboot

First of all, check where they are :
which shutdown 
/sbin/shutdown

which reboot
/sbin/reboot

After, check the package :
$ dpkg -S /sbin/shutdown
upstart: /sbin/shutdown

$ dpkg -S /sbin/reboot
upstart: /sbin/reboot

Now we can reinstall :
sudo apt-get install --reinstall upstart

Source : http://askubuntu.com/questions/631929/reboot-and-shutdown-executables-missing

dimanche 10 avril 2016

[Apache2] Too many processes

If you have a lot of instances of apache2, you can update the values for StartServers, MinSpareServers and MaxSpareServers:

<IfModule mpm_prefork_module> 
StartServers 5 #at the begining
MinSpareServers 5  #min servers spare
MaxSpareServers 10  #max servers spare
MaxClients 150 
MaxRequestsPerChild 0 
</IfModule>

Source : https://fuscata.com/kb/set-maxclients-apache-prefork

jeudi 7 avril 2016

[LinkedIn] Build resume from profile

You can use the Linkedin CV chrome extension to generate a resume in PDF.

How to use
- Install the Linkedin CV extension.
- Go to your Linkedin profile and click the "View profile as" button. Because it will convert your complete profile not the editable one.
- Click the Linkedin logo in your browser address bar. Then your Linkedin profile will be converted.
- Press (Ctrl + P) to activate the print options in Google Chrome.
- From the options column on the left choose "Save as PDF" for destination.
- Click "Save" to save your CV.

samedi 2 avril 2016

[MongoDB] Please ensure LANG and/or LC_* environment variables are set correctly.

When I run:
mongo
Error message:
Failed global initialization: BadValue Invalid or no user locale set. Please ensure LANG and/or LC_* environment variables are set correctly.

Solution:
export LC_ALL=C

jeudi 12 novembre 2015

[AngularJS] retrieve param in url

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
 
var queryValue = getParameterByName('test_user_bLzgB');

Then it is not necessary to enable html5 and to define a <base>...

Source : http://stackoverflow.com/a/28473677

Categories