anonymous No title
JavaScript
const getAccessToken = (config) => {
  const time = Date.now();
  const header = Utilities.base64Encode(JSON.stringify({ 'alg': 'RS256', 'typ': 'JWT' }));
  const claimSet = Utilities.base64Encode(JSON.stringify({
    'iss': config.CLIENT_ID,
    'sub': config.SERVICE_ACCOUNT,
    'iat': Math.floor(time / 1000),
    'exp': Math.floor(time / 1000 + 3600)
  }));
  const signature = Utilities.base64Encode(Utilities.computeRsaSha256Signature(`${header}.${claimSet}`, config.PRIVATE_KEY));
  const jwt = `${header}.${claimSet}.${signature}`;

  const endpoint = 'https://auth.worksmobile.com/oauth2/v2.0/token';
  const options = {
    method: 'post',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    payload: {
      'assertion': jwt,
      'grant_type': 'urn:ietf:params:oauth:grant-type:jwt-bearer',
      'client_id': config.CLIENT_ID,
      'client_secret': config.CLIENT_SECRET,
      'scope': config.SCOPE
    }
  }
  return JSON.parse(UrlFetchApp.fetch(endpoint, options));
}

const snedMessageToRoom = () => {
  const config = {
    SCOPE: 'bot,bot.read',
    CLIENT_ID: 'クライアントID', // ★
    CLIENT_SECRET: 'クライアントシークレット',// ★
    SERVICE_ACCOUNT: 'サービスアカウント',// ★
    PRIVATE_KEY: ` 
-----BEGIN PRIVATE KEY-----
asvdfvbas // ★
awfeawefa // ★
awefawefw // ★
-----END PRIVATE KEY-----
`
  }

  const accessToken = getAccessToken(config).access_token;
  const botId = 'ボットID'; // ★
  const channelId = 'チャンネルID'; // ★
  const url = `https://www.worksapis.com/v1.0/bots/${botId}/channels/${channelId}/messages`;
  const options = {
    method: 'post',
    headers: {
      'Authorization': `Bearer ${accessToken}`,
      'Content-Type': 'application/json'
    },
    payload: JSON.stringify({
      'content': {
        'type': 'text',
        'text': 'hello'
      }
    })
  }

  const response = UrlFetchApp.fetch(url, options);
}

anonymous No title
JavaScript
{
  "name": "text1",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "@mdi/font": "5.9.55",
    "core-js": "^3.8.3",
    "fast-xml-parser": "^4.0.8",
    "jquery": "^3.6.0",
    "jquery.typist": "^0.0.7",
    "roboto-fontface": "*",
    "vue": "^3.2.13",
    "vuetify": "npm:@vuetify/nightly@next",
    "webfontloader": "^1.0.0"
  },
  "devDependencies": {
    "@babel/core": "^7.12.16",
    "@babel/eslint-parser": "^7.12.16",
    "@vue/cli-plugin-babel": "~5.0.0",
    "@vue/cli-plugin-eslint": "~5.0.0",
    "@vue/cli-service": "~5.0.0",
    "eslint": "^7.32.0",
    "eslint-plugin-vue": "^8.0.3",
    "vue-cli-plugin-vuetify": "~2.5.1",
    "webpack-plugin-vuetify": "^2.0.0-alpha.0"
  },
  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/vue3-essential",
      "eslint:recommended"
    ],
    "parserOptions": {
      "parser": "@babel/eslint-parser"
    },
    "rules": {}
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not dead",
    "not ie 11"
  ]
}
anonymous No title
JavaScript
function ageCheck(){
    if( confirm("20歳以上ですか?")){
        alert("お酒が飲めますね!");
    }
    else {
        alert("20歳まで我慢しましょう!");
    }
}

ageCheck();
anonymous No title
JavaScript
document.evaluate("a//[contains(text(),'クリック')]",document.null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);
anonymous No title
JavaScript
//1HのstochRSIを表示
mtf = input.timeframe(title='MTF算出_60分', defval='60')
mtf_rsi = request.security(syminfo.tickerid, mtf, rsi1)
mtf_k = ta.sma(ta.stoch(mtf_rsi, mtf_rsi, mtf_rsi, lengthStoch), smoothK)
mtf_d = ta.sma(mtf_k, smoothD)

//エントリー条件を記述 条件を満たせばtrue扱いとなる
entry = ta.crossover(k,d) and ta.crossover(mtf_k,mtf_d)

//アラート条件
alertcondition(entry, title='エントリー例', message='1Dと1hのstochGC')
anonymous No title
JavaScript
class BlockChain {

  constructor(nemesisHash, timestamp, message) {
    this.chain = [{
      height: 0,
      hash: nemesisHash,
      timestamp: 0,
      epochAjustment: timestamp,
      message: message,
    }];
    console.log("Start BlockChain");
    console.log(JSON.stringify(this.chain[0], null, 2));
  }

