Joyber 发布的文章

<html>
 
<head>
<title>HTML显示json字符串并且进行格式化</title>
</head>
 
<body>
<p id="show_p">{ "name": "Brett", "address":"北京路23号", "email": "123456@qq.com" }</p>
<pre id="out_pre"></pre>
 
</body>
<script type="text/javascript">
 
  var text = document.getElementById('show_p').innerText; //获取json格式内容
  
   var result = JSON.stringify(JSON.parse(text), null, 2);//将字符串转换成json对象
 
   document.getElementById('out_pre').innerText= result ;
  
 
</script>
 
</html>

安装 supervisor

sudo pip2.7 install supervisor

查看 supervisor 的最新版本和文件列表

pip2.7 show -f supervisor

可以看到 Location 是 /usr/local/lib/python2.7/site-packages,和Files的前几个文件

  ../../../bin/echo_supervisord_conf
  ../../../bin/pidproxy
  ../../../bin/supervisorctl
  ../../../bin/supervisord

其中../../../相对路径/usr/local/lib/python2.7/site-packages得到绝对路径是:/usr/local
那前四个文件的绝对路径是:

/usr/local/bin/echo_supervisord_conf
/usr/local/bin/pidproxy
/usr/local/bin/supervisorctl
/usr/local/bin/supervisord

生成 supervisor 的配置文件

echo_supervisord_conf | sudo tee /etc/supervisord.conf

如果是root用户可以用

echo_supervisord_conf > /etc/supervisord.conf

如果提示 -bash: echo_supervisord_conf: command not found说明/usr/local/bin没有添加到visudo的secure_path内,解决方法是:

编辑visudo

sudo visudo

找到 secure_path这一行

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin

添加/usr/local/sbin和/usr/local/bin,变成这样

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin

保存编辑即可

创建一个配置文件夹,多个服务的配置文件单独放置

sudo mkdir -p /etc/supervisor.d

修改配置文件

sudo vim /etc/supervisord.conf

找到 ;[include]去掉;变成[include]

找到[include]下面的;files去掉;变成files

将files = relative/directory/.ini改成files = /etc/supervisor.d/.conf

其它配置默认即可,保存修改

添加 /etc/init.d/supervisor 开机启动

sudo vim /etc/init.d/supervisord

添加内容:

#!/bin/sh
#
# /etc/rc.d/init.d/supervisord
#
# Supervisor is a client/server system that
# allows its users to monitor and control a
# number of processes on UNIX-like operating
# systems.
#
# chkconfig: - 64 36
# description: Supervisor Server
# processname: supervisord

# Source init functions
. /etc/rc.d/init.d/functions

prog="supervisord"

prefix="/usr/local"
exec_prefix="${prefix}"
prog_bin="${exec_prefix}/bin/supervisord"
PIDFILE="/var/run/$prog.pid"
conf="/etc/supervisord.conf"

start()
{
        echo -n $"Starting $prog: "
        daemon $prog_bin --pidfile $PIDFILE -c $conf
        [ -f $PIDFILE ] && success $"$prog startup" || failure $"$prog startup"
        echo
}

stop()
{
        echo -n $"Shutting down $prog: "
        [ -f $PIDFILE ] && killproc $prog || success $"$prog shutdown"
        echo
}

case "$1" in

  start)
    start
  ;;

  stop)
    stop
  ;;

  status)
        status $prog
  ;;

  restart)
    stop
    start
  ;;

  *)
    echo "Usage: $0 {start|stop|restart|status}"
  ;;

esac

增加可执行权限

sudo chmod +x /etc/init.d/supervisord

centos 添加开机启动

sudo chkconfig --add supervisord
sudo chkconfig --level 2345 supervisord on

启动 supervisord

sudo /etc/init.d/supervisord start

Options

Core options

Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-, as in data-style="" or data-selected-text-format="count".

Note: For security reasons, the sanitize, sanitizeFn and whiteList options cannot be supplied using data attributes.

Name    Type    Default    Description
actionsBox    boolean    false    
When set to true, adds two buttons to the top of the dropdown menu (Select All & Deselect All).
container    string | false    false    
When set to a string, appends the select to a specific element or selector, e.g., container: 'body' | '.main-body'
countSelectedText    string | function    function    
Sets the format for the text displayed when selectedTextFormat is count or count > #. {0} is the selected amount. {1} is total available for selection.

