Share Code Quickly

What is Harigami?

Harigami is a simple source code sharing service. You can share source code by an URL which is issued after submission.
You can also run your source code online such as Python, Ruby, JavaScript and so on.
For free.Use for code review.
Preferences
anonymous No title
JavaScript
(async () => {
  const nodeUrl = "http://symbol-test.next-web-technology.com:3000";
  const nw = await NetworkScripts.getNetworkStructureFromNode(nodeUrl, NetworkType.TEST_NET);
  // Accountの作成
  const account1 = AccountScripts.createFromMnemonic(SAMPLE1.MNEMONIC, "password", nw);
  const account2 = AccountScripts.createFromMnemonic(SAMPLE2.MNEMONIC, "password", nw);
  console.log(account1.address);
  console.log(account2.address);
  // Account情報の取得
  const [account1Info] = await AccountScripts.getBalanceFromAddress(account1.address, nw);
  const [account2Info] = await AccountScripts.getBalanceFromAddress(account2.address, nw);
  console.log(JSON.stringify(account1Info));
  console.log(JSON.stringify(account2Info));
  // ACCOUNT1 -> 2への送金
  const mosaic = await MosaicScripts.getMosaicStructureFromMosaicId(account1Info.mosaicId, nw);
  const tx = await TransactionScripts.createTransaction(account2.address, [{ mosaic, amount: 1 }], "test", nw);
  console.log(tx.transactionInfo?.id);
  const result = await TransactionScripts.signTransaction(account1, tx, nw);
  console.log(result);
})();
anonymous No title
TypeScript
// 過去作成したニーモニックよりアカウントを復元し、保有モザイクを確認する
(async () => {
  const mnemonicWords = "xxxxxxxxxxxxxxxxxx";
  const xKey = ExtendedKey.createFromSeed(new MnemonicPassPhrase(mnemonicWords).toSeed("password").toString("hex"), Network.SYMBOL);
  const wallet = new Wallet(xKey);
  const privateKey = wallet.getChildAccountPrivateKey(Wallet.DEFAULT_WALLET_PATH);
  const symbolAccount = Account.createFromPrivateKey(privateKey, NetworkType.TEST_NET);

  const nodeUrl = "http://symbol-test.next-web-technology.com:3000";
  const address = Address.createFromRawAddress(symbolAccount.address.pretty());
  const accountRepo = new RepositoryFactoryHttp(nodeUrl).createAccountRepository();
  const accountInfo = await accountRepo.getAccountInfo(address).pipe(timeout(5000)).toPromise();

  for (const ownedMosaic of accountInfo.mosaics) {

    const mosaicId = new MosaicId(ownedMosaic.id.toHex());
    const repositry = new RepositoryFactoryHttp(nodeUrl);
    const mosaicHttp = repositry.createMosaicRepository();
    const info = await mosaicHttp.getMosaic(mosaicId).pipe(timeout(5000)).toPromise();
    console.log(info);
  }

})();
anonymous No title
TypeScript
// 新規アカウントを発行する
(async () => {
  const mnemonic = MnemonicPassPhrase.createRandom(); // hd-wallet向け
  const seed = mnemonic.toSeed("password").toString("hex"); // passphraseにて暗号化(root seed)
  const xkey = ExtendedKey.createFromSeed(seed, Network.SYMBOL);
  const wallet = new Wallet(xkey);
  const masterAccount = wallet.getAccountPrivateKey();
  const defaultAccount = wallet.getChildAccountPrivateKey(Wallet.DEFAULT_WALLET_PATH);
  console.log(mnemonic);
  // console.log(masterAccount);
  // console.log(defaultAccount);
})();
anonymous セミオートログイン Ver.2
VBA
Option Explicit

Sub リンク作成()
    
    Dim i As Long
    For i = 3 To Cells(Rows.Count, 2).End(xlUp).Row
        Hyperlinks.Add anchor:=Cells(i, 3), Address:="", SubAddress:="", TextToDisplay:="実行"
    Next
    
End Sub

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
    
    Dim ジャンル As String
    ジャンル = Target.Range.Offset(0, 1).Value
    
    Dim 最初のセル As Range
    Set 最初のセル = Target.Range.Offset(0, 2)
    
    Select Case ジャンル
        Case "フォルダ"
            Call フォルダ(最初のセル)
        Case "Zoom"
            Call Zoom(最初のセル)
    End Select
    
