Skip to content

Instantly share code, notes, and snippets.

View tkmtmkt's full-sized avatar

Takamatsu Makoto tkmtmkt

View GitHub Profile
@tkmtmkt
tkmtmkt / gist:2326853
Created April 7, 2012 09:37
Create Command Template with Credential
Get-Credential | %{
$user = $_.UserName
$pass = ConvertFrom-SecureString $_.Password
@"
<#
.SYNOPSIS
command with credential
#>
`$user = "$user"
@tkmtmkt
tkmtmkt / gist:2327972
Created April 7, 2012 11:42
Network Adapter Setting
$config = @"
"COMPUTER","IPAddress","Subnetmask","Gateway"
"ORANGE","192.168.0.6","255.255.255.0","192.168.0.1"
"BROWN", "192.168.0.7","255.255.255.0","192.168.0.1"
"@ | ConvertFrom-Csv | ?{$_.COMPUTER -eq $Env:COMPUTERNAME}
gwmi Win32_NetworkAdapterConfiguration | ?{$_.IPEnabled -eq $true -and $_.Description -match "WiFi"} | %{
$_.EnableDHCP()
$_.EnableStatic($config.IPAddress, $config.Subnetmask)
$_.SetGateways($config.Gateway,1)
@tkmtmkt
tkmtmkt / CollectVersionInfo.ps1
Created April 25, 2012 16:00
Jobを使って計算機のバージョン情報を収集するサンプル
<#
.SYNOPSIS
ソフトウェアのバージョン情報を収集する
#>
$ps1_file = &{$myInvocation.ScriptName}
$base_dir = Split-Path (Split-Path $ps1_file)
$log_dir = "$base_dir\log"
$log_file = "$log_dir\$((Split-Path -Leaf $ps1_file).Replace(".ps1",".log"))"
if (-not (Test-Path "$log_dir")) {New-Item "$log_dir" -Force -ItemType Directory}
@tkmtmkt
tkmtmkt / capture.ps1
Created May 27, 2012 14:01
クリップボード内の画像をファイルに保存する
<#
.SYNOPSIS
クリップボート内の画像をファイルに出力します。
#>
Function cap
{
powershell -sta -command {
Add-Type -AssemblyName System.Windows.Forms
$cb = [Windows.Forms.Clipboard]
$img = $cb::GetImage()
@tkmtmkt
tkmtmkt / Build.scala
Created June 5, 2012 14:05
sbtのディレクトリ構成をカスタマイズする設定を試してみた
import sbt._
import Keys._
object TestBuild extends Build {
lazy val root: Project = Project("root", file("."), aggregate = nonRoots)
lazy val nonRoots = projects.filter(_ != root).map(p => LocalProject(p.id))
lazy val sub1 = consoleProject("sub1", file("sub1"))
lazy val sub2 = webProject("sub2", file("sub2"))
@tkmtmkt
tkmtmkt / gist:2948484
Created June 18, 2012 13:55
ディスプレイモニタの情報を取得/表示する
gwmi -Namespace root\wmi WmiMonitorID | %{
New-Object PSObject -Property @{
ManufacturerName = -join ($_.ManufacturerName | %{[char]$_})
ProductCodeID = -join ($_.ProductCodeID | %{[char]$_})
SerialNumberID = -join ($_.SerialNumberID | %{[char]$_})
UserFriendlyName = -join ($_.UserFriendlyName | %{[char]$_})
WeekOfManufacture = $_.WeekOfManufacture
YearOfManufacture = $_.YearOfManufacture
}
}
@tkmtmkt
tkmtmkt / build.sbt
Created August 4, 2012 04:54
標準のディレクトリ構成を変更するscala設定ファイル(Basic)
name := "My Project"
version := "0.1-SNAPSHOT"
organization := "home"
unmanagedBase <<= baseDirectory / "lib"
sourceDirectory in Test <<= baseDirectory / "test"
@tkmtmkt
tkmtmkt / Build.scala
Created August 4, 2012 04:57
標準のディレクトリ構成を変更するscala設定ファイル(Full:マルチプロジェクト)
import sbt._
import Keys._
object TestBuild extends Build {
lazy val root: Project = Project("root", file("."), aggregate = nonRoots)
lazy val nonRoots = projects.filter(_ != root).map(p => LocalProject(p.id))
lazy val main = consoleProject("main", file("main")) dependsOn(sub1, sub2, sub3)
lazy val sub1 = webProject("sub1", file("sub1"))
@tkmtmkt
tkmtmkt / gist:3837177
Created October 4, 2012 23:47
エポック秒の計算
(date "2012/10/04 22:00").Subtract((date "1970/01/01 09:00")).TotalSeconds
((date "2012/10/04 22:00") - (date "1970/01/01 09:00")).TotalSeconds
date (date "2012/10/04 22:00").ToUniversalTime() -u "%s"
date (date "2012/10/04 22:00").AddHours(-9) -u "%s"
(date "2012/10/04 22:00" -u "%s") - 9*60*60
@tkmtmkt
tkmtmkt / gist:4519239
Created January 12, 2013 16:57
Windowsの管理者権限の有無を判定する
function IsAdministrator {
[Security.Principal.WindowsPrincipal]$id = [Security.Principal.WindowsIdentity]::GetCurrent()
$id.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}