表单: Language Notes
用户: dreamable
创建日期: 2021-08-21 08:36:14 UTC
更新日期: 2021-08-21 08:46:23 UTC
引用:(Table ID 41, Record ID 1)

title :
Functors
note :
标签:
表单: LinuxNotes
用户: dreamable
创建日期: 2021-09-08 13:25:30 UTC
更新日期: 2021-09-08 13:25:30 UTC
引用:(Table ID 28, Record ID 8)

标题 :
AWS Elastic IP
笔记 :
  • 保留IP,最多5个
  • 这样EC2重启后IP地址不再变化
  • 有些区域的可以设定reverse DNS,对发送email有帮助
标签:
表单: LinuxNotes
用户: dreamable
创建日期: 2021-08-23 00:18:58 UTC
更新日期: 2021-08-23 00:19:06 UTC
引用:(Table ID 28, Record ID 7)

标题 :
gio mount smb
笔记 :
gio mount smb://<servername>/<sharename>
# enter password
# once the mount is created it will create a temporary path located at  the following path, for example:
# /run/user/1000/gvfs/smb-share\:server\=host.domain.com\,share\=files/
ln -s /run/user/<userid>/gvfs/smb-share\:server\=<servername>\,share\=<sharename>/ ~/<mountpoint>
标签:
表单: LinuxNotes
用户: dreamable
创建日期: 2021-08-22 22:48:47 UTC
更新日期: 2021-08-22 22:59:21 UTC
引用:(Table ID 28, Record ID 6)

标题 :
Ubuntu disable sleep
笔记 :
 sudo -H gedit /etc/systemd/logind.conf
 HandleLidSwitch=ignore
 sudo service systemd-logind restart
 # Still sleep after idle
 sudoedit /etc/UPower/UPower.conf
 Change IgnoreLid to IgnoreLid=true
 service upower restart
# also in /etc/systemd/logind.conf
HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignore
HandleHibernateKey=ignore
HandleSuspendKey=ignore
IdleAction=ignore
IdleActionSec=0
 # Still sleep after idle
sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
标签:
表单: LinuxNotes
用户: dreamable
创建日期: 2021-08-22 22:00:21 UTC
更新日期: 2021-08-22 22:00:21 UTC
引用:(Table ID 28, Record ID 5)

标题 :
内网穿透
笔记 :

路由器NAT映射端口,尝试并成功

  1. ssh
  2. rdesktop
  3. smb
标签:
表单: LinuxNotes
用户: dreamable
创建日期: 2021-08-22 21:59:39 UTC
更新日期: 2021-08-22 21:59:39 UTC
引用:(Table ID 28, Record ID 4)

标题 :
Basic HTTP File Server
笔记 :

python3 -m http.server

标签:
表单: WebNotes
用户: dreamable
创建日期: 2021-05-02 22:03:59 UTC
更新日期: 2021-05-02 22:06:07 UTC
引用:(Table ID 25, Record ID 6)

标题 :
bootstrap making dropdown scrollable
笔记 :

guide

  • inline style
style="overflow-y:auto; max-height:80vh"
  • CSS for all
.dropdown-menu {
 overflow-y:auto; 
 max-height:80vh
}
标签:
表单: WebNotes
用户: dreamable
创建日期: 2021-03-05 11:45:34 UTC
更新日期: 2021-03-05 11:45:34 UTC
引用:(Table ID 25, Record ID 5)

标题 :
JS import vs require
笔记 :

guide

  1. require is for CommonJS (node.js way to load modules)
  2. import is for ES6. But not supported via CommonJS by browsers
标签:
表单: WebNotes
用户: dreamable
创建日期: 2021-03-02 11:56:58 UTC
更新日期: 2021-03-02 11:56:58 UTC
引用:(Table ID 25, Record ID 4)

标题 :
Clear form fields with jQuery
笔记 :

guide

$('yourdiv').find('form')[0].reset();
标签:
表单: WebNotes
用户: dreamable
创建日期: 2021-02-25 07:44:00 UTC
更新日期: 2021-02-25 07:44:14 UTC
引用:(Table ID 25, Record ID 3)

标题 :
Find element that has either class 1 or class 2
笔记 :