When set to a function, the first parameter is the number of selected options, and the second is the total number of options. The function must return a string.
deselectAllText    string    'Deselect All'    
The text on the button that deselects all options when actionsBox is enabled.
dropdownAlignRight    boolean | 'auto'    false    
Align the menu to the right instead of the left. If set to 'auto', the menu will automatically align right if there isn't room for the menu's full width when aligned to the left.
dropupAuto    boolean    true    
checks to see which has more room, above or below. If the dropup has enough room to fully open normally, but there is more room above, the dropup still opens normally. Otherwise, it becomes a dropup. If dropupAuto is set to false, dropups must be called manually.
header    string    false    
adds a header to the top of the menu; includes a close button by default
hideDisabled    boolean    false    
removes disabled options and optgroups from the menu data-hide-disabled: true
iconBase    string    'glyphicon'    
Set the base to use a different icon font instead of Glyphicons. If changing iconBase, you might also want to change tickIcon, in case the new icon font uses a different naming scheme.
liveSearch    boolean    false    
When set to true, adds a search box to the top of the selectpicker dropdown.
liveSearchNormalize    boolean    false    
Setting liveSearchNormalize to true allows for accent-insensitive searching.
liveSearchPlaceholder    string    null    
When set to a string, a placeholder attribute equal to the string will be added to the liveSearch input.
liveSearchStyle    string    'contains'    
When set to 'contains', searching will reveal options that contain the searched text. For example, searching for pl with return both Apple, Plum, and Plantain. When set to 'startsWith', searching for pl will return only Plum and Plantain.
maxOptions    integer | false    false    
When set to an integer and in a multi-select, the number of selected options cannot exceed the given value.

This option can also exist as a data-attribute for an <optgroup>, in which case it only applies to that <optgroup>.
maxOptionsText    string | array | function    function    
The text that is displayed when maxOptions is enabled and the maximum number of options for the given scenario have been selected.

If a function is used, it must return an array. array[0] is the text used when maxOptions is applied to the entire select element. array[1] is the text used when maxOptions is used on an optgroup. If a string is used, the same text is used for both the element and the optgroup.
mobile    boolean    false    
When set to true, enables the device's native menu for select menus.
multipleSeparator    string    ', '    
Set the character displayed in the button that separates selected options.
noneSelectedText    string    'Nothing selected'    
The text that is displayed when a multiple select has no selected options.
noneResultsText    string    'No results matched {0}'    
The text displayed when a search doesn't return any results.
selectAllText    string    'Select All'    
The text on the button that selects all options when actionsBox is enabled.
selectedTextFormat    'values' | 'static' | 'count' | 'count > x' (where x is an integer)    'values'    
Specifies how the selection is displayed with a multiple select.

