作者归档:Innsd

2020-4-13 English Reading.

Reading record.source:https://time.com/5819795/opec-barrel-cut-coronavirus/


DUBAI, United Arab Emirates — OPEC, Russia and other oil-producing nations on Sunday finalized an unprecedented production cut of nearly 10 million barrels, or a tenth of global supply, in hopes of boosting crashing prices amid the coronavirus pandemic and a price war, officials said.

继续阅读

2020-4-12 English Reading.

Reading Record. source:https://time.com/5819074/federal-reserve-fed-coronavirus-lending/


The Federal Reserve may not be done with its all-out blitz to help the U.S. economy survive a coronavirus-induced shutdown, even after launching an unprecedented $2.3 trillion in lending programs.

The central bank used up only about 40% of the as much as $454 billion in seed capital that Congress provided it in extending help to small and mid-sized businesses, state and local governments and some risky corners of the financial markets on Thursday. 继续阅读

2020-4-11 English Reading.

Reading Record.

srocue:https://time.com/5819080/unemployment-coronavirus/

Economists expect the U.S. to suffer its largest-ever contraction this quarter and the unemployment rate to soar to a post-Depression record, followed by a recovery that will be moderate and drawn out.

Gross domestic product will plummet an annualized 25% from April through June after a smaller setback in the first quarter and the jobless rate will hit 12.6%, the highest since the 1940s, according to the median forecasts in Bloomberg’s monthly survey of 69 economists.

继续阅读

2020-4-9 English Reading.

Reading Record

source:https://time.com/5817083/jack-dorsey-pledges-1-billion-coronavirus-relief/

Jack Dorsey is devoting $1 billion of his stake in Square Inc., the payments firm he co-founded, to help fund the coronavirus relief effort.

“After we disarm this pandemic, the focus will shift to girl’s health and education, and UBI,” Dorsey said Tuesday in a tweet, referring to universal basic income. The pledge represents about 28% of his wealth, he said.

继续阅读

CSAPP-Lab:Data Lab

今天开坑写一个系列,记录自己做11个CSAPP配套Lab的过程。

本帖为第一个实验,Data Lab。

实验内容下载地址:http://csapp.cs.cmu.edu/3e/labs.html


目录:

  1. Data Lab
  2. Bomb Lab
  3. Attack Lab
  4. Buffer Lab (IA32)
  5. Architecture Lab
  6. Architecture Lab (Y86)
  7. Cache Lab
  8. Performance Lab
  9. Shell Lab
  10. Malloc Lab
  11. Proxy Lab

1.实验文件

实验文件解压后 有一个datalab-handout文件夹,里面有很多c文件,我们只需要在 bits.c里面编写程序,然后运行评测程序即可。

2.使用方法

bits.c文件里面有许多空函数,我们的工作就是根据函数的描述把空函数补充完整。
补充完整后,进行编译,使用make命令即可,make编译无错误后,运行btest程序./btest即可进行评测。

只测试单个函数:
./btest -f [函数名]

指定参数
./btest -f [函数名] -1 [参数1] -2 [参数2] -3……

输出调试
可以直接在bits.c文件里面调用printf方法输出调试信息,不需要包含stdio.h头文件。

3.实验内容:

