Skip to content

Instantly share code, notes, and snippets.

@r-plus
r-plus / gist:52f81f0afdbba79365b6102d4bec4e1d
Created October 29, 2016 08:32
How to check CPU on mac.
$ sysctl -n machdep.cpu.brand_string
Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz
@r-plus
r-plus / innerShadow.swift
Created January 30, 2016 09:32
inner shadow
import UIKit
import XCPlayground
extension UIView {
public func addInnerShadow(topColor: UIColor = UIColor.blackColor().colorWithAlphaComponent(0.3)) {
let shadowLayer = CAGradientLayer()
shadowLayer.cornerRadius = layer.cornerRadius
shadowLayer.frame = bounds
shadowLayer.frame.size.height = 10.0
shadowLayer.colors = [
@r-plus
r-plus / filter_first_instead_way.swift
Created January 20, 2016 18:02
faster getting way than filter+first.
import CoreFoundation
extension Array {
func firstMatchFilter<T: Equatable>(target: T) -> Element? {
let start = CFAbsoluteTimeGetCurrent()
guard let index = self.indexOf({ $0 as! T == target }) else {
return nil
}
let end = CFAbsoluteTimeGetCurrent()
print("elapsed time = \(end - start)")
@r-plus
r-plus / zabbix_graph_save.ps1
Created November 13, 2015 01:03
Zabbix graph save powershell script.
# Zabbix graph save script.
# Required PowerShell v3.0 or later.
# variables.
$zabbixURL = "http://192.168.0.10/zabbix/"
$zabbixAPIURL = $zabbixURL + "api_jsonrpc.php"
$zabbixGraphURL = $zabbixURL + "chart2.php?graphid="
$baseJSON = @{ "jsonrpc" = "2.0"; "id" = 1 }
# Get login token.
@r-plus
r-plus / frequent_commands.ps1
Created September 9, 2015 01:37
note for future use.
# よく使うやつ。主にStartTime見る用
Get-Process -Name 'winlogon' | Format-Table -AutoSize -Property Name, StartTime, Id, PM, VM, WS
# Service. StartModeが取れないダメCmdlet。そっちが目的ならGet-WmiObject
Get-Service | format-table -Autosize -Property DisplayName, Name, Status
# Get-ServiceでPIDが取れないのでWMIを使わざるを得ない。大体タスクマネージャーから確認した方が早い。
Get-Process -Id (Get-WmiObject -Query "select * from win32_service where name='wuauserv'").ProcessId | Format-Table Name, StartTime
@r-plus
r-plus / ro.ps1
Last active August 29, 2015 14:22
Add everyone read-only ACE to target path.
# Add everyone read-only ACE to target path.
# Doc: https://technet.microsoft.com/en-us/library/ff730951.aspx
function Add-ReadOnlyACE([string]$path)
{
if (-not (Test-Path $path)) { return }
# Create additionnal ACE.
$colRights = [System.Security.AccessControl.FileSystemRights]"AppendData, ChangePermissions, CreateDirectories, CreateFiles, Delete, DeleteSubdirectoriesAndFiles, Write"
$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]"ContainerInherit, ObjectInherit"
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None
@r-plus
r-plus / vfp_used_size.ps1
Last active August 29, 2015 14:22
Script to get HVFP filesystem used size via http api.
# Script to get HVFP filesystem used size via http api.
# API Refference: http://itdoc.hitachi.co.jp/Pages/document_list/manuals/vfp.html
$filesystem = "FS01"
# [System.Web.HttpUtility] for japanese UrlEncode if necessary.
#[void]([Reflection.Assembly]::LoadWithPartialName("System.Web"))
# Ignore warning about self signed SSL cert.
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
@r-plus
r-plus / GetSystemSettings.ps1
Last active August 29, 2015 14:16
Get general settings of Windows for individual test.
# This script required administrator permission.
# Disk, Partition and Firewall getting cmdlet require 2012 or later.
$LOG = "C:\$(hostname)_OS_Test_$((Get-Date -Format d).Replace('/','')).log"
function EchoTitle($title)
{
echo ""
echo "******************** ${title} ********************"
echo ""
@r-plus
r-plus / Cacti_Template_DNS_WMI.xml
Last active August 29, 2015 14:14
Cacti templace - DNS received query request/sec for Windows via WMI
<cacti>
<hash_0000247a26072efb1c6c5b9358fa308220a69a>
<name>Windows - DNS(WMI)</name>
<graph>
<t_title>on</t_title>
<title>|host_description| - DNS</title>
<t_image_format_id></t_image_format_id>
<image_format_id>1</image_format_id>
<t_height></t_height>
<height>120</height>
@r-plus
r-plus / SQL_DB_Size.py
Created February 2, 2015 09:39
Get SQL Server space usage data for cacti monotoring via WinRM.
#!/usr/bin/env python
import winrm
import sys
import getopt
import json
# set default
host = "localhost"
credencial_file = "/etc/cacti/cactiwinrm.json"