Recently I have to clean up my .Net solution with a long list of projects. One of cleanup is to remove all obj
folders. It is very tedious doing it manually.
I turn to Powershell Script to find a quick way. Soon I got my solution, only two lines of codes and I could do in PS console interactively:
Here is the function:
$a = Get-ChildItem -Path H:MyRepository\Solution\ -Recurse | Where-Object {$_Name -Match '^obj$' }
$a | { rm -r $_.FullName }
Repeat the same steps to remove bin
folders.
Wednesday, August 20, 2014
PS: Remove folder recursively
Posted by D Chu at 2:24 PM 0 comments
Labels: PowerShell, Visual Studio Tips
Friday, May 09, 2014
TnDao: Chinese Version of TED
TED is my favorite web resources I watch for talks about new ideas and views, technical or none-technical topics. Actually, I was involved in its translation program as volunteer and I did some video subtitle translations when I found some excellent talks.
I knew there is Chinese TED, which is called as TEDToChina. This one has been very active. Most contents there are from English TED talks with Chinese translation. Many Chinese like this web resource to open to new ideas, concepts, and views. I have couple friends there based on strong interest in TED.
To my surprise, two days ago, I found another similar version of TED, totally in Chinese, from China. It is TnDao. It initially started in 2011 from Shanghai. Now it makes its great impact wave to Beijing. The most interesting thing of TnDao is that all the talks are concentrated on issues in China.
I watched some vedio presentations in past two days. I could not stop watching after starting one. They are really eye-open views about current China. Some make me excited, but a lots of them make my heart sad, and heavy. There are so many social issues like poor children, drags, and others. It is good to know that there are so many intellectual, talent and influential people from all levels in China realize those issues and they invest their time, efforts and money to deal with.
I just by-chance know about TnDao from Weibo, Chinese Twitter and Ximalaya, a voice based social network like internet radio. Web, internet and mobile apps are in big wave in China. There are so many people already using those technologies and services. I often talk to my English speaking friends and co-workers that now days Chinese is a very important language in social life with technology.
References
- TnDao, Chinese version of TED with truly Chinese topics.
- Ximalaya, Listen to what you want, anywhere and anytime, Internet Radio with huge contents of voices in Chinese.
Posted by D Chu at 2:01 PM 0 comments
Thursday, May 08, 2014
.Net var (C#) Almost Everywhere, One Exception
Starting from .Net 3.0, Microsoft introduced type var in C#, as a simply way to binding strongly type. This is a very convenient way to define variables. Basically, .Net will be smart enough to infer correctly data type. It makes code maintenance and update much easy and no need to change data type in case variable types changed. I like it very much and use var almost everywhere.
However, recently I found one case this var is not able to infer explicit data type. In the case of dynamic delegate, you have to use explicit delegate type:
var myDelegate = delegate(int valueA, int valueB) { return valueA + valueB; };
.Net cannot infer what delegate type is for myDelegate. You have to use the explicit delegate type in this case:
delegate int SumOfTwoValues(int v1, int v2);
SumOfTwoValues myDelegate = delegate(int valueA, int valueB) { return valueA + valueB; };
I found this interesting exception when I was sharing my knowledge about delegate with my co-worker.
Posted by D Chu at 10:05 AM 0 comments
Labels: .Net, C#, Visual Studio Tips
Tuesday, April 08, 2014
iOS 7 Training Course by Stanford University
Here is the description of the course:
Updated for iOS 7. Tools and APIs required to build application for the iPhone platform using the iOS SDK. Users interface designs for mobile devices and unique user interactions using multi-touch technologies. Objective-oreiented design using model-controller paradigm, memory management, Objective topics includes: objective-oriented database API, animation, multi-threading and performance considerations.
Prerequisites: C language and objective-orianted programming experience
Recommended: Programming Abstractions.
Offered by Stanford School of Engineering and released with Creative Commons BY-NC-SA licenses. If you have disability-related accessibility question, please email cs193p-accessibility@lists.stanford.edu.
Couse Outline
I. Couse Introduction, Overview of iOS, MVC Objective-C
II. Xcode 5
III. Objetive-C
IV. Foundation, Attributed Strings
V. View Controller Lifecycle
This course is on the top of Cources in iTunesU.
Today I finished the first course. I am going to update this blog with my progress.
Posted by D Chu at 10:14 PM 1 comments
Labels: iOS Training
Monday, April 07, 2014
PS Function: Convert Collection of PSObjects
PS Table-view is a very useful view to present collection of PSObjects. This works well with PSObejects with just simple and single value properties, such as name, age, telephone number etc. However, if there is any properties with collections, the layout may be too for for those long list of collection objects.
I find out a great way to convert collection of PSObjects with collections as its properties. It works very well to break collection of values as multiple lines in column so that the layout of table view is much tight and clean.
Here is the function:
#FileName: UtilCollection.ps1
#================================
#FUNCTION LISTINGS
#================================
Function ConvertPSObjectCollection {
<#
.SYNOPSIS
Gets a converted collection of PSObjects so that the converted
collection can be nicely displayed in table-view.
.DESCRIPTION
This function will convert a collection of PSObjects with
one or more array properties to a collection of PSObjects so
that the colleciton can be output to a nice and tight table view.
The input collection contains PSObjects with one or more array
property element. Normally array elements are too wide to be displayed
in a table-view. By converting collection, the returned colection
can be viewed nicely in table-view.
This function is based on SO solution http://stackoverflow.com/questions/22723954/powershell-autosize-and-specific-column-width
.PARAMETER CollectionPSObjects
Mandatory. Collection of PSObjects, PSObject have one or more
property of array data.
.INPUTS
Parameters above
.OUTPUTS
A collection of converted PSObjects with same prorperties
but array elements as rows in the collection so that the
collection can be nicely formated output to a table view.
.NOTES
Version: 1.0
Authors: David Chu
Creation Date: 10/04/2014
Purpose/Change: Initial function development
.EXAMPLE
$myCol = @(
(New-Object –TypeName PSObject –Prop @{'id'='01';'name'='a';'items'=@(1,2,3);'others'=@('SampleA1','SampleA2')}),
(New-Object –TypeName PSObject –Prop @{'id'=@('02a','02b');'name'='b';'items'=@(1,2,3);'others'=@('SampleB1','SampleB2','SampleB3','SampleB4','SampleB5')}),
(New-Object –TypeName PSObject –Prop @{'id'='03';'name'=@('c1','c2');'items'=@(1,2,3);'others'='SampleC'})
)
$myCol1 = ConvertPSObjectCollection $myCol
$myCol1 | FT ID,Name,Items,Others -AutoSize
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true)] $CollectionPSObjects
)
Process {
$m_result = $CollectionPSObjects | %{
$Current = $_
$Members = $_|GM|?{$_.MemberType -match "Property"}| `
Select -ExpandProperty Name
$Rows = ($Members|%{$current.$_.count}| `
sort -Descending|Select -First 1)-1
For($i=0; $i -le $Rows;$i++){
$LoopObject = New-Object PSObject -Property `
@{$($Members[0]) = if($Current.$($Members[0]).count -gt 1) { `
$Current.$($Members[0])[$i] `
} else{ `
if(!($i -gt 0)){ `
$Current.$($Members[0]) `
}else{ `
$Null `
} `
} `
}
If($Members.Count -gt 1){
$Members[1..$Members.count]|%{
Add-Member -InputObject $LoopObject `
-MemberType NoteProperty `
-Name $_ `
-Value $(if($Current.$_.count -gt 1) { `
$Current.$_[$i] `
}else { `
if(!($i -gt 0)) { `
$Current.$_ `
}else{ `
$Null `
} `
} `
)
}
}
$LoopObject
}
}
return $m_result
}
}
References
- SO Question: Autosize and Specific Column Width
Posted by D Chu at 3:13 PM 0 comments
Labels: PowerShell
Wednesday, April 02, 2014
Three Shortcuts of PowerShell Script
Recently I have been writing PS codes at work. PS is a really good and powerful script language in Windows environment. I have never learned it systematically or from basic concept to advanced level. Based on my other programming skills, I just pick it and use it at work. In most cases, I just do the internet search for solutions if I don't have clue how to resolve my problems. Therefore, I have been on and off depending on my work requirements.
Still I don't know some very basic concepts. Here are three most commonalty used code cases:
%{....}
@{....}
?{....}
I just use them based on other people's codes. For these three shortcuts, I have trouble to google explanations. Finally, last week, I got an answer from SO.
%{...}: ForEach{}
@{...}: Constructor for hash table
?{...}: shortcut for Where {....}
References
- SO comment discussion on Francis Padron's quetsion.
Posted by D Chu at 8:53 PM 0 comments
Labels: PowerShell