Skip to content

Instantly share code, notes, and snippets.

@tksst
tksst / gist:d679171c2ff912c19d13
Last active October 19, 2016 07:02
1発でTLS証明書の秘密鍵&CSRを作成するスクリプト
#!/bin/bash
CN=example.jp
OU="XYZ Department"
O="Foo Bar Institute, Ltd."
L=Yokohama
ST=Kanagawa
C=JP
<%-- 手っ取り早くセッションのテストをするJSP --%><%@
page contentType="text/plain; charset=UTF-8"%><%
int num = 0;
if (!session.isNew()) {
num = ((Integer)session.getAttribute("num")).intValue();
}
%>num: <%= num++ %>
session ID: <%= session.getId() %>
session created: <%= session.getCreationTime() %>
<% session.setAttribute("num", new Integer(num)); %>
@tksst
tksst / exif.sh
Created October 23, 2016 03:16
SONYのビデオカメラで撮影してPlayMemories Homeで取り込んだとき、4GB超えるファイルが結合されるが、その更新時刻をEXIF時刻に変更する。
#!/bin/bash
touch_date=$( exif --ifd=EXIF --tag=0x9003 -i -m "$1.THM" | perl -pe 's/(\d+):(\d+):(\d+) (\d+):(\d+):(\d+)/$1$2$3$4$5.$6/' )
target_file="$1.mp4"
echo "target file: ${target_file}"
echo "date: ${touch_date}"
touch -t "$touch_date" "$target_file"
#!/bin/bash
readonly MAC=01:23:45:67:89:AB
readonly BROADCAST=255.255.255.255
readonly PORT=9
# bashの組み込みechoに依存している
# zshでもそのまま動く(エスケープシーケンスがデフォルト有効で -e オプションは無視される)
# 注:
# ncコマンドでbroadcastする場合に
import S3 from "aws-sdk/clients/s3";
const s3 = new S3();
export async function* s3ListAllObjects(bucketName: string, limit: number = Number.MAX_VALUE) {
let p = s3.listObjectsV2({ Bucket: bucketName }).promise();
for (let i = 0; i < limit; ++i) {
const result = await p;
@tksst
tksst / Gitで過去のコミットをまとめてreset-authorする.md
Last active November 5, 2022 10:20
Gitで過去のコミットをまとめてreset-authorする
git rebase -i <commit> --exec "git commit --amend --reset-author --no-edit --allow-empty --allow-empty-message"

git rebase:

--exec

Append "exec <cmd>" after each line creating a commit in the final history. <cmd> will be interpreted as one or more shell commands. Any command that fails will interrupt the rebase, with exit code 1.
typedef struct
{
char *str;
conn_rec *c;
} dump_conn_notes_ctx;
static int foo(void *rec, const char *key, const char *value)
{
dump_conn_notes_ctx *v = rec;
@tksst
tksst / add_pac.cmd
Last active February 20, 2022 01:56
PACファイルを切り替える
@echo off
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections" /v "DefaultConnectionSettings" /t REG_BINARY /d "4600000016" /f
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v "AutoConfigURL" /t REG_SZ /d "http://YOUR_PAC_URL" /f
if errorlevel 1 (
echo error occured
pause
)
@tksst
tksst / recursiveReaddir.ts
Created August 26, 2022 10:21
recursiveReaddir.ts
import fs from "node:fs/promises";
import path from "node:path";
async function* recursiveReaddir(dir: string): AsyncGenerator<string> {
const dirents = await fs.readdir(dir, { withFileTypes: true });
for (const dirent of dirents) {
const joined = path.join(dir, dirent.name);
if (dirent.isDirectory()) {
// eslint-disable-next-line no-await-in-loop
for await (const name of recursiveReaddir(joined)) {
@tksst
tksst / index.mjs
Created September 6, 2022 14:58
recursiveReaddir.mjs
import fs from "node:fs/promises";
import path from "node:path";
function isNil(it) {
return it === null || it === undefined;
}
function isNotNil(it) {
return it !== null && it !== undefined;
}