Skip to content

Instantly share code, notes, and snippets.

View danmaq's full-sized avatar
:octocat:
:)

Shuhei Nomura danmaq

:octocat:
:)
View GitHub Profile
@danmaq
danmaq / psExec.cmd
Created August 12, 2016 08:41
PowerShell のスクリプト実行が許可されていない環境でも ps1 スクリプトを動かす方法 (バッチファイルにスクリプトを埋め込むこともできます!)
@powershell -NoProfile -ExecutionPolicy Unrestricted "$s=[scriptblock]::create((gc \"%~f0\"|?{$_.readcount -gt 1})-join\"`n\");&$s" %*&goto:eof
<#
これで下記の hoge.ps1 が起動します。
または下記を消して、その行から PowerShell スクリプトをべた書きでもおk
#>
. .\hoge.ps1
@danmaq
danmaq / rund4wsl.sh
Last active August 13, 2016 07:06
/etc/rcX.d/AllScripts launcher for "Ubuntu on Windows". Usage: sudo rund4wsl.sh -l <runlevel> -o <start|stop>
#!/bin/bash
failed()
{
echo $1 1>&2
exit 1
}
usage()
{
failed "Usage: sudo $0 -l <runlevel> -o <start|stop>"
@danmaq
danmaq / setup_wmf5.cmd
Created January 12, 2017 20:53
Script of upgrade powershell to 5.0. Targets: Windows 7 or 8.1. (2008 R2 or 2012 R2 are not supported yet)
@powershell -NoProfile -ExecutionPolicy Unrestricted "$s=[scriptblock]::create((gc \"%~f0\"|?{$_.readcount -gt 1})-join\"`n\");&$s" %*&goto:eof
Set-StrictMode -Version 2.0
# OS およびバージョン検証 (使用可能な OS は Windows7 または 8.1 の x86 または x64 のみ)
$os = [System.Environment]::OSVersion
if ($os.Platform -ne [System.PlatformID]::Win32NT) { throw "Detected the OS type that is not supported. This installer requires Windows 7 (x86 or x64) or upper version." }
$wver = $os.Version
if ($wver.Major -lt 6 -or $wver.Minor -lt 1) { throw "Detected the OS version that is not supported. This installer requires Windows 7 (x86 or x64) or upper version." }
if ($wver.Major -eq 6 -and $wver.Minor -eq 2) { throw "Windows 8 should be upgraded to 8.1 before this installation." }
@danmaq
danmaq / exec_more_win7.cmd
Created January 14, 2017 03:10
This Windows batch file verifies that the OS version is Windows 7 or later. If arguments exists, run it.
@echo off
rem USAGE: exec_more_win7 [command: run on Windows7-10] [args for command]
rem ERRORLEVEL: 0: >= Win7, 1: < Win7
rem EXAMPLE 1: call exec_more_win7
rem EXAMPLE 2: exec_more_win7 msiexec /i installer4win7.msi /qn
rem Windows Vista (NT 6.0)
ver | find "Version 6.0" > nul
if not errorlevel 1 goto VISTA
@danmaq
danmaq / confirm.cmd
Created January 14, 2017 05:42
This Windows batch file confirm yes or no. If arguments exists, run it.
@echo off
rem USAGE: confirm [command: run if confirmed] [args for command]
rem ERRORLEVEL: 0: confirmed, 1: declined
rem EXAMPLE 1: call confirm
rem EXAMPLE 2: confirm msiexec /i foo.msi /qn
setlocal
echo Are you sure you want to run? [y/N]
set /P confirm=""
@danmaq
danmaq / call_windows_update.cmd
Last active November 19, 2017 22:30
Script of apply Windows Update automatically. (includes: http://www.vwnet.jp/Windows/PowerShell/FullAutoWU.htm )
@echo off
whoami /groups | Find "High Mandatory Level" > NUL
if not errorlevel 1 goto RUN
powershell -Command Start-Process -Verb runas "%0"
exit /b %errorlevel%
:RUN
powershell -NoProfile -ExecutionPolicy Unrestricted "$s=[scriptblock]::create((gc \"%~f0\"|?{$_.readcount -gt 9})-join\"`n\");&$s" %*
exit /b 0
Set-StrictMode -Version 2.0
@danmaq
danmaq / kemoyuri.fs
Last active January 27, 2018 07:20
😺💡 サーバル関数とあかり関数の組み合わせ https://twitter.com/danmaq/status/828743554574880768 #ゆるゆり #けものフレンズ
let サーバル x = sprintf "きみは%sなフレンズなんだね!" x
let あかり x = sprintf "わぁい%sあかり%sだいすき!" x x
let Mixed x = サーバル (あかり (サーバル (あかり x)))
[<EntryPoint>]
let main argv =
printfn "%A" (Mixed "カバンちゃん")
0
// Question: https://twitter.com/danmaq/status/828743554574880768
@danmaq
danmaq / dotEraseRegex.js
Created February 24, 2017 01:16
Delete dots appearing after the second time. example: 10.234.156.78 -> 10.23415678
const re = /(\.)(.*)\1+/;
const replace = s => s.match(re) ? replace(s.replace(re, '$1$2')) : s;
@danmaq
danmaq / hello-world.pl
Last active January 27, 2018 07:24
💡 Hello World without using literals.
#!/usr/bin/perl -w
use IO::File; #####################< MY BODY WIDTH EQUALS THE ASCII CODE. >#########################
my $hello_txt = IO::File->new(__FILE__, O_RDONLY); ########################################################
foreach ($hello_txt->getlines()) ##########################################################################
{ ############################################################################################################
my $length = length; ######
my $character = chr $length; #####################################################
print $character; ########################################################################################
} ###############################################################################################################
$hello_txt->close(); ######################################################################################
@danmaq
danmaq / danmaq.terminal
Created May 5, 2017 01:57
My theme for macOS Terminal.app
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BackgroundBlur</key>
<real>0.049349713962891201</real>
<key>BackgroundColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGKyxYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKcHCBMZHSQoVSRudWxs1QkKCwwNDg8QERJcTlNDb21wb25lbnRzVU5TUkdCXE5T