Skip to content

Instantly share code, notes, and snippets.

@breezhang
breezhang / binaryfromat.cs
Created February 13, 2012 07:39
C# string Fromat
int bitarray = Enumerable.Range(0, 0x100).Select(i => { var x = Convert.ToString((Byte)i, 2);
return new string('0',8-x.Length)+x;
}).Count(s => (s.IndexOf("1111") >= 0 || s.IndexOf("000") >= 0));
@breezhang
breezhang / gist:1817617
Created February 13, 2012 15:31
Enumerable Join some stuff
//need .net 4.0
var s1 = Enumerable.Range(1, 10).ToList().Select(i => new {name = i%7,sex =i,age= i*10});
var s2 = Enumerable.Range(1, 10).ToList().Select(i => new {name = i & 0xFE});
var result = s2.Join(s1, arg => arg.name, arg => arg.name, (a, b) => b).Distinct();
if(result.Any())
{
result.ToList().ForEach(obj => _show(obj.name + "/"+ obj.sex + "/" + obj.age));//+"/" + obj.b));
@breezhang
breezhang / command.cs
Created February 15, 2012 16:42
find has an interface class
//System.Reflection
public class Invoker
{
private readonly List<object> _mCommand;
private const BindingFlags Flags = BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance;
public Invoker()
@breezhang
breezhang / Httpheader.ps1
Created February 18, 2012 16:30
You can get Http header
$url="full name much better eg. http://www.google.com"
#$xhttp= New-Object -ComObject msxml2.xmlhttp
#$xhttp.open("get",$url,$false)
#$xhttp.send()
#$xhttp.responseText
#$xhttp.status
#$xhttp.getAllResponseHeaders()
#alse you can net.webclient
#$req =[net.httpwebrequest]::Create($url)
@breezhang
breezhang / logon.ps1
Created February 20, 2012 07:12
Last Logon Times (Vista .. win7)
#source="http://blogs.technet.com/b/heyscriptingguy/archive/2012/02/19/use-powershell-to-find-last-logon-times-for-virtual-#workstations.aspx?utm_source=twitterfeed&utm_medium=twitter"
$Computer = 'NJLT-Service'
$Win32OS = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Computer
$Build = $Win32OS.BuildNumber
#The “If ($Build -ge 6001)” is the first decision point.
#if the build number is 6001 and above, the script block will run.
if ($Build -ge 6001)
{
$Win32User = Get-WmiObject -Class Win32_UserProfile -ComputerName $Computer
@breezhang
breezhang / Get-HexDump.ps1
Created February 20, 2012 12:14
from twitters :)
function Get-HexDump($path,$width=10, $bytes=-1)
{
$OFS=""
Get-Content -Encoding byte $path -ReadCount $width `
-totalcount $bytes | Foreach-Object {
$byte = $_
$hex = $byte | Foreach-Object {
" " + ("{0:x}" -f $_).PadLeft(2,"0")}
$char = $byte | Foreach-Object {
if ([char]::IsLetterOrDigit($_))
@breezhang
breezhang / x.bat
Created February 22, 2012 10:35
if y get error Get-ExecutionPolicy : Invalid class try this script :)
from http://msmvps.com/blogs/lduncan/pages/20217.aspx
How Do I Rebuilt a Corrupt WMI Repository?
The following can be done through a batch file or executed manually from the command line:
net stop winmgmt
c:
cd %systemroot%\system32\wbem
rd /S /Q repository
@breezhang
breezhang / simply.pac
Created February 25, 2012 15:49
switch proxy for mainland china :)
/*you need file */
/*
You can visit http://autoproxy2pac.appspot.com/
download http://autoproxy2pac.appspot.com/gfwtest.js append some stuff
e.g
@breezhang
breezhang / SetStaticIP.ps1
Created February 28, 2012 08:41
set DNS just ipv4
#Summary: Microsoft Scripting Guy, Ed Wilson,
#talks about using Windows PowerShell to set the static IP and DNS addresses on a server.
#Microsoft Scripting Guy, Ed Wilson, is here.
#One of the really cool things about computers is that you never get bored.
#At least for me this is true.
#for example, I have a server that has been running Exchange Server
#absolutely perfectly for more than a year.
#Today, it acted like a 150 pound St. Bernard that had become bored.
#That’s right, it threw a fit. Why did it do so? Well, I had changed the IP network configuration,
#and I did not change the IP address on this machine. for some reason,
I have no idea add some comm for MSDN
Worker remoteWorker = (Worker) ad.CreateInstanceAndUnwrap(
Assembly.GetExecutingAssembly().FullName,
"Worker"); issue==> typeof(Worker).FullNam