Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
https://neos21.net/

Neos21 Neos21

:octocat:
https://neos21.net/
View GitHub Profile
@Neos21
Neos21 / js-operators.js
Last active May 31, 2021
JavaScript の演算子を練習する
View js-operators.js
void function bitwiseNot() {
console.log('\n~ : Bitwise Not : ビット否定');
console.log({ '~-2': ~-2, '~-1': ~-1, '~0': ~0, '~1': ~1, '~2': ~2 });
console.log(`['A', 'B', 'C'].indexOf('D') : `, ['A', 'B', 'C'].indexOf('D'));
console.log(`~['A', 'B', 'C'].indexOf('D') … 0 = Falsy : `, ~['A', 'B', 'C'].indexOf('D'));
console.log(`if(~['A', 'B', 'C'].indexOf('D')) … Not Includes`);
}()
void function exponentiation() {
console.log('\n** : Exponentiation : べき乗');
@Neos21
Neos21 / index.js
Created May 17, 2021
Simple Node.js HTTP Server
View index.js
const port = process.env.PORT || 8080;
require('http').createServer((req, res) => {
console.log(new Date(), req.url);
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end('<!DOCTYPE html><html lang="ja"><head><meta charset="UTF-8"><title>Test</title></head><body><h1>Test</h1></body></html>');
}).listen(port);
console.log(`Server Started : Port [${port}]`);
@Neos21
Neos21 / html-to-markdown.js
Created Jan 9, 2021
HTML を Pedantic な Markdown に変換する
View html-to-markdown.js
const unified = require('unified'); // v9.2.0
const rehypeParse = require('rehype-parse'); // v7.0.1
const rehypeRemark = require('rehype-remark'); // v8.0.0
const remarkStringify = require('remark-stringify'); // v8.1.1 : https://github.com/remarkjs/remark/tree/remark-stringify%408.1.1/packages/remark-stringify
const html = '<html> <!-- ココに HTML ソース --></html>'
const result = unified()
.use(rehypeParse, { fragment: true }) // head・body などを付けない
.use(rehypeRemark)
@Neos21
Neos21 / exec-on-load.js
Created Jan 9, 2021
この JS がどのタイミングで読み込まれても exec() 関数を必ずページ読み込み時に実行する
View exec-on-load.js
(() => {
const exec = () => {
console.log('Something');
};
if(!document.readyState || document.readyState === 'interactive') {
console.log('Interactive (onload)');
window.addEventListener('load', exec);
}
else if(document.readyState === 'loading') {
@Neos21
Neos21 / go-to-gh.js
Created Dec 31, 2020
Go To GitHub Repository Page (From Neo's World)
View go-to-gh.js
((
loc,
fqdn,
gitHubSrc,
documents,
corsAnywhere
) => {
if(!loc.href.includes(fqdn)) return alert("Here Is Not Neo's World");
const open = (url) => { loc.href = url; return Promise.resolve(); }; // 遷移する関数
View README.md

Cross Post

Netlify Functions で動かしていたソースコードの簡略版。

  • Do Well (オレオレマイクロブログ)
  • Misskey
  • Mastodon

に投稿を一括送信する。

@Neos21
Neos21 / list-dom-tree.js
Created Oct 7, 2020
List DOM Tree (Please Execute On DevTools Console)
View list-dom-tree.js
tree = [];
function walk(elem, depth) {
if(elem === undefined) elem = document.body;
if(depth === undefined) depth = 0;
const name = ' '.repeat(depth)
+ elem.tagName.toLowerCase()
+ (elem.id && `#${elem.id}`)
+ [...elem.classList].map(cls => `.${cls}`).join('');
tree.push(name);
elem.children.forEach(child => walk(child, depth + 1));
View install-jq.sh
#!/bin/sh
if ! type jq > /dev/null 2>&1; then
sudo curl -sS -o /usr/local/bin/jq -L https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 && sudo chmod +x /usr/local/bin/jq
fi
View df-json.sh
#!/bin/sh
\df -P \
| tail -n +2 \
| awk '
BEGIN {
printf "{\n";
printf " \"volumes\": [\n";
}
{
@Neos21
Neos21 / apache.sh
Created Aug 26, 2020
Apache Nginx Server Admin Alias
View apache.sh
alias cdh='cd /var/www/html/'
alias cda='vi /etc/httpd/'
alias vic='vi /etc/httpd/conf/httpd.conf'
alias vis='vi /etc/httpd/conf.d/ssl.conf'
alias taila='tail -f /var/log/httpd/access_log'
alias taile='tail -f /var/log/httpd/error_log'
alias tailsa='tail -f /var/log/httpd/ssl_access_log'
alias tailse='tail -f /var/log/httpd/ssl_error_log'
alias tailsr='tail -f /var/log/httpd/ssl_request_log'
alias apre='systemctl restart httpd'