Skip to content

Instantly share code, notes, and snippets.

@changbowen
changbowen / docker cheatsheet
Created April 26, 2019 07:03
docker cheatsheet
# testing
docker run -it --rm busybox sh
@changbowen
changbowen / wipe_disk_and_check_bad_sectors.sh
Last active May 27, 2019 09:02
Wipe disk and check bad sectors
# check physical and logical sector size
lsblk -o Name,PHY-SEC,LOG-SEC
# wipe disk
sudo shred -v -n1 -z /dev/sdx
# check bad sectors (readonly)
sudo badblocks -vs -b 4096 -c 65536 /dev/sdx
# check bad sectors and wipe disk
function ipChangeHandler {
Write-Host "Detected an IP change..."
Write-Host "Collecting connections information..."
$connObjs = New-Object System.Collections.ArrayList
$ints = Get-NetIPAddress -AddressFamily IPv4 -PrefixOrigin Dhcp -AddressState Preferred
foreach ($int in $ints) {
$_alias = $int.InterfaceAlias
$_index = $int.InterfaceIndex
$_ipaddr = $int.IPAddress
$intCfg = $int | Get-NetIPConfiguration
public static class NativeMethods
{
[DllImport("user32.dll")]
private static extern bool EnumDisplayMonitors(IntPtr hdc, IntPtr lprcClip, MonitorEnumDelegate lpfnEnum, IntPtr dwData);
private delegate bool MonitorEnumDelegate(IntPtr hMonitor, IntPtr hdcMonitor, ref Rect2 lprcMonitor, IntPtr dwData);
[DllImport("user32.dll")]
private static extern bool GetMonitorInfo(IntPtr hwnd, ref MonitorInfo mInfo);
[DllImport("Shcore")]
@changbowen
changbowen / Python.xml
Last active August 5, 2019 07:22
Python live templates for PyCharm
<templateSet group="Python">
<template name="for" value="for $VAR$ in $ITERABLE$:&#10; $END$" description="Iterate (for ... in ...)" toReformat="false" toShortenFQNames="true">
<variable name="ITERABLE" expression="pyIterableVariable()" defaultValue="&quot;iterable&quot;" alwaysStopAt="true" />
<variable name="VAR" expression="collectionElementName(ITERABLE)" defaultValue="&quot;item&quot;" alwaysStopAt="true" />
<context>
<option name="Python" value="true" />
</context>
</template>
<template name="fori" value="for $INDEX$, $VAR$ in enumerate($ITERABLE$):&#10; $END$" description="Iterate (for ... in enumerate)" toReformat="false" toShortenFQNames="true">
<variable name="ITERABLE" expression="pyIterableVariable()" defaultValue="" alwaysStopAt="true" />
@changbowen
changbowen / get_cdp.py
Last active August 16, 2019 07:36
Getting CDP (Cisco Discovery Protocol) information via Python on specified list of ESXi hosts
#!/usr/bin/env python
import sys
import atexit
from pyVim.connect import SmartConnectNoSSL, Disconnect
import pyVmomi
from pyVmomi import vim
from typing import List, Dict, Union
from tabulate import tabulate
from getpass import getpass
@changbowen
changbowen / yaml.json
Last active September 11, 2019 07:42
VS Code Ansible snippets
{
"Insert new variable": {
"prefix": ": ",
"body": [
": \"{{ ${2:value} }}\"$0"
],
"description": "Insert new ansible variable"
},
"Insert conditional list": {
"prefix": "cond",
@changbowen
changbowen / DpiImage.cs
Last active September 18, 2019 06:49
WPF Image control that does not scale with system DPI
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace ZipImageViewer
{
public class DpiImage : Image
{
git checkout --orphan latest_branch # orphan omits all the history
git add * # if you want to include all files (respecting gitignore). Otherwise make other changes here.
git commit -am "commit message"
git branch -D master # delete master branch
git branch -m master # rename current branch to master
git push -f origin master
@changbowen
changbowen / Get-CDP.ps1
Last active March 13, 2020 09:22
Getting CDP (Cisco Discovery Protocol) information via PowerShell on specified list of ESXi hosts
<#
.SYNOPSIS
Get CDP information from one or more ESX hosts.
.PARAMETER VMHost
VMHost can be a list of the below entries:
- FQDN name of the host
- VMware.Vim.HostSystem (return type of 'Get-View -ViewType HostSystem')
- VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl (return type of 'Get-VMHost')