Skip to content

Instantly share code, notes, and snippets.

View den3606's full-sized avatar

den3606 den3606

View GitHub Profile
@PakL
PakL / Nightbot dice roll.md
Last active January 15, 2024 18:48
Nightbot command to roll dice

Simple Nightbot command to roll any number of any kind of dice

$(eval var i=parseInt,d=[],e='$(provider)'=='twitch'?'melziiD20':'🎲20',j=0,l,m='$(query)'.match(/^(([0-9]+)\s+)?(([0-9]+)?d([0-9]+)|([0-9]+))$/)??{},c=i(m[2]??1),n=i(m[4]??1),s=i(m[5]??m[6]??20);c=c>20?20:(c<1||!c?1:c);n=(n<1?1:n);s=(s<1?1:s);for(;j<c;j+=1){d.push(Math.round(n*(s-1)*Math.random())+n)}r=`$(user) rolled ${d.join(', ')} with ${n<2?'a ':n+'×'}🎲`+s;l=r.lastIndexOf(',');(l<0?r:r.substr(0,l)+' and'+r.substr(l+1)).replace(/( |🎲)20(,| |$)/g,` ${ e } $2`))

Examples:
!roll - PakL rolled a 2 with a 🎲6
!roll 20 - PakL rolled a 14 with a 🎲20
!roll 2d6 - PakL rolled a 11 with 2×:game_die:6

@LeeDDHH
LeeDDHH / youtube-markdown.md
Created November 29, 2020 04:51
Youtube markdown 埋め込み
@imbudhiraja
imbudhiraja / convert-keys-to-camel-case
Last active February 24, 2023 14:38
Converting Object Keys from Snake Case, Kebab Case to Camel Case with JavaScript
const mongoose = require('mongoose');
const toCamel = (string) => string.replace(/([-_][a-z])/gi, ($1) => $1
.toUpperCase()
.replace('-', '')
.replace('_', ''));
const isObject = (args) => args === Object(args) && !Array.isArray(args) && typeof args !== 'function';
const keysToCamel = (args) => {
@uupaa
uupaa / get.path.for.node.js.md
Last active December 5, 2023 11:18
node.js で絶対パスや相対パスを取得する方法 npm __dirname

node.js でパスを取得する方法についてのメモ

$ node ~/hoge/Foo.js/a.js

を実行したときに、

  • process.argv[1] から、node コマンドに指定された a.js のパス( ~/hoge/Foo.js/a.js )を取得できます