2020年5月22日 星期五

陽明大學米卡茲早餐店

炸雞塊特別好吃
店員女兒在椅子上睡得很香很可愛

2020年5月19日 星期二

ssh免密碼登入

ssh免密碼登入

SSH免密碼登入設定小細節

關於免密碼登入這件事網路上很多教學了,但有時照著做,伺服器仍會跟你要密碼,這是因為有些權限沒有設定好的關係。

根據sshd的man page,這裡有提到一些重點:

 ~/.ssh/
     This directory is the default location for	all user-specific con-
     figuration	and authentication information.	 There is no general
     requirement to keep the entire contents of	this directory secret,
     but the recommended permissions are read/write/execute for	the
     user, and not accessible by others.

 ~/.ssh/authorized_keys
     Lists the public keys (DSA, ECDSA,	Ed25519, RSA) that can be used
     for logging in as this user.  The format of this file is de-
     scribed above.  The content of the	file is	not highly sensitive,
     but the recommended permissions are read/write for	the user, and
     not accessible by others.

     If	this file, the _~/.ssh_ directory, or the	user's home directory
     are writable by other users, then the file	could be modified or
     replaced by unauthorized users.  In this case, **sshd** will not al-
     low it to be used unless the **StrictModes** option has been set to
     "no".

也就是說,ssh相關的目錄要做好以下設定才行:

$HOME/.ssh/ 權限要設定成700
$HOME/.ssh/authorized_keys權限設定成600
$HOME 預設的設定通常正確,但要留意不能讓其他user能寫

如果違背以上限制,還是會被要密碼的~

2020年3月11日 星期三

python tricks

python tricks

Python ticks quick reference

pdb/ipdb

https://docs.python.org/3/library/pdb.html
https://github.com/gotcha/ipdb
pdb

import pdb; pdb.set_trace()

ipdb

import ipdb
ipdb.set_trace()

list comprehension

>> [i for i in range(10) if i != 5]

output

[0, 1, 2, 3, 4, 6, 7, 8, 9]

列出object properties

>> vars(<object>)

f-string

PEP 498

>> a = 1234
>> print(f"a = {a}")
a = 1234

yield - send

asyncio

PEP 492
https://docs.python.org/3/library/asyncio-task.html#coroutines
simple example

async def main():
    task1 = asyncio.create_task(
        say_after(1, 'hello'))

    task2 = asyncio.create_task(
        say_after(2, 'world'))

    print(f"started at {time.strftime('%X')}")

    # Wait until both tasks are completed (should take
    # around 2 seconds.)
    await task1
    await task2

    print(f"finished at {time.strftime('%X')}")

Running Tasks Concurrently

import asyncio

async def factorial(name, number):
    f = 1
    for i in range(2, number + 1):
        print(f"Task {name}: Compute factorial({i})...")
        await asyncio.sleep(1)
        f *= i
    print(f"Task {name}: factorial({number}) = {f}")

async def main():
    # Schedule three calls *concurrently*:
    await asyncio.gather(
        factorial("A", 2),
        factorial("B", 3),
        factorial("C", 4),
    )

asyncio.run(main())

# Expected output:
#
#     Task A: Compute factorial(2)...
#     Task B: Compute factorial(2)...
#     Task C: Compute factorial(2)...
#     Task A: factorial(2) = 2
#     Task B: Compute factorial(3)...
#     Task C: Compute factorial(3)...
#     Task B: factorial(3) = 6
#     Task C: Compute factorial(4)...
#     Task C: factorial(4) = 24

multiprocessing

multithreading

concurrent

Encoding declarations

https://docs.python.org/3.6/reference/lexical_analysis.html#encoding-declarations
Put the follow comment in the first or second line of the Python script:
-*- coding: <encoding-name> -*-

取得環境變數

import os
os.environ.get('X509_USER_PROXY')

min

這是特別的用法

>>> a = [{"test":{"val1":1}, "name":"A"}, {"test":{"val1":2}, "name": "B"}]
>>> min(a, key=lambda k: k["test"]["val1"])
{'test': {'val1': 1}, 'name': 'A'}

zip

>>> list(zip([1, 2, 3], [4, 5, 6]))
[(1, 4), (2, 5), (3, 6)]

enumerate

>>> list(enumerate(a))
[(0, 'a'), (1, 'b'), (2, 'c')]

getattr

>>>class  A(object):
> ... bar = 1 
> ... 
>>> a = A() 
>>> getattr(a, 'bar')
1

用在自動取得attr時可能會很方便

2020年1月10日 星期五

cvmfs note

cvmfs TS

@ WN
systemctl restart autofs
cvmfs_config wipecache (or remove /var/cache/cvmfs2/shared)
cvmfs_config probe

@ cvmfs server
cvmfs_server resign -d 120

  • /tmp/cvmfs.log
  • /etc/cvmfs/default.local

2020年1月2日 星期四

javascript

javascript

javascript notes

var that = this

如果在object中執行ajax,想在.done(或success)中設定好Object的property,那可能會需要使用此技巧。

例:

class testObj{
    constructor(){
        var that = this
        $.ajax({
    	    url: "someurl...",
	    type: "GET",
	    contentType: "json"
        }).done(function(data){
	    console.log(data)
	    that.hostname = data.info.hostname
        })
    }
};
a = new testObj()
console.log(a.hostname)

看起來感覺很糟,除此之外尚有另外的解法:


class testObj{
    constructor(){
        $.ajax({
    	    url: "someurl...",
	    type: "GET",
	    contentType: "json",
	    context: this
        }).done(function(data){
	    console.log(data)
	    this.hostname = data.info.hostname
        })
    }
};
a = new testObj()
console.log(a.hostname)

嗯…還是醜醜的
javascript要寫得好看不容易呀

解構子

可以拿來組合兩個array

example

a = [1, 2, 3]
b = [4, 5, 6]
console.log([...a, ...b])
//except: [1, 2, 3, 4, 5, 6]