Skip to content

Instantly share code, notes, and snippets.

@syu5-gh
syu5-gh / AdjustDateTime.cs
Created February 22, 2016 15:43
Adjust date and time function using date header from HTTP response for NETMF.
private static bool AdjustDateTime()
{
try
{
var webReq = WebRequest.Create("http://time.windows.com");
webReq.Method = "HEAD";
var webResp = webReq.GetResponse();
Debug.Print("Begin Response.");
foreach (var key in webResp.Headers.AllKeys)
{
@syu5-gh
syu5-gh / get_powercfg.ps1
Last active February 5, 2022 23:49
Get Power Configuration #PowerShell Script #windows
<#
.SYNOPSIS
Get Power Configuration PowerShell Script
.EXAMPLES
get_powercfg.ps1
#>
# https://msdn.microsoft.com/en-us/library/dn622955%28v=vs.85%29.aspx
$subgroup = (Get-WmiObject -Namespace root\cimv2\power -Class win32_powersettingSubgroup)
$in_subgroup = (Get-WmiObject -Namespace root\cimv2\power -Class win32_powersettingInSubgroup)
@syu5-gh
syu5-gh / styles.less
Created July 24, 2015 06:00
My styles.less for #GitHub #Atom
atom-text-editor {
background:black;
color:white;
}
atom-text-editor .cursor {
color:#6e8;
}
.heading {
@syu5-gh
syu5-gh / gist:f03d242e639809dd67b3
Created June 7, 2015 06:58
I2C Read/Write Transaction for NETMF
int writeTransaction(byte[] data)
{
int tryCount = 0;
int writtenSize = 0;
while (writtenSize < data.Length && tryCount < MAX_TRY)
{
var dataForWrite = new byte[data.Length - writtenSize];
Array.Copy(data, writtenSize, dataForWrite, 0, data.Length - writtenSize);
var i2ctx = new I2CDevice.I2CTransaction[] {
I2CDevice.CreateWriteTransaction(dataForWrite),
@syu5-gh
syu5-gh / gist:7bc0ad670df71522eda8
Created March 19, 2015 05:35
Zero clear whole unused space.
dd if=/dev/zero of=zero bs=4k; \rm zero
@syu5-gh
syu5-gh / FormattedOutputDebugString.cpp
Created February 9, 2015 02:41
Formatted OutputDebugString (Windows, Win32)
void DebugOut(wchar_t *fmt, ...)
{
va_list argp;
va_start(argp, fmt);
wchar_t dbg_out[4096];
vswprintf_s(dbg_out, fmt, argp);
va_end(argp);
OutputDebugString(dbg_out);
}
@syu5-gh
syu5-gh / gist:aee1bb7b11b06b38fa37
Created January 14, 2015 02:16
HOW TO: Obtain COM Apartment state (STA or MTA) in Windows PowerShell
>powershell -mta
Windows PowerShell
Copyright (C) 2014 Microsoft Corporation. All rights reserved.
PS > [system.threading.thread]::CurrentThread
ManagedThreadId : 7
ExecutionContext : System.Threading.ExecutionContext
Priority : Normal
@syu5-gh
syu5-gh / gist:9889651
Last active August 29, 2015 13:57
HOW TO : Retrieve authenticode information with PowerShell.
$(Get-AuthenticodeSignature c:\windows\explorer.exe).SignerCertificate.Subject
# Output sample:
# CN=Microsoft Windows, O=Microsoft Corporation, L=Redmond, S=Washington, C=US
@syu5-gh
syu5-gh / gist:9889588
Last active August 29, 2015 13:57
HOW TO : Compare to .exe or .dll file version embedded as the version resource with PowerShell.
function Compare-FileVersion {
param($path, $version_str)
$ver_info = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($path)
if ($ver_info.FileVersion -eq $version_str) {
return $True
}
return $False
}
@syu5-gh
syu5-gh / gist:9889572
Last active August 29, 2015 13:57
HOW TO : Make sure whether 2 binary files are same or not with PowerShell 4.
function IsEqualBinFile {
param($src, $dst)
$src_hash = Get-FileHash $src
$dst_hash = Get-FileHash $dst
if ($src_hash.Hash -eq $dst_hash.Hash) {
return $True
}
return $False
}