//1
/* 
 * bitXor - x^y using only ~ and & 
 *   Example: bitXor(4, 5) = 1
 *   Legal ops: ~ &
 *   Max ops: 14
 *   Rating: 1
* bit异或
* 要求只用~和&完成异或操作
* 思路:第一题比较简单,任何逻辑操作都可以用~和&表达,异或也是,
* 去查一下亦或的等价表达式,用摩根公式简化一下即可 */ int bitXor(int x, int y) { int a = ~(~x & y); int b = ~( x & ~y); int c = ~( a & b); return c; } /* * tmin - return minimum two's complement integer * Legal ops: ! ~ & ^ | + << >> * Max ops: 4 * Rating: 1
* 返回补码表达的最小值
* 根据补码的知识,补码的最小值就是1000000……000B */ int tmin(void) { return 1<<31; } //2 /* * isTmax - returns 1 if x is the maximum, two's complement number, * and 0 otherwise * Legal ops: ! ~ & ^ | + * Max ops: 10 * Rating: 1
* 检验参数x是否是补码最大值
* 思路,补码最大值是0111……1111 用~(1<<31))得到0111……111 然后和x进行一下亦或操作即可,如果完全一直则得0,取反为1 */ int isTmax(int x) { return !(x^(~(1<<31))); } /* * allOddBits - return 1 if all odd-numbered bits in word set to 1 * where bits are numbered from 0 (least significant) to 31 (most significant) * Examples allOddBits(0xFFFFFFFD) = 0, allOddBits(0xAAAAAAAA) = 1 * Legal ops: ! ~ & ^ | + << >> * Max ops: 12 * Rating: 2 */ int allOddBits(int x) { int nX = ~x; return !( (nX&0xAA) | (nX&(0xAA<<8)) | (nX&(0xAA<<16)) | (nX&(0xAA<<24))); } /* * negate - return -x * Example: negate(1) = -1. * Legal ops: ! ~ & ^ | + << >> * Max ops: 5 * Rating: 2 */ int negate(int x) { return (~x)+1; } //3 /* * isAsciiDigit - return 1 if 0x30 <= x <= 0x39 (ASCII codes for characters '0' to '9') * Example: isAsciiDigit(0x35) = 1. * isAsciiDigit(0x3a) = 0. * isAsciiDigit(0x05) = 0. * Legal ops: ! ~ & ^ | + << >> * Max ops: 15 * Rating: 3 */ int isAsciiDigit(int x) { int a = !(!(x>>8));//验证高24位是否全为0(符合要求), int b = !(!(0x30^(x&0xF0))); int c1 = (0x08&x)>>3; int c2 = (0x04&x)>>2; int c3 = (0x02&x)>>1; int c = (c1 & c2) | (c1 & c3);//如果是0表示 低四位符合要求 // printf("x:0x%x a:0x%x b:0x%x c:0x%x c1:0x%x c2:0x%x c3:0x%x\n",x,a,b,c,c1,c2,c3); return !(a | b | c); } /* * conditional - same as x ? y : z * Example: conditional(2,4,5) = 4 * Legal ops: ! ~ & ^ | + << >> * Max ops: 16 * Rating: 3 */ int conditional(int x, int y, int z) { int a = ((!(!x))<<31)>>31; return (y&a) | (z&~a); } /* * isLessOrEqual - if x <= y then return 1, else return 0 * Example: isLessOrEqual(4,5) = 1. * Legal ops: ! ~ & ^ | + << >> * Max ops: 24 * Rating: 3 */ int isLessOrEqual(int x, int y) { int x_sign = x>>31&1; int y_sign = y>>31&1; int a = x_sign & (!y_sign); int b = !(x_sign^y_sign); int c = b & ((x+~y)>>31 & 1); return a | c; } //4 /* * logicalNeg - implement the ! operator, using all of * the legal operators except ! * Examples: logicalNeg(3) = 0, logicalNeg(0) = 1 * Legal ops: ~ & ^ | + << >> * Max ops: 12 * Rating: 4 */ int logicalNeg(int x) { int x_sign = (x>>31) & 1; int myx = x&(~(1<<31)); int a = (myx+~0)>>31; return (a & ((~x_sign)&1)); } /* howManyBits - return the minimum number of bits required to represent x in * two's complement * Examples: howManyBits(12) = 5 * howManyBits(298) = 10 * howManyBits(-5) = 4 * howManyBits(0) = 1 * howManyBits(-1) = 1 * howManyBits(0x80000000) = 32 * Legal ops: ! ~ & ^ | + << >> * Max ops: 90 * Rating: 4 */ int howManyBits(int x) { int b16,b8,b4,b2,b1,b0; int sign=x>>31; x = (sign&~x)|(~sign&x);//如果x为正则不变,否则按位取反(这样好找最高位为1的,原来是最高位为0的,这样也将符号位去掉了) // 不断缩小范围 b16 = !!(x>>16)<<4;//高十六位是否有1 x = x>>b16;//如果有(至少需要16位),则将原数右移16位 b8 = !!(x>>8)<<3;//剩余位高8位是否有1 x = x>>b8;//如果有(至少需要16+8=24位),则右移8位 b4 = !!(x>>4)<<2;//同理 x = x>>b4; b2 = !!(x>>2)<<1; x = x>>b2; b1 = !!(x>>1); x = x>>b1; b0 = x; return b16+b8+b4+b2+b1+b0+1;//+1表示加上符号位 }

2020-4-6 English Reading.

Price Gouging

Though Trump didn’t detail his concerns with 3M, White House trade adviser Peter Navarro said at a Thursday news conference that the administration has had concerns about whether the company’s production around the world is being delivered to the U.S.

Dallas Mavericks owner Mark Cuban said he has been in touch with the White House about supposed price gouging by resellers of 3M masks and accused the company of not doing enough to ensure they end up in the hands of medical professionals.

3M has previously said it hasn’t changed the prices it charges and can’t control the prices dealers or retailers charge for their products.