End Sub

Sub フォルダ(ByVal セル As Range)
    
    Rem コピー1
    セル.Copy
    AppActivate "*無題 - メモ帳"
    Call ySendKeys("^V")
    Call ySendKeys("{TAB}")
    
    Rem コピー2
    セル.Offset(0, 1).Copy
    Call ySendKeys("^V")
    Call ySendKeys(" ")
    Call ySendKeys("{TAB}")
    
    Application.CutCopyMode = False
    
End Sub

Sub Zoom(ByVal セル As Range)
    
    Rem コピー1
    セル.Copy
    AppActivate "Zoom"
    Call ySendKeys("^V")
    Call ySendKeys("{TAB}{TAB}{TAB}{TAB}")
    Call ySendKeys(" ")
    Call ySendKeys("{TAB}")
    Call ySendKeys(" ", 2)                          '2秒とめる
    
    Rem コピー2
    セル.Offset(0, 1).Copy
    AppActivate "ミーティングパスコードを入力"
    Call ySendKeys("^V")
    Call ySendKeys("{TAB}")
    Call ySendKeys(" ", 5)                          '5秒とめる
    
    Call ySendKeys(" ")
    
    Application.CutCopyMode = False
    
End Sub

Private Function ySendKeys(Keys As String, Optional Time As Double = 0.5, Optional Wait As Boolean = True)
    
    Call Application.SendKeys(Keys, Wait)
    Call Application.Wait([Now()] + Time / 86400)
    
End Function
anonymous セミオートログイン
VBA
Option Explicit

Sub リンク作成()
    
    Dim i As Long
    
    For i = 3 To Cells(Rows.Count, 2).End(xlUp).Row
        Hyperlinks.Add anchor:=Cells(i, 3), Address:="", SubAddress:="", TextToDisplay:="実行"
    Next
    
End Sub

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
    
    Dim ジャンル As String
    ジャンル = Target.Range.Offset(0, 1).Value
    
    Dim 最初のセル As Range
    Set 最初のセル = Target.Range.Offset(0, 2)
    
    Select Case ジャンル
        Case "フォルダ"
            Call フォルダ(最初のセル)
        Case "Zoom"
            Call Zoom(最初のセル)
    End Select
    
End Sub

Sub フォルダ(ByVal セル As Range)
    
    Rem コピー1
    セル.Copy
    AppActivate "エクスプローラ":                   Application.Wait [Now() + "00:00:00.5"]         '0.5秒とめる
    Application.SendKeys "^V", True:                Application.Wait [Now() + "00:00:00.5"]         '0.5秒とめる
    Application.SendKeys "{TAB}", True:             Application.Wait [Now() + "00:00:00.5"]         '0.5秒とめる
    
    Rem コピー2
    セル.Offset(0, 1).Copy
    Application.SendKeys "^V", True:                Application.Wait [Now() + "00:00:00.5"]         '0.5秒とめる
    Application.SendKeys " ", True:                 Application.Wait [Now() + "00:00:00.5"]         '0.5秒とめる
    Application.SendKeys "{TAB}", True:             Application.Wait [Now() + "00:00:00.5"]         '0.5秒とめる
    Application.SendKeys "{ENTER}", True
    
    Application.CutCopyMode = False
    
End Sub

