Skip to content

Instantly share code, notes, and snippets.

@froop
froop / TestDnsQuotaByInetAddress.java
Last active March 26, 2022 07:41
[AWS][EC2][Java] AWSのDNSクォータをテスト
// Command: java -Dsun.net.inetaddr.ttl=0 TestDnsQuotaByInetAddress 172.30.3.11
// Metric: ethtool -S eth0 | grep linklocal_allowance_exceeded
public class TestDnsQuotaByInetAddress {
private static final int TRIALS = 10_000;
private static final int THREADS = 1_024;
private static final int LOG_THRESHOLD = 1_000;
public static void main(String[] args) throws InterruptedException, ExecutionException {
final String host = args[0];
final ExecutorService executor = Executors.newFixedThreadPool(THREADS);
@froop
froop / InstallHinemosAgent.ps1
Last active August 3, 2022 10:36
[Windows] Install Hinemos Agent
Param($Major='6.2', $Minor='2', $Manager='172.30.3.10')
$PackageZip = "hinemos-agent-${Major}.${Minor}-1.win.zip"
$DownloadUrl = "https://github.com/hinemos/hinemos/releases/download/v${Major}.${Minor}/${PackageZip}"
$PackageMsi = "C:\HinemosAgentInstaller-${Major}.${Minor}_win.msi"
$InstallPath = "C:\Program Files (x86)\Hinemos\Agent${Major}.${Minor}"
$ServiceName = "Hinemos_${Major}_Agent"
(New-Object System.Net.WebClient).DownloadFile(${DownloadUrl}, "C:\${PackageZip}")
Expand-Archive -Path "C:\${PackageZip}" -DestinationPath "C:\"
@froop
froop / TestRaceConditionOfArrayList.java
Last active February 22, 2022 11:41
[Java] ArrayListを複数スレッドから使用した場合に発生する競合のテスト
public class TestRaceConditionOfArrayList {
private static final int NUMBER_OF_TRIALS = 1_000_000;
private static final int NUMBER_OF_THREADS = 8;
private static final List<Integer> SOURCE_LIST = Arrays.asList(1, 2);
public static void main(String[] args) throws InterruptedException, ExecutionException {
ExecutorService executor = Executors.newFixedThreadPool(NUMBER_OF_THREADS);
List<Future<String>> futures = new ArrayList<>();
Testee testee = new Testee();
for (int i = 0; i < NUMBER_OF_TRIALS; i++) {
@froop
froop / InstallSnmp.ps1
Created February 5, 2022 08:14
[Windows] Install SNMP Service
Install-WindowsFeature SNMP-Service -IncludeAllSubFeature -IncludeManagementTools
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\SNMP\Parameters\ValidCommunities" -Name "public" -Value 4 -type DWord
Remove-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Services\SNMP\Parameters\PermittedManagers"
#Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\SNMP\Parameters\PermittedManagers" -Name "1" -Value "localhost" -type String
#Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\SNMP\Parameters\PermittedManagers" -Name "2" -Value "172.30.3.10" -type String
Restart-Service -Name SNMP
New-NetFirewallRule -DisplayName "SNMP Service" -Direction Inbound -Protocol UDP -LocalPort 161 -Action Allow
@froop
froop / InstallJava8Oracle.ps1
Last active August 3, 2022 10:56
[Windows] Insatall Oracle Java 8
$URL = "https://javadl.oracle.com/webapps/download/AutoDL?BundleId=246808_424b9da4b48848379167015dcc250d8d" # 8u341
#$URL = "https://javadl.oracle.com/webapps/download/AutoDL?BundleId=246474_2dee051a5d0647d5be72a7c0abff270e" # 8u333
#$URL = "https://javadl.oracle.com/webapps/download/AutoDL?BundleId=245807_df5ad55fdd604472a86a45a217032c7d" # 8u321
#$URL = "https://javadl.oracle.com/webapps/download/AutoDL?BundleId=245479_4d5417147a92418ea8b615e228bb6935" # 8u311
(New-Object System.Net.WebClient).DownloadFile($URL, "C:\jre8.exe")
cmd /C "C:\jre8.exe" /s
[System.Environment]::SetEnvironmentVariable("JAVA_HOME", "C:\Program Files\Java\jre1.8.0_341", "Machine")
Remove-Item "C:\jre8.exe"
@froop
froop / regex-sample.py
Created December 26, 2021 06:51
[Python] 正規表現サンプル
import re
with open('/content/drive/MyDrive/input.tsv') as file:
for line in file:
res = re.match('^([^\t]+)\t([^\t]+)\t.{3}([^\t]+)\t([^\t]+)$', line)
print('%s\t%s\t%s' % (res.group(2), res.group(4), bytes.fromhex(res.group(3))))
@froop
froop / ec2-launch-template.bat
Last active November 29, 2021 22:18
[AWS][Windows] Launch EC2 instance from template
set /P TEMPLATE_ID=Template ID:
aws ec2 run-instances ^
--launch-template LaunchTemplateId=%TEMPLATE_ID% ^
> ec2-run-instance.log
REM change instance type: --instance-type t3.nano ^
aws ec2 describe-instances ^
--filters ^
"Name=tag:aws:ec2launchtemplate:id,Values=%TEMPLATE_ID%" ^
@froop
froop / cloud-config.yml
Last active December 23, 2021 23:17
[Linux][EC2] CentOS 7環境構築
#cloud-config
timezone: Asia/Tokyo
runcmd:
- cd /home/centos
- curl -L -o init-os.sh https://gist.github.com/froop/224549dad2a39c584b571ee16ca66142/raw/init-centos7-ec2.sh
- chmod +x init-os.sh
- ./init-os.sh
- rm init-os.sh
@froop
froop / configure-docker-centos7.sh
Last active December 23, 2021 23:17
[Linux] CentOS 7 + Docker
#!/bin/bash -eu
# locale
localectl set-locale LANG=ja_JP.UTF-8
# timezone
echo 'ZONE="Asia/Tokyo"' > /etc/sysconfig/clock
rm -f /etc/localtime
ln -fs /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
@froop
froop / httplib.py
Created September 25, 2021 20:23
[Python] HTTP GET minimum (Python 2.7)
import httplib
con = httplib.HTTPConnection('172.31.1.12', 80)
con.request('GET', '/')
res = con.getresponse()
print(res.status)