$(".a, .b")
this will match all elements with class a OR class b

标签:
表单: WebNotes
用户: dreamable
创建日期: 2021-01-29 12:16:11 UTC
更新日期: 2021-01-29 12:16:11 UTC
引用:(Table ID 25, Record ID 2)

标题 :
onblur infinite loop issue in Safari
笔记 :

问题: onblur触发alter,然后在safari下死循环

根源:Root Cause: Each time clicking on 'Ok' button of the alert, onblur happens and we are trapped in an infinite loop.

解决

        alert('wrong !!!');
        setTimeout(function(){
            field.focus();
        },0);

注意必须使用setTimeout,直接focus不能work。设置field.value为空不是必须的。

遗留问题:如果用tab转到下一个form field,也有onblur事件,还是死循环。

解决方法:如果value是空,则忽略,不触发alter

更多讨论:1, 2

标签:
表单: PythonNotes
用户: dreamable
创建日期: 2021-03-16 01:10:44 UTC
更新日期: 2021-03-16 01:11:23 UTC
引用:(Table ID 14, Record ID 2)

标题 :
Python3 + MongoDB bug
笔记 :

遇到一个奇怪的问题,在Python3中,调用MongoDB。Sorting会影响结果。

基本代码

   order = pymongo.DESCENDING if self.descending else pymongo.ASCENDING
   items = self.tb.find(cond).sort(self.uid,order).limit(self.limit)
   logging.info(f"There are {items.count()} items")
   for idx,t in enumerate(items):
      logging.info(f"Working on {idx}-th item: {t[self.uid]}")

问题:

  1. 当order为descending,limit> # of records, hang after 100 records
  2. 当order为ascending的时候,问题不存在
  3. 当limit <= # of records时候,问题不存在
  4. 只对一个collection有此问题,其它类似collection没有此问题
  5. 存在{uid: -1}的index,添加{uid:1}的index无帮助

找不到原因,可能是某个地方的bug。采用ascending order绕开了这个问题。

标签:
表单: PythonNotes
用户: dreamable
创建日期: 2020-11-23 23:50:21 UTC
更新日期: 2020-12-02 23:47:54 UTC
引用:(Table ID 14, Record ID 1)

标题 :
cython
笔记 :
  1. python vs cpython vs cython

    • python: 语言
    • cpython: Python的解释器,用C实现的,也有用Java实现的Jython
    • cython:优化器,将python编译为C语言,提高运行速度
      • superset language
      • python + C extension
  2. install (version 0.29.21)

    sudo pip install cython
    
  3. setup.py

    from setuptools import setup
    from Cython.Build import cythonize
    setup(
    name='Hello world app',
    ext_modules=cythonize(["hello.py","utils.py","config.py"],annotate=True),
    zip_safe=False,
    )
    
    python setup.py build_ext --inplace
    
    • build error
    • in ~/engine: ERROR: error: [Errno 2] No such file or directory: 'engine/hello.so'
    • in ~/engine/tmp: OK
    • in `~/engine2': OK
    • remove __init__.py solves the problem.
标签:
表单: RailsNotes
用户: dreamable
创建日期: 2021-08-25 06:22:13 UTC
更新日期: 2021-08-25 06:22:13 UTC
引用:(Table ID 3, Record ID 50)

标题 :
Rails Webpacker & stylesheets
笔记 :
  1. I have an issue that select2 css is not included in production, although OK in development.
  2. Further, I found all css included in app/javascripts/packs/application.js not working
  3. I do add stylesheets_pack_tag in views/layout/application.html, but no effect, no <link> generated. why? Seems to be a Rails6.1.3/webpacker5.0 bug
  4. In development, according to the extract_css=false setting in config/webpacker.yml, so all css are embed in the HTML. In production, the css is extracted, put in a separated file public/packs/css/applicationxxx.css. However, it's not included in html, so not work.
  5. One solution is to update extract_css=false for production as well, this leads to embed css in HTML, which works but is ugly.
  6. I workaround the problem by moving all css from packs to assets/stylesheets/application.scss
  7. To import css in node_modules, remember to use @import 'select2/dist/css/select2.min'; instead of @import 'select2/dist/css/select2.min.css';. The later cases works in development, but the file is empty in production. I guess because Rails production doesn't know the local directory of node_modules. The former case works, as the css is copied to application.css, instead of a separated file.
标签:
表单: RailsNotes
用户: dreamable
创建日期: 2021-08-24 23:43:20 UTC
更新日期: 2021-08-24 23:44:20 UTC
引用:(Table ID 3, Record ID 49)

标题 :
Rails 6.0 deploy problems.
笔记 :
  1. css file not found.
/* in application.scss */
@import "./github_markdown.css";
-> 
@import "github_markdown";
  1. Font awesome icons not found. solution
# in Gemfile
gem 'font_awesome5_rails'
# in application.scss
@import 'font_awesome5_webfont';
标签:
表单: RailsNotes
用户: dreamable
创建日期: 2021-08-24 22:03:47 UTC
更新日期: 2021-08-24 22:03:47 UTC
引用:(Table ID 3, Record ID 48)

标题 :
deploy error
笔记 :
/home/eda/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/net-ssh-6.1.0/lib/net/ssh/authentication/ed25519_loader.rb:21:in `raiseUnlessLoaded': OpenSSH keys only supported if ED25519 is available (NotImplementedError)
net-ssh requires the following gems for ed25519 support:
 * ed25519 (>= 1.2, < 2.0)
 * bcrypt_pbkdf (>= 1.0, < 2.0)
