Skip to content

Instantly share code, notes, and snippets.

@zakuroishikuro
zakuroishikuro / stop_lenovo_vantage_cleaning_mode.ps1
Last active January 5, 2024 14:57
kill lenovo vantage cleaning mode
$filePath = "C:\ProgramData\Lenovo\Vantage\Addins\ThinkKBDAddin\*\LenovoVantage.CleanYourDevice.exe"
$acl = Get-Acl $filePath
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Everyone", "Execute", "Deny")
$acl.SetAccessRule($rule)
Set-Acl -Path $filePath -AclObject $acl
@zakuroishikuro
zakuroishikuro / create_logseq_page.js
Last active October 18, 2023 17:54
logseq bookmarklet
javascript: (()=>{
const {hostname, pathname} = location;
let page = hostname + pathname;
let content = "";
const now = new Date();
const date = now.toLocaleDateString().replace(/\//g, "-");
const time = now.toLocaleTimeString();
content = `source:: [${document.title}](${location.href})\ncreated:: [[${date}]] ${time}`;
@zakuroishikuro
zakuroishikuro / tiktoken_search_long_word.py
Last active May 2, 2023 14:18
1トークンで長い単語を探す
import tiktoken
import heapq
import re
ONLY_JAPANESE = True
CONTAINS_NON_SYMBOL = True
MODEL = "gpt-3.5-turbo"
#MODEL = "gpt-4"
enc = tiktoken.encoding_for_model(model)
const defaultDict = <T>(defaultValue: T, object = {}): { [key: string]: T } => {
return new Proxy(object, {
get(obj, prop) {
return prop in obj ? obj[prop] : defaultValue;
},
});
};
const dict = defaultDict(100);
declare global {interface Object { log<T>(this: T, msg?): T }} // prettier-ignore
export function main(input: string): number | string {
const [A, B] = input.split(/\s/).map(Number);
return input;
}
// === ここから読む必要なし ===
const DEBUG = process.env.NODE_ENV === "test";
Object.assign(Object.prototype,{log<T>(this:T,msg="log"){if(DEBUG)console.log(`[${msg}] ${this}`);return this}}) // prettier-ignore
Object.defineProperty(Object.prototype, "out", {
value() {
console.log(this.toString());
return this;
},
});
interface Object {
out<T>(this: T): T;
}
@zakuroishikuro
zakuroishikuro / getout.ts
Created November 13, 2022 00:04
console.logするだけのgetter生やしたい
Object.defineProperty(Object.prototype, "out", {
get() {
console.log(this.toString());
return this;
},
});
interface Object {
get out(): any; // ここをanyじゃなくoutを呼んでいるインスタンスの型にしたい
}
const comp = (a, b) => +(a > b || (a < b && -1));
[{ id: "a" }, { id: "c" }, { id: "b" }].sort((a, b) => comp(a.id, b.id));
//=> [{ id: "a" }, { id: "b" }, { id: "c" }]
@zakuroishikuro
zakuroishikuro / bookmarklet.js
Created September 3, 2022 14:32
https://node.green/ でv18とv12の差分だけ表示するブックマークレット
javascript:{
const [v12,v18] = [".v12", ".v18"].map(v=>document.querySelector(v).cellIndex);
const style = document.createElement("style");
style.textContent = `
th, td {display: none}
td:nth-child(1),
th:nth-child(${v12 + 1}), th:nth-child(${v18 + 1}),
td:nth-child(${v12 + 1}), td:nth-child(${v18 + 1})
{
/**
* ましゅまろ1 物理現象グラフィックバトル
* https://products.sint.co.jp/hubfs/resource/topsic/pgb2021/1_1.pdf
*
* 入出力は適当 (文字列 or 数値)
*/
// 前提条件 (実行しない)
function premise(input) {
const [x, y, k] = input.split(/\s+/).map(s => parseInt(s));