Jekyll2023-10-05T22:10:35+00:00https://kindhearted57.github.io/feed.xml57’LandSlowly learning...
JRRrubujubi@gmail.comImposter Syndrome - Anxiety/Depression - Perfectionism -Gender2023-03-05T00:00:00+00:002023-03-05T00:00:00+00:00https://kindhearted57.github.io/2023/03/05/about-imposter-syndrome<p>Decide to write this one in Chinese with the hope that I can convey my idea better.
(但是写到最后变成了尴尬的中英混杂)</p>
<h3 id="起因">起因</h3>
<p>睡前随便打开了一个podcast,系列的题目叫做The Psychology of your 20’s,感觉很有趣,于是翻到第一篇,发现第一篇的题目叫<a href="https://open.spotify.com/episode/1FctRLPRJ3pKfDEeJSxUGs?si=Sk-mb9aHQkWRCK18NHgVew">The Psychology of Imposter Syndrome - why do you feel like such a fraud??</a> 这个时候我更加的被吸引了 – 说到20’s 的心理问题,第一反应可能会是情感/家庭/对未来迷茫之类。而Imposter Syndrome确实实实在在是我的最大问题。在过去的几年里,我的大部分时间用来科研或对科研焦虑,科研的大部分时间在Imposter Syndrome里煎熬。</p>
<p>本来是为了助眠打开的podcast,结果是越听越兴奋,这几项问题串起了我在过去很久一段时间的学习生活上的不悦,并且我自认为自己是比较孤单的在承受这些。</p>
<p>于是想整理一些对这期podcast的一些笔记📒。</p>
<h3 id="the-cycle">The cycle</h3>
<p>主持首先提出了她对大部分心理现象的观点:If it survives, it must have a purpose in nature. 而Imposter Syndrome存在的原因是什么呢?一个很有趣的观点是,如果从适者生存的角度来看的话,自恋是更符合自然选择的一种行为模式(自恋确实是一种人格障碍,Imposter syndrome并不是)。 目前大部分人的imposter syndrome产生的原因是peer preasure (以领英为首的社交媒体)触手可及。</p>
<p>Imposter Syndrome的cycle:</p>
<p><em>First stage</em>: 一个被指定的任务中产生的Anxiety(trigger)</p>
<p><em>Second stage</em>: I need to be special/the very best(anxiety leads to over preparation/perfectionist -> also leads to fear)</p>
<p><em>Third stage</em>: Superman/Superwoman expects. (Now that the person is convinced by the idea from the second stage that they need to be the very best, they will overwork, and believe that they have some superhuman ability, or need to adopt some superhuman ability in order to achieve the expectation )</p>
<p><em>Fourth stage</em>: The fear of failure. The syndrome is often exacerbated when it is an achievement related task, because the fear of failure is a possibility.</p>
<p><em>Fifth stage</em>: Denial of competence. This happens once the task is finished or near the end. There is difficulty internalizing the success and accepting praises as valid. This is not a display of false modesty, but because they set the expectation so high and they almost convince themselves that they need to have superhuman abilities to achieve the goal they have set out for. It is hard for them to take credit in the end. Because they often have the sense “there is something outside of me that allows me to do this”</p>
<p><em>Sixth stage</em>: Fear and guilt about success. Especially if the success is unusual amongst family and peers. Imposters will be less connected and more distant, and they will be overwhelmed by the difference and worry of being rejected by others.</p>
<p>我自己进入imposter syndrome的状态很类似于这个cycle。现在想来是微不足道又惭愧的。在看这些材料和写下这些文字的时候脑子里回顾了一遍自己的经历,但是实在没有勇气一起写下来,我还是偷偷记录这部分吧:)</p>
<p>除此之外,我认为还和我自己思考问题的模式有关系,这个在下一篇blog或许会写到。</p>
<p>主持认为最精确的对Imposter Syndrome的定义来自Austin Cammie:
Imposter Syndrome is a psychological phenomona, in which people are unable to internalize accomplishments.</p>
<h3 id="与其他disorder的联系">与其他disorder的联系</h3>
<p>Imposter Syndrome通常会伴有Anxiety/Depression,但至今它并没有被认为是一种disorder(Anxiety/Depression属于disorder),提到这一点是因为Imposter Syndrome不应该被认为成人格特征的一种(低自尊的/极度谦虚的)。而它没有被认为是disorder的原因是它常常属于患有Anxiety/Depression问题的人群的症状中的一环。</p>
<p>然而在一些情况下,Imposter Syndrome会严重到几乎delusional的程度。</p>
<p>Imposter Syndrome 和 perfectionism的关系:</p>
<p>They often go hand in hand.</p>
<p>Imposters tend to discount positive feedback; maintain high standards for self-evaluation. They are also very critical of their inability to realize these standards.</p>
<p>Feel self-conscious about what they do -> leads to lots of self-reflection.</p>
<p>(Perfectionism这一部分几乎涵盖了我去counselling聊的所有内容…)</p>
<h3 id="其他因素">其他因素</h3>
<p>家庭:</p>
<p>Imposter syndrome与personality和disposition有关,也就是一个有imposter倾向的人很难改变这一点。另外一个来源是成长期不稳定的外界评价,比如父母/教师有时赞扬你很聪明,有时又开始批评你,并且分界不明的话,你自己也会找不到评价自己的标准,从而出现imposter syndrome。原文说的是You will not think that your accomplishment is consistent.</p>
<p>另外Imposter Syndrome还会影响attachment style,因为imposters想从中获取constant positive feedback。</p>
<p>一个有趣的发现是一些强调natural intelligence rather than developed intelligence的家庭中imposters的出现几率更大,因为imposters无法从自己获取了developed intelligence中得到成就感。</p>
<p>性别/种族:</p>
<p>除此之外,这期节目的另外一个很重要的观点是Imposter Syndrome在女性和有色人种中出现的比例更大。然而对这两个话题我有太多想说的话太多想记录的事情,暂时还没有勇气写下来。希望以后能更加详细的专门写出来。</p>JRRrubujubi@gmail.comDecide to write this one in Chinese with the hope that I can convey my idea better. (但是写到最后变成了尴尬的中英混杂) 起因 睡前随便打开了一个podcast,系列的题目叫做The Psychology of your 20’s,感觉很有趣,于是翻到第一篇,发现第一篇的题目叫The Psychology of Imposter Syndrome - why do you feel like such a fraud?? 这个时候我更加的被吸引了 – 说到20’s 的心理问题,第一反应可能会是情感/家庭/对未来迷茫之类。而Imposter Syndrome确实实实在在是我的最大问题。在过去的几年里,我的大部分时间用来科研或对科研焦虑,科研的大部分时间在Imposter Syndrome里煎熬。 本来是为了助眠打开的podcast,结果是越听越兴奋,这几项问题串起了我在过去很久一段时间的学习生活上的不悦,并且我自认为自己是比较孤单的在承受这些。 于是想整理一些对这期podcast的一些笔记📒。 The cycle 主持首先提出了她对大部分心理现象的观点:If it survives, it must have a purpose in nature. 而Imposter Syndrome存在的原因是什么呢?一个很有趣的观点是,如果从适者生存的角度来看的话,自恋是更符合自然选择的一种行为模式(自恋确实是一种人格障碍,Imposter syndrome并不是)。 目前大部分人的imposter syndrome产生的原因是peer preasure (以领英为首的社交媒体)触手可及。 Imposter Syndrome的cycle: First stage: 一个被指定的任务中产生的Anxiety(trigger) Second stage: I need to be special/the very best(anxiety leads to over preparation/perfectionist -> also leads to fear) Third stage: Superman/Superwoman expects. (Now that the person is convinced by the idea from the second stage that they need to be the very best, they will overwork, and believe that they have some superhuman ability, or need to adopt some superhuman ability in order to achieve the expectation ) Fourth stage: The fear of failure. The syndrome is often exacerbated when it is an achievement related task, because the fear of failure is a possibility. Fifth stage: Denial of competence. This happens once the task is finished or near the end. There is difficulty internalizing the success and accepting praises as valid. This is not a display of false modesty, but because they set the expectation so high and they almost convince themselves that they need to have superhuman abilities to achieve the goal they have set out for. It is hard for them to take credit in the end. Because they often have the sense “there is something outside of me that allows me to do this” Sixth stage: Fear and guilt about success. Especially if the success is unusual amongst family and peers. Imposters will be less connected and more distant, and they will be overwhelmed by the difference and worry of being rejected by others. 我自己进入imposter syndrome的状态很类似于这个cycle。现在想来是微不足道又惭愧的。在看这些材料和写下这些文字的时候脑子里回顾了一遍自己的经历,但是实在没有勇气一起写下来,我还是偷偷记录这部分吧:) 除此之外,我认为还和我自己思考问题的模式有关系,这个在下一篇blog或许会写到。 主持认为最精确的对Imposter Syndrome的定义来自Austin Cammie: Imposter Syndrome is a psychological phenomona, in which people are unable to internalize accomplishments. 与其他disorder的联系 Imposter Syndrome通常会伴有Anxiety/Depression,但至今它并没有被认为是一种disorder(Anxiety/Depression属于disorder),提到这一点是因为Imposter Syndrome不应该被认为成人格特征的一种(低自尊的/极度谦虚的)。而它没有被认为是disorder的原因是它常常属于患有Anxiety/Depression问题的人群的症状中的一环。 然而在一些情况下,Imposter Syndrome会严重到几乎delusional的程度。 Imposter Syndrome 和 perfectionism的关系: They often go hand in hand. Imposters tend to discount positive feedback; maintain high standards for self-evaluation. They are also very critical of their inability to realize these standards. Feel self-conscious about what they do -> leads to lots of self-reflection. (Perfectionism这一部分几乎涵盖了我去counselling聊的所有内容…) 其他因素 家庭: Imposter syndrome与personality和disposition有关,也就是一个有imposter倾向的人很难改变这一点。另外一个来源是成长期不稳定的外界评价,比如父母/教师有时赞扬你很聪明,有时又开始批评你,并且分界不明的话,你自己也会找不到评价自己的标准,从而出现imposter syndrome。原文说的是You will not think that your accomplishment is consistent. 另外Imposter Syndrome还会影响attachment style,因为imposters想从中获取constant positive feedback。 一个有趣的发现是一些强调natural intelligence rather than developed intelligence的家庭中imposters的出现几率更大,因为imposters无法从自己获取了developed intelligence中得到成就感。 性别/种族: 除此之外,这期节目的另外一个很重要的观点是Imposter Syndrome在女性和有色人种中出现的比例更大。然而对这两个话题我有太多想说的话太多想记录的事情,暂时还没有勇气写下来。希望以后能更加详细的专门写出来。ssh出错记录2021-10-09T00:00:00+00:002021-10-09T00:00:00+00:00https://kindhearted57.github.io/2021/10/09/ssh%E9%98%B6%E6%AE%B5%E6%80%A7%E5%AD%A6%E4%B9%A0<h2 id="ssh-无法连接">ssh 无法连接</h2>
<p>查看<code class="language-plaintext highlighter-rouge">auth.log</code>以及<code class="language-plaintext highlighter-rouge">auth.log.1</code>,发现蹊跷的地方大概是<code class="language-plaintext highlighter-rouge">pam_unix(gdm-password:auth): authentication failure; logname= uid=0 euid=0 tty=/dev/tty2 ruser= rhost= user=jr</code></p>
<p>用来检查sshd的config文件是否有错误<code class="language-plaintext highlighter-rouge">/usr/sbin/sshd -T</code></p>
<p>可能跟密码相关
<a href="https://blog.csdn.net/qq_32169769/article/details/73849470?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_baidulandingword-1&spm=1001.2101.3001.4242">曾经重置过公私钥</a></p>
<p>在主机端,<code class="language-plaintext highlighter-rouge">/usr/sbin/sshd -dddd -D</code></p>
<p>结果得到</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>debug2: load_server_config: filename /etc/ssh/sshd_config
debug2: load_server_config: done config len = 276
debug2: parse_server_config: config /etc/ssh/sshd_config len 276
debug3: /etc/ssh/sshd_config:56 setting PasswordAuthentication yes
debug3: /etc/ssh/sshd_config:63 setting ChallengeResponseAuthentication no
debug3: /etc/ssh/sshd_config:91 setting X11Forwarding yes
debug3: /etc/ssh/sshd_config:95 setting PrintMotd no
debug3: /etc/ssh/sshd_config:114 setting AcceptEnv LANG LC_*
debug3: /etc/ssh/sshd_config:117 setting Subsystem sftp /usr/lib/openssh/sftp-server
debug1: sshd version OpenSSH_7.6, OpenSSL 1.0.2n 7 Dec 2017
debug1: private host key #0: ssh-rsa SHA256:rzmlFxxr56FVOtovqQSlbGNU/YQrDSZCLw4EPUkiRTs
debug1: private host key #1: ecdsa-sha2-nistp256 SHA256:D7epphcGuNjRbHzHl0L53mWw5yUCQLdO4guA0tRIrXU
debug1: private host key #2: ssh-ed25519 SHA256:yRCqnEmmCSJOzpjpocpGqIs1sk7dfOHaiP9xjLBPJ3U
debug1: rexec_argv[0]='/usr/sbin/sshd'
debug1: rexec_argv[1]='-dddd'
debug1: rexec_argv[2]='-D'
debug3: oom_adjust_setup
debug1: Set /proc/self/oom_score_adj from 0 to -1000
debug2: fd 3 setting O_NONBLOCK
debug1: Bind to port 22 on 0.0.0.0.
Bind to port 22 on 0.0.0.0 failed: Address already in use.
debug2: fd 3 setting O_NONBLOCK
debug3: sock_set_v6only: set socket 3 IPV6_V6ONLY
debug1: Bind to port 22 on ::.
Bind to port 22 on :: failed: Address already in use.
Cannot bind any address.
</code></pre></div></div>
<p><a href="https://serverfault.com/questions/351327/ssh-error-bind-to-port-22-failed-address-already-in-use">参考</a></p>
<p><a href="https://www.sysgeek.cn/ubuntu-disable-ipv6/"></a>
<a href="https://askubuntu.com/questions/1109934/ssh-server-stops-working-after-reboot-caused-by-missing-var-run-sshd">final solution</a>
于是手动创建了/var/run/sshd</p>
<p>然而/var/log/auth.log仍然显示</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>received signal 15; terminating
</code></pre></div></div>
<p>这个后来发现是自己service stop留下来的印记 佛了</p>
<p>最终的最终,发现是当时在学校的公网里面学校关了80端口,在ssh的时候换个端口,比如指定8022就好了。</p>
<h2 id="不知如何使用scp传输文件">不知如何使用scp传输文件</h2>
<p>本机子网掩码0xffffff00,服务器子网掩码0xff000000,本机已关闭防火墙,22端口开放,从本机可ping服务器,可ssh,scp传送文件,从服务器无法ping本机。</p>
<p>后来发现是我没有理解在ssh这个过程中公私钥的使用问题。参考一篇<a href="https://zhuanlan.zhihu.com/p/89872671">知乎回答</a>详细学习了一下。反思了前面所陈述的问题,结合ssh中公私钥的使用,我们来分析一下。</p>
<p>首先在ssh进行登录的时候,有几种情况。</p>
<ul>
<li>
<p>密码口令登陆
流程:客户端连接上服务器,服务器把自己的公钥传给客户端 -> 客户端输入服务器密码通过公钥加密之后传给服务器 -> 服务器根据自己的私钥解密登录密码,如果正确就让客户端登陆。</p>
</li>
<li>
<p>公钥登陆
流程:客户端生成RSA公钥和私钥 -> 客户端将自己的公钥存放到服务器 -> 客户端请求连接服务器,服务器将一个随机字符串发送给客户端 -> 客户端根据自己的私钥加密随机字符串再发送给服务器 -> 服务器接收到加密后的字符串之后用公钥解密,如果正确就让客户端登录,否则拒绝。</p>
</li>
</ul>
<p>而从上面这个过程可以看出来,我本地保存了服务器的公钥,但是本地的公钥并没有提供给服务器。所以我在服务器scp想传送给本机文件的时候,由于找不到这个公钥,就没办法在服务器上scp xxx文件 mypc@xxxx: / / / 这样传送。但是有个方法是,在我的本机上,scp targetserver@xxxx: /// ./location/on/mypc 这样传递文件。</p>JRRrubujubi@gmail.comssh 无法连接 查看auth.log以及auth.log.1,发现蹊跷的地方大概是pam_unix(gdm-password:auth): authentication failure; logname= uid=0 euid=0 tty=/dev/tty2 ruser= rhost= user=jr 用来检查sshd的config文件是否有错误/usr/sbin/sshd -T 可能跟密码相关 曾经重置过公私钥 在主机端,/usr/sbin/sshd -dddd -D 结果得到 debug2: load_server_config: filename /etc/ssh/sshd_config debug2: load_server_config: done config len = 276 debug2: parse_server_config: config /etc/ssh/sshd_config len 276 debug3: /etc/ssh/sshd_config:56 setting PasswordAuthentication yes debug3: /etc/ssh/sshd_config:63 setting ChallengeResponseAuthentication no debug3: /etc/ssh/sshd_config:91 setting X11Forwarding yes debug3: /etc/ssh/sshd_config:95 setting PrintMotd no debug3: /etc/ssh/sshd_config:114 setting AcceptEnv LANG LC_* debug3: /etc/ssh/sshd_config:117 setting Subsystem sftp /usr/lib/openssh/sftp-server debug1: sshd version OpenSSH_7.6, OpenSSL 1.0.2n 7 Dec 2017 debug1: private host key #0: ssh-rsa SHA256:rzmlFxxr56FVOtovqQSlbGNU/YQrDSZCLw4EPUkiRTs debug1: private host key #1: ecdsa-sha2-nistp256 SHA256:D7epphcGuNjRbHzHl0L53mWw5yUCQLdO4guA0tRIrXU debug1: private host key #2: ssh-ed25519 SHA256:yRCqnEmmCSJOzpjpocpGqIs1sk7dfOHaiP9xjLBPJ3U debug1: rexec_argv[0]='/usr/sbin/sshd' debug1: rexec_argv[1]='-dddd' debug1: rexec_argv[2]='-D' debug3: oom_adjust_setup debug1: Set /proc/self/oom_score_adj from 0 to -1000 debug2: fd 3 setting O_NONBLOCK debug1: Bind to port 22 on 0.0.0.0. Bind to port 22 on 0.0.0.0 failed: Address already in use. debug2: fd 3 setting O_NONBLOCK debug3: sock_set_v6only: set socket 3 IPV6_V6ONLY debug1: Bind to port 22 on ::. Bind to port 22 on :: failed: Address already in use. Cannot bind any address. 参考 final solution 于是手动创建了/var/run/sshd 然而/var/log/auth.log仍然显示 received signal 15; terminating 这个后来发现是自己service stop留下来的印记 佛了 最终的最终,发现是当时在学校的公网里面学校关了80端口,在ssh的时候换个端口,比如指定8022就好了。 不知如何使用scp传输文件 本机子网掩码0xffffff00,服务器子网掩码0xff000000,本机已关闭防火墙,22端口开放,从本机可ping服务器,可ssh,scp传送文件,从服务器无法ping本机。 后来发现是我没有理解在ssh这个过程中公私钥的使用问题。参考一篇知乎回答详细学习了一下。反思了前面所陈述的问题,结合ssh中公私钥的使用,我们来分析一下。 首先在ssh进行登录的时候,有几种情况。 密码口令登陆 流程:客户端连接上服务器,服务器把自己的公钥传给客户端 -> 客户端输入服务器密码通过公钥加密之后传给服务器 -> 服务器根据自己的私钥解密登录密码,如果正确就让客户端登陆。 公钥登陆 流程:客户端生成RSA公钥和私钥 -> 客户端将自己的公钥存放到服务器 -> 客户端请求连接服务器,服务器将一个随机字符串发送给客户端 -> 客户端根据自己的私钥加密随机字符串再发送给服务器 -> 服务器接收到加密后的字符串之后用公钥解密,如果正确就让客户端登录,否则拒绝。 而从上面这个过程可以看出来,我本地保存了服务器的公钥,但是本地的公钥并没有提供给服务器。所以我在服务器scp想传送给本机文件的时候,由于找不到这个公钥,就没办法在服务器上scp xxx文件 mypc@xxxx: / / / 这样传送。但是有个方法是,在我的本机上,scp targetserver@xxxx: /// ./location/on/mypc 这样传递文件。解决homebrew卡顿的问题2021-09-10T00:00:00+00:002021-09-10T00:00:00+00:00https://kindhearted57.github.io/2021/09/10/Homebrew<h1 id="homebrew">Homebrew</h1>
<h2 id="homebrew的组成部件">Homebrew的组成部件</h2>
<p>Homebrew的问题在我这里存在了很久了,但是我一直都没有管。之前解决的方法是在updating homebrew卡到∞时间的时候按下ctrl+C。今天决定解决一下这个问题,发现其实并非难事。</p>
<p><a href="https://www.cnblogs.com/feiquan/p/13267284.html">参考</a></p>
<p>然而后来发现换源也不是太好用。</p>
<p>从<a href=""></a>知乎回答看到,brew支持全局代理。于是</p>
<p><code class="language-plaintext highlighter-rouge">export ALL_PROXY=socks5://127.0.0.1:10808</code></p>
<p><code class="language-plaintext highlighter-rouge">Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask failed!</code></p>
<p><code class="language-plaintext highlighter-rouge">brew update-reset</code></p>
<p>之后</p>
<p><code class="language-plaintext highlighter-rouge">source ~/.zshrc</code></p>JRRrubujubi@gmail.comHomebrew Homebrew的组成部件 Homebrew的问题在我这里存在了很久了,但是我一直都没有管。之前解决的方法是在updating homebrew卡到∞时间的时候按下ctrl+C。今天决定解决一下这个问题,发现其实并非难事。 参考 然而后来发现换源也不是太好用。 从知乎回答看到,brew支持全局代理。于是 export ALL_PROXY=socks5://127.0.0.1:10808 Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask failed! brew update-reset 之后 source ~/.zshrcLeetcoding notebook2021-08-22T00:00:00+00:002021-08-22T00:00:00+00:00https://kindhearted57.github.io/2021/08/22/%E5%81%9A%E9%A2%98%E8%AE%B0%E5%BD%95<h1 id="做题记录">做题记录</h1>
<h2 id="题目1">题目1</h2>
<p>以数组 intervals 表示若干个区间的集合,其中单个区间为 intervals[i] = [starti, endi] 。请你合并所有重叠的区间,并返回一个不重叠的区间数组,该数组需恰好覆盖输入中的所有区间。</p>
<p>示例 1:</p>
<p>输入:intervals = [[1,3],[2,6],[8,10],[15,18]]
输出:[[1,6],[8,10],[15,18]]
解释:区间 [1,3] 和 [2,6] 重叠, 将它们合并为 [1,6].
示例 2:</p>
<p>输入:intervals = [[1,4],[4,5]]
输出:[[1,5]]
解释:区间 [1,4] 和 [4,5] 可被视为重叠区间。</p>
<p>提示:</p>
<p>1 <= intervals.length <= 104
intervals[i].length == 2
0 <= starti <= endi <= 104</p>
<h2 id="我的attempt1">我的Attempt1</h2>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>class Solution:
def merge(self, intervals) :
result_list = []
flag_list = [0]*len(intervals)
for temp1 in intervals:
for temp2 in intervals:
if temp1 != temp2:
if (temp2[0] <= temp1[1]) and (temp2[0] >= temp1[0]):
if temp2[1] > temp1[1]:
extended_list = [temp1[0],temp2[1]]
result_list.append(extended_list)
flag_list[intervals.index(temp1)] = 1
flag_list[intervals.index(temp2)] = 1
else:
extended_list = [temp1[0],temp1[1]]
result_list.append(extended_list)
flag_list[intervals.index(temp1)] = 1
flag_list[intervals.index(temp2)] = 1
for i in range(len(flag_list)):
if flag_list[i] == 0:
result_list.append(intervals[i])
result_list_sorted = []
for i in result_list:
if i not in result_list_sorted:
result_list_sorted.append(i)
return result_list_sorted
</code></pre></div></div>
<h2 id="官方解法">官方解法</h2>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>class Solution:
def merge(self, intervals: List[List[int]]) -> List[List[int]]:
intervals.sort(key=lambda x: x[0])
merged = []
for interval in intervals:
# 如果列表为空,或者当前区间与上一区间不重合,直接添加
if not merged or merged[-1][1] < interval[0]:
merged.append(interval)
else:
# 否则的话,我们就可以与上一区间进行合并
merged[-1][1] = max(merged[-1][1], interval[1])
return merged
</code></pre></div></div>
<h2 id="看了官方解法没有看代码实现之后写的解法">看了官方解法没有看代码实现之后写的解法</h2>
<p>这个要比官方解法慢个好多</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>class Solution:
def merge(self, intervals) :
intervals.sort(key = lambda x: x[0])
merged = []
merged.append(intervals[0])
for i in intervals:
if i[0]<= merged[-1][1]:
temp = [merged[-1][0],max(merged[-1][1],i[1])]
print(merged[-1][1])
print(i[1])
print(temp)
merged.pop(-1)
merged.append(temp)
else:
merged.append(i)
return merged
obj = Solution()
print(obj.merge([[1,3],[2,6],[8,10],[15,18]]))
</code></pre></div></div>
<h3 id="学到的">学到的</h3>
<p>1 遇到问题不要总是想着暴力解决,比如在这个题目中先排个序或许就会更好。</p>
<p>2 注意时间和空间消耗,尽量减少中间变量的出现。</p>
<h2 id="题目2">题目2</h2>
<p>给你一个由 ’1’(陆地)和 ‘0’(水)组成的的二维网格,请你计算网格中岛屿的数量。</p>
<p>岛屿总是被水包围,并且每座岛屿只能由水平方向和/或竖直方向上相邻的陆地连接形成。</p>
<p>此外,你可以假设该网格的四条边均被水包围。</p>
<p> </p>
<p>示例 1:</p>
<p>输入:grid = [
[“1”,”1”,”1”,”1”,”0”],
[“1”,”1”,”0”,”1”,”0”],
[“1”,”1”,”0”,”0”,”0”],
[“0”,”0”,”0”,”0”,”0”]
]
输出:1
示例 2:</p>
<p>输入:grid = [
[“1”,”1”,”0”,”0”,”0”],
[“1”,”1”,”0”,”0”,”0”],
[“0”,”0”,”1”,”0”,”0”],
[“0”,”0”,”0”,”1”,”1”]
]
输出:3
</p>
<p>提示:</p>
<p>m == grid.length</p>
<p>n == grid[i].length</p>
<p>1 <= m, n <= 300</p>
<p>grid[i][j] 的值为 ‘0’ 或 ‘1’</p>
<h2 id="官方解法-1">官方解法</h2>
<p>DFS</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>class Solution:
def dfs(self, grid, r, c):
grid[r][c] = 0
nr, nc = len(grid), len(grid[0])
for x, y in [(r - 1, c), (r + 1, c), (r, c - 1), (r, c + 1)]:
if 0 <= x < nr and 0 <= y < nc and grid[x][y] == "1":
self.dfs(grid, x, y)
def numIslands(self, grid: List[List[str]]) -> int:
nr = len(grid)
if nr == 0:
return 0
nc = len(grid[0])
num_islands = 0
for r in range(nr):
for c in range(nc):
if grid[r][c] == "1":
num_islands += 1
self.dfs(grid, r, c)
return num_islands
</code></pre></div></div>
<p>本科的时候写代码写的太差现在做题遭报应了。 这个题目看了半天才能看懂,下一个感悟是在看不懂解题方法的时候可以通过使用测试用例跟着代码一步一步向下推进而进行。</p>
<p>这个解法可以看作当通过递归找到一片岛的时候,使用海水将这片岛给淹没,然后再去找下一片岛。</p>
<p>BFS</p>
<p>这个BFS的代码贴一下,但是我看起来反正和DFS是一样的。。</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>class Solution:
def numIslands(self, grid: List[List[str]]) -> int:
nr = len(grid)
if nr == 0:
return 0
nc = len(grid[0])
num_islands = 0
for r in range(nr):
for c in range(nc):
if grid[r][c] == "1":
num_islands += 1
grid[r][c] = "0"
neighbors = collections.deque([(r, c)])
while neighbors:
row, col = neighbors.popleft()
for x, y in [(row - 1, col), (row + 1, col), (row, col - 1), (row, col + 1)]:
if 0 <= x < nr and 0 <= y < nc and grid[x][y] == "1":
neighbors.append((x, y))
grid[x][y] = "0"
return num_islands
</code></pre></div></div>
<p>并查集</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>class UnionFind:
def __init__(self, grid):
m, n =len(grid),len(grid[0])
self.count = 0
self.parent = [-1]* (m*n)
self.rank = [0] *(m*n)
for i in range(m):
for j in range(n):
if grid[i][j] == "1":
self.parent[i*n+j] = i*n+j
self.count+=1
def find(self, i):
if self.parent[i] != i:
self.parent[i] = self.find(self.parent[i])
return self.parent[i]
def union(self, x, y):
rootx = self.find(x)
rooty = self.find(y)
if rootx != rooty:
if self.rank[rootx] < self.rank[rooty]:
rootx, rooty = rooty, rootx
self.parent[rooty] = rootx
if self.rank[rootx] == self.rank[rooty]:
rootx, rooty = rooty, rootx
self.parent[rooty] = rootx
def getCount(self):
return self.count
class Solution:
def numIslands(self, grid: List[List[str]]) -> int:
nr = len(grid)
if nr ==0:
return 0
nc = len(grid[0])
uf = UnionFind(grid)
num_islands = 0
for r in range(nr):
for c in range(nc):
if grid[r][c] == '1':
grid[r][c] = '0'
for x,y in [(r-1, c), (r + 1, c), (r, c - 1), (r, c + 1)]:
if 0 <= x < nr and 0 <=y < nc and grid[x][y] == "1":
uf.union(r*nc+c, x*nc+y)
</code></pre></div></div>
<h1 id="其他内容">其他内容</h1>
<h2 id="函数的声明方式">函数的声明方式</h2>
<p>刚刚开始做题的时候一直搞不懂这个是啥意思,后来翻到了python的<a href="https://docs.python.org/3.5/library/typing.html">官方文档</a>,在3.5版本之后有介绍。</p>JRRrubujubi@gmail.com做题记录 题目1 以数组 intervals 表示若干个区间的集合,其中单个区间为 intervals[i] = [starti, endi] 。请你合并所有重叠的区间,并返回一个不重叠的区间数组,该数组需恰好覆盖输入中的所有区间。 示例 1: 输入:intervals = [[1,3],[2,6],[8,10],[15,18]] 输出:[[1,6],[8,10],[15,18]] 解释:区间 [1,3] 和 [2,6] 重叠, 将它们合并为 [1,6]. 示例 2: 输入:intervals = [[1,4],[4,5]] 输出:[[1,5]] 解释:区间 [1,4] 和 [4,5] 可被视为重叠区间。 提示: 1 <= intervals.length <= 104 intervals[i].length == 2 0 <= starti <= endi <= 104 我的Attempt1 class Solution: def merge(self, intervals) : result_list = [] flag_list = [0]*len(intervals) for temp1 in intervals: for temp2 in intervals: if temp1 != temp2: if (temp2[0] <= temp1[1]) and (temp2[0] >= temp1[0]): if temp2[1] > temp1[1]: extended_list = [temp1[0],temp2[1]] result_list.append(extended_list) flag_list[intervals.index(temp1)] = 1 flag_list[intervals.index(temp2)] = 1 else: extended_list = [temp1[0],temp1[1]] result_list.append(extended_list) flag_list[intervals.index(temp1)] = 1 flag_list[intervals.index(temp2)] = 1 for i in range(len(flag_list)): if flag_list[i] == 0: result_list.append(intervals[i]) result_list_sorted = [] for i in result_list: if i not in result_list_sorted: result_list_sorted.append(i) return result_list_sorted 官方解法 class Solution: def merge(self, intervals: List[List[int]]) -> List[List[int]]: intervals.sort(key=lambda x: x[0]) merged = [] for interval in intervals: # 如果列表为空,或者当前区间与上一区间不重合,直接添加 if not merged or merged[-1][1] < interval[0]: merged.append(interval) else: # 否则的话,我们就可以与上一区间进行合并 merged[-1][1] = max(merged[-1][1], interval[1]) return merged 看了官方解法没有看代码实现之后写的解法 这个要比官方解法慢个好多 class Solution: def merge(self, intervals) : intervals.sort(key = lambda x: x[0]) merged = [] merged.append(intervals[0]) for i in intervals: if i[0]<= merged[-1][1]: temp = [merged[-1][0],max(merged[-1][1],i[1])] print(merged[-1][1]) print(i[1]) print(temp) merged.pop(-1) merged.append(temp) else: merged.append(i) return merged obj = Solution() print(obj.merge([[1,3],[2,6],[8,10],[15,18]])) 学到的 1 遇到问题不要总是想着暴力解决,比如在这个题目中先排个序或许就会更好。 2 注意时间和空间消耗,尽量减少中间变量的出现。 题目2 给你一个由 ’1’(陆地)和 ‘0’(水)组成的的二维网格,请你计算网格中岛屿的数量。 岛屿总是被水包围,并且每座岛屿只能由水平方向和/或竖直方向上相邻的陆地连接形成。 此外,你可以假设该网格的四条边均被水包围。 示例 1: 输入:grid = [ [“1”,”1”,”1”,”1”,”0”], [“1”,”1”,”0”,”1”,”0”], [“1”,”1”,”0”,”0”,”0”], [“0”,”0”,”0”,”0”,”0”] ] 输出:1 示例 2: 输入:grid = [ [“1”,”1”,”0”,”0”,”0”], [“1”,”1”,”0”,”0”,”0”], [“0”,”0”,”1”,”0”,”0”], [“0”,”0”,”0”,”1”,”1”] ] 输出:3 提示: m == grid.length n == grid[i].length 1 <= m, n <= 300 grid[i][j] 的值为 ‘0’ 或 ‘1’ 官方解法 DFS class Solution: def dfs(self, grid, r, c): grid[r][c] = 0 nr, nc = len(grid), len(grid[0]) for x, y in [(r - 1, c), (r + 1, c), (r, c - 1), (r, c + 1)]: if 0 <= x < nr and 0 <= y < nc and grid[x][y] == "1": self.dfs(grid, x, y) def numIslands(self, grid: List[List[str]]) -> int: nr = len(grid) if nr == 0: return 0 nc = len(grid[0]) num_islands = 0 for r in range(nr): for c in range(nc): if grid[r][c] == "1": num_islands += 1 self.dfs(grid, r, c) return num_islands 本科的时候写代码写的太差现在做题遭报应了。 这个题目看了半天才能看懂,下一个感悟是在看不懂解题方法的时候可以通过使用测试用例跟着代码一步一步向下推进而进行。 这个解法可以看作当通过递归找到一片岛的时候,使用海水将这片岛给淹没,然后再去找下一片岛。 BFS 这个BFS的代码贴一下,但是我看起来反正和DFS是一样的。。 class Solution: def numIslands(self, grid: List[List[str]]) -> int: nr = len(grid) if nr == 0: return 0 nc = len(grid[0]) num_islands = 0 for r in range(nr): for c in range(nc): if grid[r][c] == "1": num_islands += 1 grid[r][c] = "0" neighbors = collections.deque([(r, c)]) while neighbors: row, col = neighbors.popleft() for x, y in [(row - 1, col), (row + 1, col), (row, col - 1), (row, col + 1)]: if 0 <= x < nr and 0 <= y < nc and grid[x][y] == "1": neighbors.append((x, y)) grid[x][y] = "0" return num_islands 并查集 class UnionFind: def __init__(self, grid): m, n =len(grid),len(grid[0]) self.count = 0 self.parent = [-1]* (m*n) self.rank = [0] *(m*n) for i in range(m): for j in range(n): if grid[i][j] == "1": self.parent[i*n+j] = i*n+j self.count+=1 def find(self, i): if self.parent[i] != i: self.parent[i] = self.find(self.parent[i]) return self.parent[i] def union(self, x, y): rootx = self.find(x) rooty = self.find(y) if rootx != rooty: if self.rank[rootx] < self.rank[rooty]: rootx, rooty = rooty, rootx self.parent[rooty] = rootx if self.rank[rootx] == self.rank[rooty]: rootx, rooty = rooty, rootx self.parent[rooty] = rootx def getCount(self): return self.count class Solution: def numIslands(self, grid: List[List[str]]) -> int: nr = len(grid) if nr ==0: return 0 nc = len(grid[0]) uf = UnionFind(grid) num_islands = 0 for r in range(nr): for c in range(nc): if grid[r][c] == '1': grid[r][c] = '0' for x,y in [(r-1, c), (r + 1, c), (r, c - 1), (r, c + 1)]: if 0 <= x < nr and 0 <=y < nc and grid[x][y] == "1": uf.union(r*nc+c, x*nc+y) 其他内容 函数的声明方式 刚刚开始做题的时候一直搞不懂这个是啥意思,后来翻到了python的官方文档,在3.5版本之后有介绍。JS Learning2021-08-16T00:00:00+00:002021-08-16T00:00:00+00:00https://kindhearted57.github.io/2021/08/16/javascript<p>#JS Notebook</p>
<p>曾经突击学过Javascript,但是过于仓促很多东西都没有好好理解,现在趁着做ethernaut的功夫复习一下javascript,这里面做一些笔记。</p>
<p>1 修改元素</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>document.getElementById("demo").innerHTML = "段落已修改。";
</code></pre></div></div>
<p>用<code class="language-plaintext highlighter-rouge">getElementsByClassName</code>修改发现改不掉,之后发现这个返回的是一个list,如下方法可以修改。</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>document.getElementsByClassName("intro").innerHTML="test";
x = document.getElementsByClassName("intro");
x[0].innerHTML="test"
</code></pre></div></div>
<p>2 Javascript 对大小写敏感</p>
<p>3 javascript中用分号来结束语句是可选的</p>
<p>4 注释</p>
<p>单行注释 <code class="language-plaintext highlighter-rouge">\\</code></p>
<p>多行注释 <code class="language-plaintext highlighter-rouge">/**/</code></p>
<p>5 let/const/var</p>
<p>6 向未声明的Javascript变量分配值,该变量自动作为window的一个属性。</p>
<p><code class="language-plaintext highlighter-rouge">carname = "Volvo";</code></p>
<p>将声明window的一个属性carname。</p>
<p>7 关于node.js和javascript的区别,参考廖雪峰的<a href="https://www.liaoxuefeng.com/wiki/1022910821149312/1023025635916288">js教程</a></p>
<p>8</p>JRRrubujubi@gmail.com#JS Notebook 曾经突击学过Javascript,但是过于仓促很多东西都没有好好理解,现在趁着做ethernaut的功夫复习一下javascript,这里面做一些笔记。 1 修改元素 document.getElementById("demo").innerHTML = "段落已修改。"; 用getElementsByClassName修改发现改不掉,之后发现这个返回的是一个list,如下方法可以修改。 document.getElementsByClassName("intro").innerHTML="test"; x = document.getElementsByClassName("intro"); x[0].innerHTML="test" 2 Javascript 对大小写敏感 3 javascript中用分号来结束语句是可选的 4 注释 单行注释 \\ 多行注释 /**/ 5 let/const/var 6 向未声明的Javascript变量分配值,该变量自动作为window的一个属性。 carname = "Volvo"; 将声明window的一个属性carname。 7 关于node.js和javascript的区别,参考廖雪峰的js教程 8Git学习笔记2021-08-15T00:00:00+00:002021-08-15T00:00:00+00:00https://kindhearted57.github.io/2021/08/15/Git%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0<h1 id="git学习笔记">Git学习笔记</h1>
<p>跟<a href="https://www.liaoxuefeng.com/wiki/896043488029600">廖雪峰</a>的教程学的,在这里记点自己看也没啥用别人看更没用的笔记</p>
<h2 id="账号设置">账号设置</h2>
<p>在安装完git之后,输入</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git config --global user.name "Your Name"
git config --global user.email "email@example.com"
</code></pre></div></div>
<h2 id="创建版本库">创建版本库</h2>
<p>创建一个空目录</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>mkdir learngit
cd learngit
pwd
(PWD) 显示当前目录
</code></pre></div></div>
<p>把目录变成git可以管理的仓库</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git init
</code></pre></div></div>
<p>当前目录下多了一个.git的目录,是git用来跟踪管理版本库的。</p>
<p><a href="https://www.cnblogs.com/ini_always/archive/2011/12/24/2300601.html">Windows的BOM Byte order mark的问题</a></p>
<h2 id="把一个文件放入git仓库">把一个文件放入git仓库</h2>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git add readme.txt
</code></pre></div></div>
<p>把文件添加到仓库</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git commit -m "here is where you write the message"
</code></pre></div></div>
<p>把文件提交到仓库</p>
<p>##</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git status
</code></pre></div></div>
<p>查看仓库当前状态,修改,准备提交的情况</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git diff
</code></pre></div></div>
<p>查看修改的difference</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git add
</code></pre></div></div>
<p>提交修改</p>
<h2 id="版本回退">版本回退</h2>
<p>查看提交记录</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git log
</code></pre></div></div>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git log --pretty=oneline
</code></pre></div></div>
<p>git中的版本表示: HEAD表示当前版本,HEAD^是上一个版本,HEAD^^是上上一个版本,往上100个版本是HEAD~100。</p>
<p>版本回退的方法:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git reset --hard HEAD^
</code></pre></div></div>
<p>版本回退之后还想回退到之前的HEAD的方法,这里面版本号不用写全</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git reset --hard (commit id of HEAD)
</code></pre></div></div>
<p>在找不到commit id的时候,<code class="language-plaintext highlighter-rouge">git reflog</code>记录每一次命令</p>
<h2 id="撤销修改">撤销修改</h2>
<p>丢弃工作区的修改,把readme.txt在工作区的修改全部撤销:</p>
<ul>
<li>
<p>readme.txt在修改之后还没有被放到暂存区,撤销修改回到和版本库一模一样的状态。</p>
</li>
<li>
<p>readme.txt已经添加到暂存区,又作了修改,撤销修改就回到添加到暂存区之后的状态。</p>
</li>
</ul>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git checkout --readme.txt
</code></pre></div></div>
<p>如果已经<code class="language-plaintext highlighter-rouge">git add</code>到暂存区,撤销暂存区的修改</p>
<p><code class="language-plaintext highlighter-rouge">git reset HEAD readme.txt</code></p>
<p>总结:</p>
<p>场景1:当你改乱了工作区某个文件的内容,想直接丢弃工作区的修改时,用命令git checkout – file。</p>
<p>场景2:当你不但改乱了工作区某个文件的内容,还添加到了暂存区时,想丢弃修改,分两步,第一步用命令git reset HEAD <file>,就回到了场景1,第二步按场景1操作。</file></p>
<p>场景3:已经提交了不合适的修改到版本库时,想要撤销本次提交,参考版本回退一节,不过前提是没有推送到远程库。</p>
<h2 id="文件删除">文件删除</h2>
<p>在文件管理器中删除
<code class="language-plaintext highlighter-rouge">rm test.txt</code></p>
<p>删除错误时,从版本库恢复到最新版本</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git checkout -- test.txt
</code></pre></div></div>
<h2 id="推送到远程库">推送到远程库</h2>
<p>在github上面新建一个仓库,并且将本地仓库与github上的仓库进行关联。</p>
<p><code class="language-plaintext highlighter-rouge">git remote add origin git@github.com:jiru/learngit.git</code></p>
<p>查看本地添加了哪些远程地址</p>
<p><code class="language-plaintext highlighter-rouge">git remote -v</code></p>
<p>删除本地指定的远程地址</p>
<p><code class="language-plaintext highlighter-rouge">git remote remove origin</code></p>
<p>其中远程库的名字是<code class="language-plaintext highlighter-rouge">origin</code>,这是git默认的叫法。</p>
<p><code class="language-plaintext highlighter-rouge">git push -u origin master</code></p>
<h2 id="从远程库克隆">从远程库克隆</h2>
<p>github给出的地址不止一个,默认的git://使用ssh,也可以使用https协议。ssh协议更快。</p>
<p><code class="language-plaintext highlighter-rouge">git@github.com:michaelliao/gitskills.git</code></p>
<p><code class="language-plaintext highlighter-rouge">https://github.com/michaelliao/gitskills.git</code></p>
<h2 id="分支">分支</h2>
<p>创建且切换
<code class="language-plaintext highlighter-rouge">git checkout -b dev</code></p>
<p>创建+切换</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git branch dev
git checkout dev
</code></pre></div></div>
<p>查看当前分支</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git branch
</code></pre></div></div>
<p>切换回到master分支</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git checkout master
</code></pre></div></div>
<p>将dev分支上的工作成果合并到master上</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git merge dev
</code></pre></div></div>
<p>删除分支</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git branch -d dev
</code></pre></div></div>
<p>更为科学的切换分支</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git switch -c dev
</code></pre></div></div>
<p><code class="language-plaintext highlighter-rouge">git log --graph</code> 看分支合并图</p>
<h3 id="分支的普通模式合并">分支的普通模式合并</h3>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git switch -c dev
git add readme.txt
</code></pre></div></div>
<h3 id="存储工作区内容">存储工作区内容</h3>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git stash
Saved working directory and index state WIP on dev: f52c633 add merge
</code></pre></div></div>
<p>查看内容</p>
<p><code class="language-plaintext highlighter-rouge">git stash list</code></p>
<p>恢复stash的内容</p>
<p><code class="language-plaintext highlighter-rouge">git stash apply</code> 恢复后stash的内容并不删除</p>
<p><code class="language-plaintext highlighter-rouge">git stash pop</code> 恢复的同时删除stash的内容</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git cherry-pick
</code></pre></div></div>
<p>复制一个特定的提交到当前分支</p>
<h3 id="标签">标签</h3>
<p>切换到需要打标签的分支</p>
<p><code class="language-plaintext highlighter-rouge">git checkout master</code></p>
<p>打标签</p>
<p><code class="language-plaintext highlighter-rouge">git tag v1.0</code></p>
<p>对 commit id 打标签</p>
<p><code class="language-plaintext highlighter-rouge">git log --pretty=oneline --abbrev-commit</code></p>
<p><code class="language-plaintext highlighter-rouge">git tag v0.9 f52c633</code></p>
<h2 id="qa">Q&A</h2>
<p>为什么github上面新建的仓库分支变成了main。</p>
<p><a href="https://zhuanlan.zhihu.com/p/339370999">原因以及处理方式</a>。</p>
<p>当然,也可以把main删掉直接用master,main看起来不太得劲。</p>JRRrubujubi@gmail.comGit学习笔记 跟廖雪峰的教程学的,在这里记点自己看也没啥用别人看更没用的笔记 账号设置 在安装完git之后,输入 git config --global user.name "Your Name" git config --global user.email "email@example.com" 创建版本库 创建一个空目录 mkdir learngit cd learngit pwd (PWD) 显示当前目录 把目录变成git可以管理的仓库 git init 当前目录下多了一个.git的目录,是git用来跟踪管理版本库的。 Windows的BOM Byte order mark的问题 把一个文件放入git仓库 git add readme.txt 把文件添加到仓库 git commit -m "here is where you write the message" 把文件提交到仓库 ## git status 查看仓库当前状态,修改,准备提交的情况 git diff 查看修改的difference git add 提交修改 版本回退 查看提交记录 git log git log --pretty=oneline git中的版本表示: HEAD表示当前版本,HEAD^是上一个版本,HEAD^^是上上一个版本,往上100个版本是HEAD~100。 版本回退的方法: git reset --hard HEAD^ 版本回退之后还想回退到之前的HEAD的方法,这里面版本号不用写全 git reset --hard (commit id of HEAD) 在找不到commit id的时候,git reflog记录每一次命令 撤销修改 丢弃工作区的修改,把readme.txt在工作区的修改全部撤销: readme.txt在修改之后还没有被放到暂存区,撤销修改回到和版本库一模一样的状态。 readme.txt已经添加到暂存区,又作了修改,撤销修改就回到添加到暂存区之后的状态。 git checkout --readme.txt 如果已经git add到暂存区,撤销暂存区的修改 git reset HEAD readme.txt 总结: 场景1:当你改乱了工作区某个文件的内容,想直接丢弃工作区的修改时,用命令git checkout – file。 场景2:当你不但改乱了工作区某个文件的内容,还添加到了暂存区时,想丢弃修改,分两步,第一步用命令git reset HEAD ,就回到了场景1,第二步按场景1操作。 场景3:已经提交了不合适的修改到版本库时,想要撤销本次提交,参考版本回退一节,不过前提是没有推送到远程库。 文件删除 在文件管理器中删除 rm test.txt 删除错误时,从版本库恢复到最新版本 git checkout -- test.txt 推送到远程库 在github上面新建一个仓库,并且将本地仓库与github上的仓库进行关联。 git remote add origin git@github.com:jiru/learngit.git 查看本地添加了哪些远程地址 git remote -v 删除本地指定的远程地址 git remote remove origin 其中远程库的名字是origin,这是git默认的叫法。 git push -u origin master 从远程库克隆 github给出的地址不止一个,默认的git://使用ssh,也可以使用https协议。ssh协议更快。 git@github.com:michaelliao/gitskills.git https://github.com/michaelliao/gitskills.git 分支 创建且切换 git checkout -b dev 创建+切换 git branch dev git checkout dev 查看当前分支 git branch 切换回到master分支 git checkout master 将dev分支上的工作成果合并到master上 git merge dev 删除分支 git branch -d dev 更为科学的切换分支 git switch -c dev git log --graph 看分支合并图 分支的普通模式合并 git switch -c dev git add readme.txt 存储工作区内容 git stash Saved working directory and index state WIP on dev: f52c633 add merge 查看内容 git stash list 恢复stash的内容 git stash apply 恢复后stash的内容并不删除 git stash pop 恢复的同时删除stash的内容 git cherry-pick 复制一个特定的提交到当前分支 标签 切换到需要打标签的分支 git checkout master 打标签 git tag v1.0 对 commit id 打标签 git log --pretty=oneline --abbrev-commit git tag v0.9 f52c633 Q&A 为什么github上面新建的仓库分支变成了main。 原因以及处理方式。 当然,也可以把main删掉直接用master,main看起来不太得劲。Solidity Bytecode2021-08-10T00:00:00+00:002021-08-10T00:00:00+00:00https://kindhearted57.github.io/2021/08/10/solidity_bytecode<h1 id="solidity-bytecode">Solidity Bytecode</h1>
<h2 id="背景">背景</h2>
<p>今天在做Bytecode的CFG,对于以下的source code:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>pragma solidity 0.4.24;
contract SimpleDAO {
mapping (address => uint) public credit;
function donate(address to) payable public{
credit[to] += msg.value;
}
function withdraw(uint amount) public{
if (credit[msg.sender]>= amount) {
require(msg.sender.call.value(amount)());
credit[msg.sender]-=amount;
}
}
function queryCredit(address to) view public returns(uint){
return credit[to];
}
}
</code></pre></div></div>
<p>CFG出来的图十分奇怪,如下所示:</p>
<p><img src="https://note.youdao.com/yws/api/personal/file/WEBd21acfd141127f33e9d15f2d60d6b21b?method=download&shareKey=43a77ef460d0e700261ba1b5269cc5ab" alt="" /></p>
<p>一开始以为是这个合约的问题,结果后来一顿操作,主要是在<a href="ethervm.io">ethervm.io</a>上面看bytecode和decompilation的结果,在decompilation的结果很是奇怪,只有一个函数</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>contract Contract {
function main() {
memory[0x40:0x60] = 0x80;
var var0 = msg.value;
if (var0) { revert(memory[0x00:0x00]); }
memory[0x00:0x0320] = code[0x20:0x0340];
return memory[0x00:0x0320];
}
}
</code></pre></div></div>
<p>这个结果上面提示了一句话,让我茅塞顿开,应该是bytecode的类型不对。</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>This might be constructor bytecode - to get at the deployed contract, go back and remove the constructor prefix, usually up to the next 6060 or 6080.
</code></pre></div></div>
<p>于是我换成了runtime bytecode,这次出现的结果看起来还比较合理。</p>
<p><img src="https://note.youdao.com/yws/api/personal/file/WEB4773ed7b370acfac7a40ba7b7afa050c?method=download&shareKey=4b2c3ddcdedfef045996be8ce0c69d40" alt="" /></p>
<p>随后我很好奇为什么这个错误会导致这样的结果,因为看起来creation bytecode和runtime bytecode的不同之处似乎只有构造函数上的不同。于是我们来比较一下这两个bytecode的不同之处。</p>
<p>关于不同的bytecode之间的不同之处,在之前就曾经读过<a href="https://medium.com/authereum/bytecode-and-init-code-and-runtime-code-oh-my-7bcd89065904">这篇medium</a>,此处依然适用。</p>
<p><img src="https://note.youdao.com/yws/api/personal/file/WEBb2c906cf85b18204ffb9335874d00ff4?method=download&shareKey=6c0b373dfd2462116861b38dd5b6d7f1" alt="" /></p>
<p>在remix的compilation details中,bytecode表示creation bytecode,runtime bytecode是runtime bytecode。</p>
<p>这两类bytecode的关系是:creation bytecode generates runtime bytecode</p>
<p>下面贴一下两种bytecode:</p>
<p>creation bytecode:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>608060405234801561001057600080fd5b50610320806100206000396000f300608060405260043610610061576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168062362a95146100665780632e1a7d4d1461009c57806359f1286d146100c9578063d5d44d8014610120575b600080fd5b61009a600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610177565b005b3480156100a857600080fd5b506100c7600480360381019080803590602001909291905050506101c6565b005b3480156100d557600080fd5b5061010a600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610294565b6040518082815260200191505060405180910390f35b34801561012c57600080fd5b50610161600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506102dc565b6040518082815260200191505060405180910390f35b346000808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254019250508190555050565b806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101515610291573373ffffffffffffffffffffffffffffffffffffffff168160405160006040518083038185875af192505050151561024457600080fd5b806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055505b50565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600060205280600052604060002060009150905054815600a165627a7a7230582016b127a1d2c86cddf3ca28ad293153e4f03a44fcdc9378a3893b902afb848a2e0029
</code></pre></div></div>
<p>runtime bytecode</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>608060405260043610610061576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168062362a95146100665780632e1a7d4d1461009c57806359f1286d146100c9578063d5d44d8014610120575b600080fd5b61009a600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610177565b005b3480156100a857600080fd5b506100c7600480360381019080803590602001909291905050506101c6565b005b3480156100d557600080fd5b5061010a600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610294565b6040518082815260200191505060405180910390f35b34801561012c57600080fd5b50610161600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506102dc565b6040518082815260200191505060405180910390f35b346000808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254019250508190555050565b806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101515610291573373ffffffffffffffffffffffffffffffffffffffff168160405160006040518083038185875af192505050151561024457600080fd5b806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055505b50565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600060205280600052604060002060009150905054815600a165627a7a7230582016b127a1d2c86cddf3ca28ad293153e4f03a44fcdc9378a3893b902afb848a2e0029
</code></pre></div></div>JRRrubujubi@gmail.comSolidity Bytecode 背景 今天在做Bytecode的CFG,对于以下的source code: pragma solidity 0.4.24; contract SimpleDAO { mapping (address => uint) public credit; function donate(address to) payable public{ credit[to] += msg.value; } function withdraw(uint amount) public{ if (credit[msg.sender]>= amount) { require(msg.sender.call.value(amount)()); credit[msg.sender]-=amount; } } function queryCredit(address to) view public returns(uint){ return credit[to]; } } CFG出来的图十分奇怪,如下所示: 一开始以为是这个合约的问题,结果后来一顿操作,主要是在ethervm.io上面看bytecode和decompilation的结果,在decompilation的结果很是奇怪,只有一个函数 contract Contract { function main() { memory[0x40:0x60] = 0x80; var var0 = msg.value; if (var0) { revert(memory[0x00:0x00]); } memory[0x00:0x0320] = code[0x20:0x0340]; return memory[0x00:0x0320]; } } 这个结果上面提示了一句话,让我茅塞顿开,应该是bytecode的类型不对。 This might be constructor bytecode - to get at the deployed contract, go back and remove the constructor prefix, usually up to the next 6060 or 6080. 于是我换成了runtime bytecode,这次出现的结果看起来还比较合理。 随后我很好奇为什么这个错误会导致这样的结果,因为看起来creation bytecode和runtime bytecode的不同之处似乎只有构造函数上的不同。于是我们来比较一下这两个bytecode的不同之处。 关于不同的bytecode之间的不同之处,在之前就曾经读过这篇medium,此处依然适用。 在remix的compilation details中,bytecode表示creation bytecode,runtime bytecode是runtime bytecode。 这两类bytecode的关系是:creation bytecode generates runtime bytecode 下面贴一下两种bytecode: creation bytecode: 608060405234801561001057600080fd5b50610320806100206000396000f300608060405260043610610061576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168062362a95146100665780632e1a7d4d1461009c57806359f1286d146100c9578063d5d44d8014610120575b600080fd5b61009a600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610177565b005b3480156100a857600080fd5b506100c7600480360381019080803590602001909291905050506101c6565b005b3480156100d557600080fd5b5061010a600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610294565b6040518082815260200191505060405180910390f35b34801561012c57600080fd5b50610161600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506102dc565b6040518082815260200191505060405180910390f35b346000808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254019250508190555050565b806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101515610291573373ffffffffffffffffffffffffffffffffffffffff168160405160006040518083038185875af192505050151561024457600080fd5b806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055505b50565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600060205280600052604060002060009150905054815600a165627a7a7230582016b127a1d2c86cddf3ca28ad293153e4f03a44fcdc9378a3893b902afb848a2e0029 runtime bytecode 608060405260043610610061576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168062362a95146100665780632e1a7d4d1461009c57806359f1286d146100c9578063d5d44d8014610120575b600080fd5b61009a600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610177565b005b3480156100a857600080fd5b506100c7600480360381019080803590602001909291905050506101c6565b005b3480156100d557600080fd5b5061010a600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610294565b6040518082815260200191505060405180910390f35b34801561012c57600080fd5b50610161600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506102dc565b6040518082815260200191505060405180910390f35b346000808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254019250508190555050565b806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101515610291573373ffffffffffffffffffffffffffffffffffffffff168160405160006040518083038185875af192505050151561024457600080fd5b806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055505b50565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600060205280600052604060002060009150905054815600a165627a7a7230582016b127a1d2c86cddf3ca28ad293153e4f03a44fcdc9378a3893b902afb848a2e0029Writing 注意事项2021-06-19T00:00:00+00:002021-06-19T00:00:00+00:00https://kindhearted57.github.io/2021/06/19/%E5%BC%95%E7%94%A8%E7%9A%84%E4%BD%BF%E7%94%A8<h2 id="引用的使用">引用的使用</h2>
<p>引用前加空格,写在标点前,后面贴着标点。如果是没有标点的情况下,后面也要空格</p>
<p>Have a nice day [1].</p>
<p>Have a nice [1] day.</p>
<h2 id="括号的使用">括号的使用</h2>
<p>跟引用几乎相同</p>
<p>Have a nice day (by looking at the stars) everyday.</p>
<p>Have a nice day (everyday).</p>JRRrubujubi@gmail.com引用的使用 引用前加空格,写在标点前,后面贴着标点。如果是没有标点的情况下,后面也要空格 Have a nice day [1]. Have a nice [1] day. 括号的使用 跟引用几乎相同 Have a nice day (by looking at the stars) everyday. Have a nice day (everyday).一件没有什么意义但是有点意思的Python小事2021-06-01T00:00:00+00:002021-06-01T00:00:00+00:00https://kindhearted57.github.io/2021/06/01/pythonbalabala<h1 id="一件没有什么意义但是有点意思的python小事">一件没有什么意义但是有点意思的Python小事</h1>
<p>六一快乐。</p>
<p>一个list,想边遍历边删除,类似于这样</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>list1 = [1,2,3,4,5,6,7,8]
for i in range(len(list1)):
del list1[i]
print(i)
</code></pre></div></div>
<p>惊讶的发现输出的结果是</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>0
1
2
3
</code></pre></div></div>
<p>这时候list的内容是</p>
<p><code class="language-plaintext highlighter-rouge">[2,4,6,8]</code></p>
<p><code class="language-plaintext highlighter-rouge">IndexError: list assignment index out of range</code></p>
<p>hhhhh读到这里就浪费了1分钟的阅读时间和半分钟的脑力思考。</p>
<p>六一快乐。</p>JRRrubujubi@gmail.com一件没有什么意义但是有点意思的Python小事 六一快乐。 一个list,想边遍历边删除,类似于这样 list1 = [1,2,3,4,5,6,7,8] for i in range(len(list1)): del list1[i] print(i) 惊讶的发现输出的结果是 0 1 2 3 这时候list的内容是 [2,4,6,8] IndexError: list assignment index out of range hhhhh读到这里就浪费了1分钟的阅读时间和半分钟的脑力思考。 六一快乐。拼写符号的一些总结2021-06-01T00:00:00+00:002021-06-01T00:00:00+00:00https://kindhearted57.github.io/2021/06/01/%E6%B3%95%E8%AF%AD%E6%8B%BC%E5%86%99%E7%AC%A6%E5%8F%B7<h2 id="法语拼写符号的一些总结">法语拼写符号的一些总结</h2>
<p>书上的说法稍微有一些死板,不便于理解,在遇到实际情况的时候刨根问底又无知识的人常常陷入困惑。特此总结一些我东拼西凑的来的知识。基本内容是从《简明法语》copy过来的,加了一点扩展。</p>
<h3 id="闭音符和开音符">闭音符和开音符</h3>
<p>(现在还没有搞清楚为什么accent grave称为开音符,accent aigu称为闭音符,但是有将accent grave翻译为尖音符,l’accent aigu翻译成钝音符)
闭音符放在字母e上方,比如état。</p>
<p>开音符放在字母a,e,u上方,比如là,dès,où</p>
<p>在这里,对于字母e来说,开闭音符可以改变发音,只要是闭音符é就发音/e/,只要是开音符就发音/ɛ/。</p>
<p>对于a,u两个字母而言,没有读音的改变,只是用来区别同音的不同义之词。如:
a与à,ou与où</p>
<p>在我自己的学习过程中,对于一些éè的读音并没有很好的区分,比如état的发音我就近乎于/ɛ/而非/e/。是因为这一点造成了我许多的困惑。</p>
<h3 id="长音符">长音符</h3>
<p>在这里面参考了<a href="https://www.zhihu.com/question/355396984/answer/902397568">这篇</a>知乎回答。十分受教。长音符并不是用来发长音用的。总结如下:</p>
<p>法语中大部分带长音符的字母在历史上是发长音的,但是在现在巴黎法语中元音的长短对立已经消失。长元音的出现是其他音素脱落的代偿机制,如Fête词源是古法语festa,Gâteau 词源是古法语gastel,元音后,辅音前的s脱落导致元音变长。</p>
<p>以下总结长音符的几点用处</p>
<p>1)用于ê,表示读/ɛ/,比如tête,fête。
2)用于ô,表示读/o/,如côte,pôle。
3)用于,表示读/a/,比如âme,mâle。
4) 用于î,û使词义不受影响。île,dû</p>
<h3 id="软音符">软音符</h3>
<p>我的困惑之处,commencer,commençais两个单词中c和ç的读音明明相同,软音符的作用在哪里。</p>
<p>c在a,o,u和辅音字母前和词尾,发比较硬的软腭音/k/,在e,i,y之前读音会软化,但有的时候c在a,o,u前发软音/s/,这个时候需要加软音符。这样就解决了前面的问题。</p>
<p>除此之外,当然还有其他的拼写符号,等我学好了再回来写。</p>JRRrubujubi@gmail.com法语拼写符号的一些总结 书上的说法稍微有一些死板,不便于理解,在遇到实际情况的时候刨根问底又无知识的人常常陷入困惑。特此总结一些我东拼西凑的来的知识。基本内容是从《简明法语》copy过来的,加了一点扩展。 闭音符和开音符 (现在还没有搞清楚为什么accent grave称为开音符,accent aigu称为闭音符,但是有将accent grave翻译为尖音符,l’accent aigu翻译成钝音符) 闭音符放在字母e上方,比如état。 开音符放在字母a,e,u上方,比如là,dès,où 在这里,对于字母e来说,开闭音符可以改变发音,只要是闭音符é就发音/e/,只要是开音符就发音/ɛ/。 对于a,u两个字母而言,没有读音的改变,只是用来区别同音的不同义之词。如: a与à,ou与où 在我自己的学习过程中,对于一些éè的读音并没有很好的区分,比如état的发音我就近乎于/ɛ/而非/e/。是因为这一点造成了我许多的困惑。 长音符 在这里面参考了这篇知乎回答。十分受教。长音符并不是用来发长音用的。总结如下: 法语中大部分带长音符的字母在历史上是发长音的,但是在现在巴黎法语中元音的长短对立已经消失。长元音的出现是其他音素脱落的代偿机制,如Fête词源是古法语festa,Gâteau 词源是古法语gastel,元音后,辅音前的s脱落导致元音变长。 以下总结长音符的几点用处 1)用于ê,表示读/ɛ/,比如tête,fête。 2)用于ô,表示读/o/,如côte,pôle。 3)用于,表示读/a/,比如âme,mâle。 4) 用于î,û使词义不受影响。île,dû 软音符 我的困惑之处,commencer,commençais两个单词中c和ç的读音明明相同,软音符的作用在哪里。 c在a,o,u和辅音字母前和词尾,发比较硬的软腭音/k/,在e,i,y之前读音会软化,但有的时候c在a,o,u前发软音/s/,这个时候需要加软音符。这样就解决了前面的问题。 除此之外,当然还有其他的拼写符号,等我学好了再回来写。