'values' displays a list of the selected options (separated by multipleSeparator. 'static' simply displays the select element's title. 'count' displays the total number of selected options. 'count > x' behaves like 'values' until the number of selected options is greater than x; after that, it behaves like 'count'.
selectOnTab    boolean    false    
When set to true, treats the tab character like the enter or space characters within the selectpicker dropdown.
showContent    boolean    true    
When set to true, display custom HTML associated with selected option(s) in the button. When set to false, the option value will be displayed instead.
showIcon    boolean    true    
When set to true, display icon(s) associated with selected option(s) in the button.
showSubtext    boolean    false    
When set to true, display subtext associated with a selected option in the button.
showTick    boolean    false    
Show checkmark on selected option (for items without multiple attribute).
size    'auto' | integer | false    'auto'    
When set to 'auto', the menu always opens up to show as many items as the window will allow without being cut off.

When set to an integer, the menu will show the given number of items, even if the dropdown is cut off.

When set to false, the menu will always show all items.
style    string | null    Bootstrap 4: 'btn-light' Bootstrap 3: 'btn-default'    
When set to a string, add the value to the button's style.
styleBase    string | null    'btn'    
The default class applied to the button. When using the setStyle method, this class will always remain.

Hint: If you want to style the element as a form control, set style to '' and styleBase to 'form-control'.
tickIcon    string    'glyphicon-ok'    
Set which icon to use to display as the "tick" next to selected options.
title    string | null    null    
The default title for the selectpicker.
virtualScroll    boolean | integer    600    
If enabled, the items in the dropdown will be rendered using virtualization (i.e. only the items that are within the viewport will be rendered). This drastically improves performance for selects with a large number of options. Set to an integer to only use virtualization if the select has at least that number of options.
width    'auto' | 'fit' | css-width | false (where css-width is a CSS width with units, e.g. 100px)    false    
When set to auto, the width of the selectpicker is automatically adjusted to accommodate the widest option.

When set to a css-width, the width of the selectpicker is forced inline to the given value.

When set to false, all width information is removed.
windowPadding    integer | array    0    
This is useful in cases where the window has areas that the dropdown menu should not cover - for instance a fixed header. When set to an integer, the same padding will be added to all sides. Alternatively, an array of integers can be used in the format [top, right, bottom, left].
sanitize    boolean    true    
Enable or disable the sanitization. If activated, 'data-content' on individual options will be sanitized.
whiteList    object    Default value    
Object which contains allowed attributes and tags
sanitizeFn    null | function    null    
Here you can supply your own sanitize function. This can be useful if you prefer to use a dedicated library to perform sanitization.

Default settings

You can change the default settings for bootstrap-select by modifying its Constructor.DEFAULTS object:

$.fn.selectpicker.Constructor.DEFAULTS.multipleSeparator = ' | ';

Events

Bootstrap-select exposes a few events for hooking into select functionality.

hide.bs.select, hidden.bs.select, show.bs.select, and shown.bs.select all have a relatedTarget property, whose value is the toggling anchor element.

Event Type    Description
show.bs.select    This event fires immediately when the show instance method is called.
shown.bs.select    This event is fired when the dropdown has been made visible to the user (will wait for CSS transitions, to complete).
hide.bs.select    This event is fired immediately when the hide instance method has been called.
hidden.bs.select    This event is fired when the dropdown has finished being hidden from the user (will wait for CSS transitions, to complete).
loaded.bs.select    This event fires after the select has been initialized.
rendered.bs.select    This event fires after the render instance has been called.
refreshed.bs.select    This event fires after the refresh instance has been called.
changed.bs.select    
This event fires after the select's value has been changed. It passes through event, clickedIndex, isSelected, previousValue.

previousValue is the value of the select prior to being changed. If the select's value has been changed either via the .selectpicker('val'), .selectpicker('selectAll'), or .selectpicker('deselectAll') methods, clickedIndex and isSelected will be null.

Methods

.selectpicker('val')
.selectpicker('selectAll')
.selectpicker('deselectAll')
.selectpicker('render')
.selectpicker('mobile')
.selectpicker('setStyle')
.selectpicker('refresh')
.selectpicker('toggle')
.selectpicker('hide')
.selectpicker('show')
.selectpicker('destroy')

Centos 7默认gcc版本为4.8,有时需要更高版本的,这里以升级至8.3.1版本为例,分别执行下面三条命令即可,无需手动下载源码编译

PS:我在安装的时候已经可以使用11这个版本了

1、安装centos-release-scl

sudo yum install centos-release-scl

2、安装devtoolset,注意,如果想安装7.版本的,就改成devtoolset-7-gcc,以此类推

sudo yum install devtoolset-8-gcc*

3、激活对应的devtoolset,所以你可以一次安装多个版本的devtoolset,需要的时候用下面这条命令切换到对应的版本

scl enable devtoolset-8 bash

大功告成,查看一下gcc版本

gcc -v

显示为 gcc version 8.3.1 20190311 (Red Hat 8.3.1-3) (GCC)

补充:这条激活命令只对本次会话有效,重启会话后还是会变回原来的4.8.5版本,要想随意切换可按如下操作。

**首先,安装的devtoolset是在 /opt/rh 目录下的

每个版本的目录下面都有个 enable 文件,如果需要启用某个版本,只需要执行

source ./enable

所以要想切换到某个版本,只需要执行

source /opt/rh/devtoolset-8/enable

可以将对应版本的切换命令写个shell文件放在配了环境变量的目录下,需要时随时切换,或者开机自启

4、直接替换旧的gcc

旧的gcc是运行的 /usr/bin/gcc,所以将该目录下的gcc/g++替换为刚安装的新版本gcc软连接,免得每次enable

mv /usr/bin/gcc /usr/bin/gcc-4.8.5
ln -s /opt/rh/devtoolset-8/root/bin/gcc /usr/bin/gcc
mv /usr/bin/g++ /usr/bin/g++-4.8.5
ln -s /opt/rh/devtoolset-8/root/bin/g++ /usr/bin/g++
gcc --version
g++ --version

$f = fopen('curl_debug', 'wb');
curl_setopt($ch,CURLOPT_VERBOSE,true);//默认是标准错误输出中
curl_setopt($ch,CURLOPT_STDERR ,$f);//有了该指令,请求过程记录会写到该文件中

记录的文件内容大致如下 :

*   Trying 14.215.177.39...
* TCP_NODELAY set
* Connected to www.baidu.com (14.215.177.39) port 80 (#0)
> GET / HTTP/1.1
Host: www.baidu.com
Accept: */*

< HTTP/1.1 200 OK
< Accept-Ranges: bytes
< Cache-Control: no-cache
< Connection: keep-alive
< Content-Length: 14615
< Content-Type: text/html
< Date: Tue, 02 Nov 2023 16:34:39 GMT
< Pragma: no-cache
< Server: BWS/1.1
< Vary: Accept-Encoding
< 
* Connection #0 to host www.baidu.com left intact

curl本身的bug导致如果CURLINFO_HEADER_OUT设置为true时(即开启输出响应头), CURLOPT_VERBOSE会不生效.所以你需要将CURLINFO_HEADER_OUT配置去掉.