  static __init__() {
    const nemesisMessage = "hello block chain Symbol !!";
    const nemesisHashRow = Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_256, nemesisMessage);
    const nemesisHash = nemesisHashRow.map(n => ("0" + ((n < 0) ? 256 + n : n).toString(16)).slice(-2)).join("").toUpperCase();
    const timestamp = new Date().getTime();
    return new BlockChain(nemesisHash, timestamp, nemesisMessage);
  }

  add() {
    const message = new Date().toLocaleString() + " Blockを追加しました";
    const lastBlock = this.chain[this.chain.length - 1];
    const epochAjustment = this.chain[0].epochAjustment;
    const date = new Date().getTime();
    if (this.hashSum() === true) {
      const hashRow = Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_256, `${lastBlock.hash}${message}`);
      const hash = hashRow.map(n => ("0" + ((n < 0) ? 256 + n : n).toString(16)).slice(-2)).join("").toUpperCase();
      const block = { height: this.chain.length, hash, timestamp: date - epochAjustment, message, epochAjustment: undefined };
      console.log(JSON.stringify(block, null, 2))
      this.chain.push(block);
    } else {
      throw new Error("データの改竄があった為、停止しました");
    }
  }

  hashSum() {
    if (this.chain.length === 1) {
      return true;
    }
    for (let i = 1; i < this.chain.length; i++) {
      const prev = this.chain[i - 1];
      const current = this.chain[i];
      const currentHashRow = Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_256, `${prev.hash}${current.message}`);
      const currentHash = currentHashRow.map(n => ("0" + ((n < 0) ? 256 + n : n).toString(16)).slice(-2)).join("").toUpperCase();
      if (currentHash !== current.hash) return false;
    }
    return true;
  }

}

function test() {
  const Chain = BlockChain.__init__();
  for (let i = 0; i < 50; i++) {
    Utilities.sleep(1000);
    Chain.add();
    // 改竄
    if(i === 10){
      console.log("データを改竄しました");
      Chain.chain[5].message = "改竄します";
    }
  }
}
anonymous テキスト選択禁止を解除するブックマークレットだよ
Public Domain JavaScript
javascript:document.body.appendChild((function(){var s=document.createElement('style');s.innerHTML='* { user-select: initial !important; -webkit-user-select: initial !important; }'; return s})());var ss = function() { event.stopImmediatePropagation(); return true; }; document.querySelectorAll('*').forEach(function(e) { e.addEventListener('selectstart', ss, true); });
anonymous Node.jsでGoogle Apps Script APIを使う
JavaScript
const fs = require('fs');

const { google } = require('googleapis');
const OAuth2 = google.auth.OAuth2;

// OAuthクライアントを初期化
const creds = JSON.parse(fs.readFileSync('creds.json', 'utf-8')).installed;
const oauth2Client = new OAuth2(
    creds.client_id,
    creds.client_secret,
    'urn:ietf:wg:oauth:2.0:oob'
);

// 認証コードを取得するためのURLを取得
const getAuthorizeUrl = () => {
    const authorizeUrl = oauth2Client.generateAuthUrl({
        access_type: 'offline',
        scope: [
            'https://www.googleapis.com/auth/script.scriptapp',
            'https://www.googleapis.com/auth/drive'
        ],
    });
    return authorizeUrl;
}

// トークンを取得してJSONファイルに保存
const getToken = () => {
    const code = 'getAuthorizeUrlで得たコード';
    oauth2Client.getToken(code, (err, token) => {
        fs.writeFileSync('token.json', JSON.stringify(token));
    });
}

// GAS APIを実行
const callAppsScript = (auth) => {
    const scriptId = 'デプロイID';
    const script = google.script('v1');
    script.scripts.run({
        auth: auth,
        resource: {
            function: 'doSomething',
        },
        scriptId: scriptId,
    }, (err, resp) => {
        // GASの関数からの戻り値
        console.log(resp.data.response.result);
    });
}

// エントリー
const main = () => {
    // JSONからトークンを取得してOAuthClientにセットする
    const token = JSON.parse(fs.readFileSync('token.json', 'utf-8'));
    oauth2Client.setCredentials(token);
    // GASの関数を実行
    callAppsScript(oauth2Client);
}


main();
anonymous No title
JavaScript
window.addEventListener('keypress', handleKeyDown);

var pressed = "";
var howmany = 0;
document.querySelector('#main').innerHTML = `
<h1>${pressed}<h1>
<h2>現在${howmany}文字入力中です<h2>
<h3>右クリックでファイルにセーブできます<h3>
`
function handleKeyDown (event) {
  if(event.key !== "Enter"){
  if(event.key === "Backspace"){
    pressed = pressed.slice(0, pressed.length - 1)
  }else if (event.key === " "){
    pressed += " "
  
  }else if(/[a-zA-Z0-9]/.test(event.key)){
  pressed += event.key
  }else if(/[,.;:@!"#$%&'-^<>?+*`~=_/]/.test(event.key)){
  pressed += event.key
  }
}
  
  howmany = pressed.length
  document.querySelector('#main').innerHTML = `
<h1>${pressed}<h1>
<h2>現在${howmany}文字入力中です<h2>
`
}

function draw() {
  if (mouseButton === RIGHT && mouseIsPressed === true) {
    var typed = createWriter('typed.txt')
    typed.print(pressed);
    typed.close();
    typed.clear();
    }
}
anonymous No title
JavaScript
import fs from "fs";
const buffer = Buffer.from(fs.readFileSync("sample.png"));
// --- split png header & chunk --- //
// skip
// --- --- //
console.log("1. Hex", buffer.toString("hex").length);
console.log("2. Base64", buffer.toString("base64").length);
console.log("3. Binary", buffer.toString("binary").length);
console.log("4. Uint8", Uint8Array.from(buffer).toString().length);
console.log("5. 2進数", [...buffer.values()].map(b => b.toString(2)).join("").length);
Don't you submit code?
Submit