Sub Zoom(ByVal セル As Range)
    
    Rem コピー1
    セル.Copy
    AppActivate "Zoom":                             Application.Wait [Now() + "00:00:00.5"]         '0.5秒とめる
    Application.SendKeys "^V", True:                Application.Wait [Now() + "00:00:00.5"]         '0.5秒とめる
    Application.SendKeys "{TAB}", True:             Application.Wait [Now() + "00:00:00.5"]         '0.5秒とめる
    Application.SendKeys "{TAB}", True:             Application.Wait [Now() + "00:00:00.5"]         '0.5秒とめる
    Application.SendKeys "{TAB}", True:             Application.Wait [Now() + "00:00:00.5"]         '0.5秒とめる
    Application.SendKeys "{TAB}", True:             Application.Wait [Now() + "00:00:00.5"]         '0.5秒とめる
    Application.SendKeys " ", True:                 Application.Wait [Now() + "00:00:00.5"]         '0.5秒とめる
    Application.SendKeys "{TAB}", True:             Application.Wait [Now() + "00:00:00.5"]         '0.5秒とめる
    Application.SendKeys " ", True:                 Application.Wait [Now() + "00:00:00.5"]         '0.5秒とめる
    
    Application.Wait [Now() + "00:00:02"]           '2秒とめる(PW画面に移るまで時間かかるため)
    
    Rem コピー2
    セル.Offset(0, 1).Copy
    AppActivate "ミーティングパスコードを入力":     Application.Wait [Now() + "00:00:00.5"]         '0.5秒とめる
    Application.SendKeys "^V", True:                Application.Wait [Now() + "00:00:00.5"]         '0.5秒とめる
    Application.SendKeys "{TAB}", True:             Application.Wait [Now() + "00:00:00.5"]         '0.5秒とめる
    Application.SendKeys " ", True:                 Application.Wait [Now() + "00:00:00.5"]         '0.5秒とめる
    
    Application.Wait [Now() + "00:00:05"]           '5秒とめる(接続に時間がかかるため)
    
    Application.SendKeys " ", True
    
    Application.CutCopyMode = False
    
End Sub
anonymous No title
Python
import gspread
from oauth2client.service_account import ServiceAccountCredentials
import asyncio
import gspread_asyncio

