ときどきの雑記帖 RE* (新南口)
虹とスニーカーの頃
夏が来れば思い出す
ではないけど、この時期になると自分の大学受験のときのことを思い出してですね(ry
今週のしずえさん
「ローファー」「スニーカー」「サンダル」
組合せ計量機
ピタゴラスイッチで知った(見た)。
こんな機械があるのね。 反射的に「最適な組み合わせ」→「組合せ爆発」と連想したけど このぐらいの数なら「ものの数ではない」か。
特許が出ていると思うんだけど、どんなもんだかちょっと見てみたい😄
parseInt
[B! javascript] 【JavaScript】実数から整数への変換に parseInt() を使ってはいけない2つの理由🙅♀️ - Qiita という話題に関して
僕も浮動小数点数から整数への変換がparseIntで問題なさそうと判断できる心理がまったく分からなかったんですが、「parseという単語の意味はよく分からんけどなんかintに変換してくれるやつ」ぐらいの認識だとそういう判断ができてしまいそうだなとさっき思い至りました。 https://t.co/kZjiJ4a4D7
— athos)))))))) (@athos0220) January 8, 2022
"javascript convert float to int"でウェブ検索(Duck2Go)したら、こんなサイトがトップで出てきました。
— もりぐち (@mrgchr) January 8, 2022
こういうサイトを参考にして、趣旨を理解せずに使う人も多いのかもしれませんね。https://t.co/kDKWArA2e6
(だとしても、Qiitaに書いて無知をひけらかすような真似は止めておけば?と思います)
というツイートを見かけたので Convert a Float Number to Int in JavaScript | Delft Stack を見たのだけど、 知っている手法もあった一方でいくつか知らなかったものもあった (それぞれが「有用」かどうかはまた別の問題)。 0ビット右シフト(でfloat/double→int変換)ってどこかで見たような気もするんだけど、どこでだろう?
intへの変換にparseIntを使う発想がどこから出てきたかなどにはここでは触れない (近寄りたくない) 😄
/
one true awkのキャラクタークラス中での/
の扱い
(変更がrevertされたと以前書いたやつね)、
変更しないという方針になったっぽい?
you should have visited previously closed issues, #135 and #81 this will not be fixed in onetrueawk for now. thanks
thanks for the discussion. i’m less concerned with the strict readings of POSIX or the book. for me the main issue is that the regex “/” lexer is broken and inconsistent with RE in strings. i have not seen todd’s fixes, will take a look.
i'm less concerned with the strict readings of POSIX or the book
に、(申し訳ないけど)ちょっと笑ってしまった。
まあなんというかその(ry
mkdir -p
ところでひとつ闇テクを紹介すると、
— らりお・ザ・.*🈗然㊌㋞㋰㋷㋓ (@lo48576) January 12, 2022
mkdir -p foo1/bar1-1/baz1-1-1/../baz1-1-2/../../bar1-2/../../foo2/bar2-1
みたいな感じで一撃でツリーまるごと作ることができます
ということで(ry
coreutils/mkdir.c at master · coreutils/coreutils
int
main (int argc, char **argv)
{
char const *specified_mode = NULL;
int optc;
char const *scontext = NULL;
struct mkdir_options options;
options.make_ancestor_function = NULL;
options.mode = S_IRWXUGO;
options.mode_bits = 0;
options.created_directory_format = NULL;
options.set_security_context = NULL;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
atexit (close_stdout);
while ((optc = getopt_long (argc, argv, "pm:vZ", longopts, NULL)) != -1)
{
switch (optc)
{
case 'p':
options.make_ancestor_function = make_ancestor;
break;
と、-p
オプション指定時はoptions.make_ancestor_function
と
そこに設定されたmake_ancestor
でなにかするのだろうと
同じファイルの他の部分を探すとmake_ancestor
はすぐに見つかる。
が
coreutils/mkdir.c at master · coreutils/coreutils
/* Make ancestor directory DIR, whose last component is COMPONENT,
with options OPTIONS. Assume the working directory is COMPONENT's
parent. Return 0 if successful and the resulting directory is
readable, 1 if successful but the resulting directory is not
readable, -1 (setting errno) otherwise. */
static int
make_ancestor (char const *dir, char const *component, void *options)
{
struct mkdir_options const *o = options;
if (o->set_security_context
&& defaultcon (o->set_security_context, component, S_IFDIR) < 0
&& ! ignorable_ctx_err (errno))
error (0, errno, _("failed to set default creation context for %s"),
quoteaf (dir));
if (o->umask_ancestor != o->umask_self)
umask (o->umask_ancestor);
int r = mkdir (component, S_IRWXUGO);
if (o->umask_ancestor != o->umask_self)
{
int mkdir_errno = errno;
umask (o->umask_self);
errno = mkdir_errno;
}
if (r == 0)
{
r = (o->umask_ancestor & S_IRUSR) != 0;
announce_mkdir (dir, options);
}
return r;
}
ふむ?
確かにmkdir (component, S_IRWXUGO)
というのはあるが
これは
MKDIR(2)
だろうから脇に積んでからバックトラック(謎)して
options.make_ancestor_function
経由で調べると
coreutils/mkdir.c at master · coreutils/coreutils
make_dir_parents
という関数を呼び出しているのが目についた。
この関数は
coreutils/install.c at 00ea4bacf6063ccc125209d5186f8f2382c6f0d4 · coreutils/coreutils
でも使っている GNULibにある関数。
gnulib/mkdir-p.c at 3c99da63be95a3bc6cc881e1ca6c849a921569e1 · coreutils/gnulib
/* Ensure that the directory DIR exists.
WD is the working directory, as in savewd.c.
If MAKE_ANCESTOR is not null, create any ancestor directories that
don't already exist, by invoking MAKE_ANCESTOR (DIR, ANCESTOR, OPTIONS).
This function should return zero if successful, -1 (setting errno)
otherwise. In this case, DIR may be modified by storing '\0' bytes
into it, to access the ancestor directories, and this modification
is retained on return if the ancestor directories could not be
created.
Create DIR as a new directory, using mkdir with permissions MODE;
here, MODE is affected by the umask in the usual way. It is also
OK if MAKE_ANCESTOR is not null and a directory DIR already exists.
Call ANNOUNCE (DIR, OPTIONS) just after successfully making DIR,
even if some of the following actions fail.
Set DIR's owner to OWNER and group to GROUP, but leave the owner
alone if OWNER is (uid_t) -1, and similarly for GROUP.
Set DIR's mode bits to MODE, except preserve any of the bits that
correspond to zero bits in MODE_BITS. In other words, MODE_BITS is
a mask that specifies which of DIR's mode bits should be set or
cleared. Changing the mode in this way is necessary if DIR already
existed, if MODE and MODE_BITS specify non-permissions bits like
S_ISUID, or if MODE and MODE_BITS specify permissions bits that are
masked out by the umask. MODE_BITS should be a subset of
CHMOD_MODE_BITS.
However, if PRESERVE_EXISTING is true and DIR already exists,
do not attempt to set DIR's ownership and file mode bits.
Return true if DIR exists as a directory with the proper ownership
and file mode bits when done, or if a child process has been
dispatched to do the real work (though the child process may not
have finished yet -- it is the caller's responsibility to handle
this). Report a diagnostic and return false on failure, storing
'\0' into *DIR if an ancestor directory had problems. */
と関数前のコメントに動作が細かく説明されているのを横目にしつつ 関数本体を見る。
bool
make_dir_parents (char *dir,
struct savewd *wd,
int (*make_ancestor) (char const *, char const *, void *),
void *options,
mode_t mode,
void (*announce) (char const *, void *),
mode_t mode_bits,
uid_t owner,
gid_t group,
bool preserve_existing)
{
int mkdir_errno = (IS_ABSOLUTE_FILE_NAME (dir) ? 0 : savewd_errno (wd));
if (mkdir_errno == 0)
{
ptrdiff_t prefix_len = 0;
int savewd_chdir_options = (HAVE_FCHMOD ? SAVEWD_CHDIR_SKIP_READABLE : 0);
if (make_ancestor)
{
prefix_len = mkancesdirs (dir, wd, make_ancestor, options);
if (prefix_len < 0)
{
if (prefix_len < -1)
return true;
mkdir_errno = errno;
}
}
とこの関数でも色々やっているのだけど、さらに別のGNULibの関数 mkancesdirs を呼び出しているのを見てくじけた😄
まあ大体わかった(本当に?)のでヨシ!
style
「引用符以外を」ってどういう言い回しってどういうものなのだろうと思いつつ 引用符以外を検索するperl - Qiita から replace_noquote.pl をみてびっくりした。
use strict;
use warnings;
use File::Basename 'basename', 'dirname';
use Getopt::Long 'GetOptions';
# CONSTANT
my $version = "00.00";
my $revision = "20220111" ;
my $OK = 1;
my $NG = 0;
my $ModeSRCH = "S" ;
my $ModeREPL = "R" ;
my $ModeHS = "HS" ;
my $ModeHR = "HR" ;
一瞬アセンブリ言語のソースかと思ってしまった (タブじゃなくて素直に(?)スペースで区切っているところもあるのがよくわからん)。
銀河の歴史がまた一ページ
宇宙暦800年1月13日 自由惑星同盟軍がマル・アデッタ星域に布陣したとの報が銀河帝国軍にもたらされた。#本伝7巻 #大親征 #マル・アデッタ星域会戦
— 今日は何の日@銀英伝bot (@logh_today) January 12, 2022