物理の駅 Physics station by 現役研究者

テクノロジーは共有されてこそ栄える

Surface book 2についてくる Office Home & Business 2016は、Office 365に契約している場合ゴミになるのか?

ゴミです。

本製品は、本製品が付属していたパソコンでのみ使用できます。本製品のみをネットオークションなどで転売したり、他のパソコンで使用することはライセンス契約違反です。

って書いてあるし。

せっかくOffice 365でMicrosoftに貢ごうと思っても、目の前に未使用の Office Home & Business 2016 があるとなんか躊躇するよね、何なんだろうこの商法は。大嫌い。

C# WPF で BitmapImage (BitmapSource) のピクセルにアクセスし書き換える方法

BitmapImage (BitmapSource) のピクセルにアクセスし書き換える方法

例として、コントラストを変える処理を紹介する。

BitmapSource ApplyContrast(BitmapSource image, double contrast)
{
    if (contrast == 0) return image;
    var bitmap = new FormatConvertedBitmap(image, PixelFormats.Gray8, null, 0);
    int width = bitmap.PixelWidth;
    int height = bitmap.PixelHeight;
    byte[] pixcels = new byte[width * height];
    int stride = (width * bitmap.Format.BitsPerPixel + 7) / 8;
    bitmap.CopyPixels(pixcels, stride, 0);
    var offset = 256 * contrast;
    for (int x = 0; x < pixcels.Length; x++)
    {
        pixcels[x] = (byte)Math.Min(Math.Max(pixcels[x] * (1 + contrast) - offset, 0), 255);
    }
    return BitmapSource.Create(width, height, 96, 96, PixelFormats.Gray8, null, pixcels, stride);
}

そんなに早くないから大量の処理には向かないよ

Portable版 Visual Studio Code (VSCode)における Open with Codeの追加方法 (Windows)

Portable版 VS CodeC:\Users\Masahiro\OneDrive\Software\VSCode\Code.exe に展開したとする。 このままでは右クリックしたときの便利な設定を使えないので、手動でレジストリに追加する。

ファイルを右クリックしたときに有効になる設定

  • HKEY_CLASSES_ROOT*\shell\Open with Code
    既定に Edit with Code
    Icon 文字列に C:\Users\Masahiro\OneDrive\Software\VSCode\Code.exe,0
  • HKEY_CLASSES_ROOT*\shell\Open with Code\command 既定に "C:\Users\Masahiro\OneDrive\Software\VSCode\Code.exe" "%1"
    または、C:\Users\Masahiro\OneDrive\Software\VSCode\Code.exe "%W" "%1"

フォルダを右クリックしたときに有効になる設定

  • HKEY_CLASSES_ROOT\Directory\shell\VSCode
    既定に Open with Code
    Icon文字列に C:\Users\Masahiro\OneDrive\Software\VSCode\Code.exe,0
  • HKEY_CLASSES_ROOT\Directory\shell\VSCode\command
    既定に "C:\Users\Masahiro\OneDrive\Software\VSCode\Code.exe" "%1"

フォルダ内の空白部分を右クリックしたときに有効になる設定

  • HKEY_CLASSES_ROOT\Directory\Background\shell\VSCode
    既定に Open with Code
    Icon文字列に C:\Users\Masahiro\OneDrive\Software\VSCode\Code.exe,0
  • HKEY_CLASSES_ROOT\Directory\Background\shell\VSCode\command
    既定に "C:\Users\Masahiro\OneDrive\Software\VSCode\Code.exe" "%V"

%1 は1個目の引数、%V はそのファイルのフルパス、%W は親フォルダのフルパス が帰ってくるらしい。 qiita.com

ファイル単体を開きたい場合の引数は %1 、ファイルをフォルダ内で開きたい場合の引数は "%W" "%1" とするとよいだろう。

Anaconda updateでのエラー

conda update -all

で最後に

Preparing transaction: done
Verifying transaction: done
Executing transaction: | DEBUG menuinst_win32:__init__(196): Menu: name: 'Anaconda${PY_VER} ${PLATFORM}', prefix: 'C:\Users\%username%\Anaconda3', env_name: 'None', mode: 'user', used_mode: 'user'
DEBUG menuinst_win32:create(320): Shortcut cmd is C:\Users\%username%\Anaconda3\python.exe, args are ['C:\\Users\\%username%\\Anaconda3\\cwp.py', 'C:\\Users\\%username%\\Anaconda3', 'C:\\Users\\%username%\\Anaconda3\\python.exe', 'C:\\Users\\%username%\\Anaconda3\\Scripts\\jupyter-notebook-script.py', '%USERPROFILE%']
/ DEBUG menuinst_win32:__init__(196): Menu: name: 'Anaconda${PY_VER} ${PLATFORM}', prefix: 'C:\Users\%username%\Anaconda3', env_name: 'None', mode: 'user', used_mode: 'user'
DEBUG menuinst_win32:create(320): Shortcut cmd is C:\Users\%username%\Anaconda3\python.exe, args are ['C:\\Users\\%username%\\Anaconda3\\cwp.py', 'C:\\Users\\%username%\\Anaconda3', 'C:\\Users\\%username%\\Anaconda3\\python.exe', 'C:\\Users\\%username%\\Anaconda3\\Scripts\\jupyter-notebook-script.py', '%USERPROFILE%']
done

というエラーが出るのはなぜだろう

Slackのあるチャンネルの投稿を全て消すpythonコード

import time
from slackclient import SlackClient
slack_client = SlackClient('****-************-************-************-********************************')
target_channel ="channel"

def list_channels():
    channels_call = slack_client.api_call("channels.list")
    if channels_call.get('ok'):
        return channels_call['channels']
    return None

def channel_info(channel_id):
    channel_info = slack_client.api_call("channels.info", channel=channel_id)
    if channel_info:
        return channel_info['channel']
    return None

if __name__ == '__main__':
    channels = list_channels()
    if channels:
        for channel in channels:
            print(channel['name'])
            if channel['name'] != target_channel:
                continue            
            while True:
                detailed_info = channel_info(channel['id'])
                if not detailed_info['latest']:
                    break                
                message_ts = detailed_info['latest']['ts']
                slack_client.api_call("chat.delete", channel=channel['id'], ts=message_ts)
                time.sleep(1)
    else:
        print("Unable to authenticate.")

削除は出来るが、Total messagesの数は減らない。