scope = ['https://spreadsheets.google.com/feeds','https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name('spreadsheet-sample.json', scope)
gc = gspread.authorize(credentials)

# 「キー」でワークブックを取得
SPREADSHEET_KEY = '15IFIuwiVy08hvNI4cdxfJK-D61S8AWvPcPxZhpon3c0'
wb = gc.open_by_key(SPREADSHEET_KEY)
ws = wb.sheet1  # 一番左の「シート1」を取得


#===ここからスクレイピング用コード===
import requests
import bs4
import pandas as pd
import codecs
from urllib.parse import urljoin
from urllib.parse import urlparse
import urllib.request, urllib.error
import time
import itertools

i = 0
while True:
    try:
        print(str(i+1)+'ページ目')
        url = 'https://haken.rikunabi.com/h/r/HS1B070n.jsp?g=W&shokushu_Cd=0342&kinmuchi_Cd=27152%2C27153%2C27104%2C27106%2C27107%2C27158%2C27159%2C27161%2C27113%2C27114%2C27115%2C27116%2C27117%2C27118%2C27119%2C27120%2C27121%2C27122%2C27123%2C27124%2C27125%2C27126%2C27127%2C27128&totalCount=135&targetPage=1&search_Area_Kbn=W&return_Kbn=1&cmd=PREV&pageNo='+str(i)
        res = requests.get(url)
        res.raise_for_status()
        soup = bs4.BeautifulSoup(res.content, 'html.parser')

        titles = []
        for title in soup.select('.ttl_cst a'):
            t = title.get_text(strip=True)
            titles.append(t)

        comps = []
        for comp in soup.select('.txt_company_data a'):
            c = comp.get_text(strip=True)
            comps.append(c)

        gs_list = []
        for t in range(len(titles)):
            lists = []
            lists.append(titles[t])
            lists.append(comps[t])
            gs_list.append(lists)
        time.sleep(3)

        for row_datas in gs_list:
            ws.append_row(row_datas)
            print(row_datas)

        time.sleep(30)

        i+=1

    except requests.exceptions.HTTPError:
       print('次ページなし')
       break
anonymous No title
Python
print("てすと")
anonymous コピー&リネーム
VBA
Option Explicit
Const フォルダパスの行数 = 3
Const 元の列数 = 2
Const コピー先の列数 = 3
Const 最初の行 = 6

Sub リネーム()
    
    Dim ws作業シート As Worksheet
    Set ws作業シート = ThisWorkbook.ActiveSheet
    
    Rem コピー先の指定がなければフォルダを作成
    If ws作業シート.Cells(フォルダパスの行数, コピー先の列数) = "" Then
        MkDir ws作業シート.Cells(フォルダパスの行数, 元の列数) & "\リネーム後"
        ws作業シート.Cells(フォルダパスの行数, コピー先の列数) = ws作業シート.Cells(フォルダパスの行数, 元の列数) & "\リネーム後"
    End If
    
    Dim 最後の行 As Long
    最後の行 = ws作業シート.Cells(Rows.Count, 元の列数).End(xlUp).Row
    
    Rem コピー&リネーム
    Dim f As Long
    For f = 最初の行 To 最後の行
        FileCopy ws作業シート.Cells(フォルダパスの行数, 元の列数).Value & "\" & ws作業シート.Cells(f, 元の列数).Value, _
                 ws作業シート.Cells(フォルダパスの行数, コピー先の列数).Value & "\" & ws作業シート.Cells(f, コピー先の列数).Value
    Next
    
    MsgBox "コピー&リネーム完了!"
    
End Sub
anonymous ブックシートの保護と解除
VBA
Sub 全シートの保護と解除()
    
選択:
    
    Rem 保護の設定・解除の選択
    Dim 選択 As Long
    選択 = Application.InputBox(Prompt:="処理を選択してください" & vbCrLf & vbCrLf & " 1 = 保護   2 = 解除   0 = キャンセル", Type:=1)
    
    Rem キャンセルと再選択
    If 選択 = False Then GoTo キャンセル処理
    If Not (選択 = 1 Or 選択 = 2) Then
        MsgBox "1 か 2 を入力してください"
        GoTo 選択
    End If
    
    Rem パスワードの入力
    Dim GetPW As String
    Select Case 選択
        Case 1
            GetPW = Application.InputBox(Prompt:="保護パスワードを入力してください", Type:=2)
            If GetPW = False Then GoTo キャンセル処理
            Call 保護(GetPW)
        Case 2
            GetPW = Application.InputBox(Prompt:="解除パスワードを入力してください", Type:=2)
            If GetPW = False Then GoTo キャンセル処理
            Call 保護解除(GetPW)
    End Select
    
    Exit Sub
    
キャンセル処理:
    MsgBox "キャンセルしました"
    
End Sub

Sub 保護(ByVal PW As String)
    
    Rem シートの保護
    Dim ws As Worksheet
    For Each ws In Worksheets
        ws.Protect Password:=PW, UserInterfaceOnly:=True     'マクロでの操作は許可
    Next
    
    Rem ブックの保護
    ActiveWorkbook.Protect Password:=PW, Structure:=True, Windows:=False
    
End Sub

Sub 保護解除(ByVal PW As String)
    
    Rem シートの保護解除
    Dim ws As Worksheet
    For Each ws In Worksheets
        ws.Unprotect Password:=PW
    Next
    
    Rem ブックの保護解除
    ActiveWorkbook.Unprotect Password:=PW
    
End Sub
anonymous ブックとシートの保護
VBA
Sub 全シートの保護と解除()
    
    On Error GoTo キャンセル処理
    
    Rem 保護の設定・解除の選択
    Dim 選択 As Long
    選択 = InputBox("処理を選択してください" & vbCrLf & vbCrLf & "保護 = 1  解除 = 2")
    
    On Error GoTo 0
    
    Rem パスワードの入力
    Dim GetPW As String
    GetPW = InputBox("パスワードを入力してください")
    
    Select Case 選択
        Case 1
            Call 保護(GetPW)
        Case 2
            Call 保護解除(GetPW)
    End Select
    
    Exit Sub
    
キャンセル処理:
    MsgBox "キャンセルしました"
    
End Sub

Sub 保護(ByVal PW As String)
    
    Rem シートの保護
    Dim ws As Worksheet
    For Each ws In Worksheets
        ws.Protect Password:=PW, UserInterfaceOnly:=True     'マクロでの操作は許可
    Next
    
    Rem ブックの保護
    ActiveWorkbook.Protect Password:=PW, Structure:=True, Windows:=False
    
End Sub

Sub 保護解除(ByVal PW As String)
    
    Rem シートの保護解除
    Dim ws As Worksheet
    For Each ws In Worksheets
        ws.Unprotect Password:=PW
    Next
    
    Rem ブックの保護解除
    ActiveWorkbook.Unprotect Password:=PW
    
End Sub