The president is facing mounting pressure from governors and congressional Democrats to use the Korean War-era defense law that gives him sweeping powers to force companies to produce personal protective equipment and ventilators that are in short supply. More than 236,000 people in the U.S. have contracted the virus and more than 5,600 have died, according to Johns Hopkins University.

Health-care officials and governors have said that in some localities, people may die because there won’t be enough ventilators for the growing number of patients who need them.

New York Governor Andrew Cuomo on Thursday said the state would run out of ventilators in six days at the current rate. “If a person comes in and needs a ventilator and you don’t have a ventilator, the person dies,” Cuomo told reporters.

Ventilator Shortage

Trump said at the White House later on Thursday that “thousands” of ventilators are in production. But he faulted states for failing to stockpile them, deflecting criticism of his administration.

“We’re not an ordering clerk, we’re a backup,” Trump said. “The states have to stock up. It’s like one of those things, they waited.”

He has expressed reluctance to use the defense law, comparing it to nationalizing industries. He has said he prefers to use threats to invoke the act as leverage to force companies to comply with demands to manufacture equipment.

The president, however, ordered General Motors Co. last Friday to make ventilators by directing the U.S. health secretary, under the defense law, to require the automaker to do so.

—With assistance from Ellen Proper.

source:

https://time.com/5815155/3m-face-masks-trump/

2020-4-5 English Reading.

President Donald Trump attacked 3M over concerns with supplies of protective face masks as his administration issued an order under the Defense Production Act to speed production of ventilators and respirators for coronavirus patients.

3M responded hours later with a statement, saying early Friday that it has increased production of respirator masks significantly and was already working with the administration to prioritize orders from the Federal Emergency Management Agency. The latest actions offer a framework to “expand even further the work we are doing in response to the global pandemic crisis,” 3M said.

继续阅读

2020-4-2 English Reading.

In August 2019, the Arizona Municipal Water Users Association built a 16-foot pyramid of jugs in its main entrance in Phoenix. The goal was to show residents of this desert region how much water they each use a day—120 gallons—and to encourage conservation.

“We must continue to do our part every day,” executive director Warren Tenney wrote in a blog post. “Some of us are still high-end water users who could look for more ways to use water a bit more wisely.”

A few weeks earlier in nearby Mesa, Google proposed a plan for a giant data center among the cacti and tumbleweeds. The town is a founding member of the Arizona Municipal Water Users Association, but water conservation took a back seat in the deal it struck with the largest U.S. internet company. Google is guaranteed 1 million gallons a day to cool the data center, and up to 4 million gallons a day if it hits project milestones. If that was a pyramid of water jugs, it would tower thousands of feet into Arizona’s cloudless sky.

继续阅读

apache2虚拟端口配置,在一台机器配置多个站点

环境:Ubuntu16.4  Apache/2.4.18

在server端,一个站点需要有一个独立的根目录,例如默认的站点就以/var/www/html/作为站点的根目录。浏览器给到一个http请求的时候,服务器就会在这个目录下面寻找需要返回的文件或信息。

浏览器请求server的时候,会包含一些域名信息,这样服务器就可以建立多个目录。当浏览器请求通过aaa.com或bbb.com发出http请求的时候,server就可以到对应的目录下面返回需要的信息。

在本环境下,进行多站点配置的目录主要是/etc/apache2/sites-available 和  /etc/apache2/sites-enabled。
前者是可用的站点配置,后者是启用的站点配置,而后者目录里面基本上是通过符号链接,链接到前者目录下面的内容的。

root@iZuf6ajm9b61u7hmifsrjaZ:/etc/apache2/sites-enabled# ls -l total 0 lrwxrwxrwx 1 root root 35 Aug 4 2019 000-default.conf -> ../sites-available/000-default.conf

默认的配置如上面,是一个符号链接链接到/sites-available下的文件,抽象的来说可以认为这两个目录下是同一个文件。

我们看下文件里面的内容:

root@iZuf6ajm9b61u7hmifsrjaZ:/etc/apache2/sites-available# cat 000-default.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request’s Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName www.inncc.ink

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html

# Available loglevels: trace8, …, trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with “a2disconf”.
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>

很清楚,里面描述了在80端口的一个站点,站点的目录是/var/www/html  ServerName www.inncc.ink对应域名。

所以我们直接把这个默认的文件cp两份,分别用作site1.com site2.com  修改ServerName 和DocumentRoot 即可。
修改完成后,在sites-enabled下面建立两个链接到这俩文件的符号链接即可。
文件名没有特殊的要求。

最后重启apache2 :service apache2 restart即可