Tech C**P
14 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
How to remove a user on CentOS 6?

userdel my-target-user

In case you want to remove all the associated user files too use -r parameter:

userdel -r my-target-user

Yes! As simple as that.

#linux #sysadmin #userdel #user #centos
Have you heard about CORS (Cross Origin Resource Sharing)?

If you know it, but like me you don't know it as you should and every time the bowser gives you a new error in console you again get wandered in the wilderness, I'd suggest going to the awesome link below and read thoroughly line by line:

https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

NOTE: this article is fantastic! Believe you me. You will understand eveything you need to know exactly what is CORS and how to handle it properly.


#browser #mozilla #CORS #cross_origin #cross_origin_resource_sharing
An interesting thing in console of browsers:

You give ANY styling to console.log outputs! Here is how:

const style = [
'background: linear-gradient(to right, #5433ff, #20bdff, #a5fecb);',
'color: #fff',
'padding: 10px 20px',
'line-height: 35px'].join(';');

console.log('%cHi there!', style);

By using %c you can give styles to your text outputs.

#css #console #developer_tools #text_formatting
nginX by default does not set CORS headers for requests with error status codes like 401. There are 2 options here to add CORS headers:

1- If your nginX version is new you have the option of always to add to add_header:
add_header 'Access-Control-Allow-Origin' $http_origin always;

2- If you got error of invalid number of arguments in "add_header" directive, then use more_set_headers:
more_set_headers -s '401 400 403 404 500' 'Access-Control-Allow-Origin: $http_origin';

NOTE: when this error happens then in $.ajax or any similar method you wont have access to status codes. So be extremely catious!!!

#nginX #web_server #CORS #more_set_headers #add_header #ajax
How to upload a text content as a file in $.Ajax()?

FormData class is used to create a multipart/form-data inside of JS code. A sample code speaks thousand words:


var formData = new FormData();
var blob = new Blob([YOUR_CONTENT_HERE], { type: "text/html"});
formData.append("file", blob);


We have created a binary data from the text which is in the format of text/html, then I have appended the data as an input file with the name of file (which will be captured on server-side).

The Ajax part is utterly simple:


$.ajax({
type: 'POST',
url: 'https://www.example.com/storage',
data: formData,
processData: false,
contentType: false
}).done(function(data) {});


NOTE: DO NOT OMIT processData, contentType parameters.

#javascript #jQuery #ajax #FormData #Blob #upload
Today's Tech Term:

D2D: D2D is shorthand for Disk-To-Disk and refers to data backups using disks.

#tech_terms #D2D #disk_to_disk
DAAS: DAAS (short for Data As A Service) is a “central repository”/”cloud strategy” that facilitates on-demand accessibility of business-critical data by an organization’s users in a timely manner.


#tech_term #DAAS
What is the difference between the below exceptions:

try:
// Your code block
except:
// Your exception block

Vs:

try:
// Your code block
except Exception:
// Your exception block

A bare except: clause will catch SystemExit and KeyboardInterrupt exceptions, making it harder to interrupt a program with Control-C, and can disguise other problems. If you want to catch all exceptions that signal program errors, use except Exception: (bare except is equivalent to `except BaseException:`).

NOTE: When catching exceptions, mention specific exceptions whenever possible instead of using a bare except: clause.

A better try & except:

try:
import platform_specific_module
except ImportError:
platform_specific_module = None

#python #PEP8 #try #except #try_except #exception
Does that happen for you too, to CD into a wrong directory and need to get back to the previous directory?

Let's say you are in a long path like /mnt/new_volume/backup/files/archive, now you switch to home of your directory. In order to get back to the previous directory, you just need to issue the below command:

cd -

#linux #cd
What do you think the best way is to extract active users from the list below in Python?

users = [
{
"email":"[email protected]",
"is_active":True
},
{
"email":"[email protected]",
"is_active":True
},
{
"email":"[email protected]",
"is_active":False
},
{
"email":"[email protected]",
"is_active":False
}
]

Waiting for the answers :)

#python #question