Skip to content

Instantly share code, notes, and snippets.

View umorigu's full-sized avatar

Moriguchi, Hirokazu umorigu

View GitHub Profile
@umorigu
umorigu / userdata.sh
Created March 16, 2019 05:02
Ubuntu 18.04 GUI - EC2 Use data
#!/bin/bash
set -eux
apt -y update
#echo grub-pc hold | dpkg --set-selections
#apt -y upgrade
#sed -i 's/^PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config
#systemctl restart ssh
@umorigu
umorigu / _autoshutdown.sh
Last active March 16, 2019 00:50
Linux: 一定時間操作しなかったら shutdown (Ubuntu 18.04)
#!/bin/bash
# Precondition: `export PROMPT_COMMAND="history -a"` in .bashrc for ubuntu user
set -eux
COMMAND_TIME=$(date -Is -r /home/ubuntu/.bash_history)
NOW=$(date -Is)
if [[ $(date -d "$NOW" +%s) -lt $(date -d "$COMMAND_TIME +60 minutes" +%s) ]]; then
@umorigu
umorigu / autoshutdown.service
Last active March 16, 2019 00:28
Linux: 一定時間操作しなかったら shutdown (起動直後uptime利用版)
[Unit]
Description=Auto shutdown
[Service]
Type=oneshot
ExecStart=/opt/autoshutdown/autoshutdown.sh
@umorigu
umorigu / attach.inc.php
Created June 1, 2011 16:37
attach.inc.php for too long filename attach file.
<?php
// PukiWiki - Yet another WikiWikiWeb clone
// $Id: attach.inc.php,v 1.82 2006/04/14 23:51:12 teanan Exp $
// Copyright (C)
// 2003-2006 PukiWiki Developers Team
// 2002-2003 PANDA <panda@arino.jp> http://home.arino.jp/
// 2002 Y.MASUI <masui@hisec.co.jp> http://masui.net/pukiwiki/
// 2001-2002 Originally written by yu-ji
// License: GPL v2 or (at your option) any later version
//
@umorigu
umorigu / gist:985590
Created May 22, 2011 15:33
PukiWiki attach plugin filename length bookmarklet
javascript:(function(){
function checkUploadFile() {
var maxLength = 100;
function getHexNameString(s) {
var enc = encodeURIComponent(s);
var result = '';
for (var i = 0; i < enc.length; i++) {
if (enc.substr(i, 1) === '%') {
result += enc.substr(i + 1, 2);
i += 2;
@umorigu
umorigu / gist:973181
Created May 15, 2011 14:00
PukiWiki topicpath anywhere
javascript:(
function(){
var h1list = document.getElementsByTagName('h1');
if (h1list.length == 0) {
return;
}
var h1 = h1list[0];
if (h1.className != "title") {
return;
}
@umorigu
umorigu / pukiwiki.php
Created March 6, 2011 07:28
PukiWiki: /pukiwiki.php?... へのアクセスを /?... へ301リダイレクトする
<?php
$request_uri = $_SERVER['REQUEST_URI'];
$uri = preg_replace("/\/pukiwiki\.php/", "/", $request_uri, 1);
header("HTTP/1.1 301 Moved Permanently");
header("Location: $uri");
echo $uri;
?>
@umorigu
umorigu / gist:820486
Created February 10, 2011 13:11
シングルクオートで囲まれた箇所以外の文字列のみ置換する
// 「シングルクオートで囲まれた箇所以外の文字列のみ置換する」
// aaa を AAA に置換
var target = "var aaa = 'UUUaaaXXX'; alert(aaa); ";
var replaced = target.replace(
/(aaa)|('[^']+')/g, // ここのaaaが検索文字列
function (num, m1, m2, old) {
if (m1) return 'AAA'; // ここのAAAが置換先文字列
return m2;
}
);
@umorigu
umorigu / gist:772187
Created January 10, 2011 00:38
Windows の「プログラムの追加と削除」一覧を出力するワンライナー
mshta.exe "javascript:window.onload=function(){k='Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\';r=new ActiveXObject('WbemScripting.SWbemLocator').ConnectServer(null, 'root\\default').Get('StdRegProv');m=r.Methods_.Item('EnumKey');p=m.InParameters.SpawnInstance_();p.hDefKey=0x80000002;p.sSubKeyName=k;s=r.ExecMethod_(m.Name, p).sNames.toArray();w=new ActiveXObject('WScript.Shell');for(i in s)try{document.write(w.RegRead('HKLM\\'+k+'\\'+s[i]+'\\DisplayName')+'<br>');}catch(e){}}"