See https://github.com/net-ssh/net-ssh/issues/565 for more information
Gem::MissingSpecError : "Could not find 'ed25519' (~> 1.2) among 175 total gem(s)
Checked in 'GEM_PATH=/home/eda/.local/share/gem/ruby/3.0.0:/home/eda/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0' , execute `gem env` for more information"
ssh-add ~/.ssh/id_rsa.pub
# error
Could not open a connection to your authentication agent.
eval `ssh-agent -s`
ssh-add
标签:
表单: RailsNotes
用户: dreamable
创建日期: 2021-05-08 15:04:26 UTC
更新日期: 2021-05-08 15:11:38 UTC
引用:(Table ID 3, Record ID 47)

标题 :
Generate slug from name automatically
笔记 :
  1. parameterize

    • copy code from github
    • but I don't want to exclude Chinese chars, based on this, I added
    s = s.replace(/[^\x00-\x7F]/g, "")
    
  2. add a JS function

    • According to this The input event is HTML5, feels like onchange without the need to lose focus on the element. It's not supported by IE8 and below, which should use onpropertychange.
    • For non HTML5 solution, according to this, we need onkeydown oncut onpaste
      • onchange occurs only when you blur the textbox
      • onkeyup & onkeypress doesn't always occur on text change
      • onkeydown occurs on text change (but cannot track cut & paste with mouse click)
      • onpaste & oncut occurs with keypress and even with the mouse right click.
    require('./parameterize.js')
    $(document).on("turbolinks:load", function() {
      $('form').on('input', '.parameterize-to', function(event) {
        console.log("parameterize value updated")
        let tid = $(this).attr('dst-id');
        console.log("DEBUG:: The dst ID is: %s!",tid)
        let content= $(this).val().trim()
        console.log("DEBUG:: The form value is: %s!",content)
        let slug = parameterize(content)
        console.log("DEBUG:: Set value of %s to is: %s!",tid,content)
        $("#"+tid).val(slug);
      });
    });
    
  3. Apply it in views. Set class and ID properly. It works with input, cut & paste in Chrome

标签:
表单: RailsNotes
用户: dreamable
创建日期: 2021-05-02 23:57:46 UTC
更新日期: 2021-05-02 23:57:46 UTC
引用:(Table ID 3, Record ID 46)

标题 :
Rails i18n strings auto-lowercased?
笔记 :

source

There should be no modifications to the content you specify as part of the internationalization process. It sounds like something is calling humanize on the string before it is output. Some of the standard Rails form helper methods do this I believe. If you just output the translation using t('email') you should see 'E-Mail' correctly.

Update: From your comments it seems like it is a label that is causing the problem. If you explicitly specify the text for the label rather than relying on the default behaviour you will get the translation exactly as you specify. So,

<%= f.label(:email, t('email')) %>

should generate the correct label from the translations.

标签: