2012년 12월 13일 목요일
2012년 9월 26일 수요일
웹 파일 유무 체크
public static bool WebExists(string url)
{
bool ret = true;
if (url == null)
return false;
HttpWebResponse response = null;
try
{
var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "HEAD";
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException)
{
ret = false;
}
finally
{
if (response != null)
{
response.Close();
}
}
return ret;
}
2012년 8월 15일 수요일
Implementing Set in javascript
var Set = function () { }
Set.prototype.size = function () { var cnt = 0; for (obj in this) { if (typeof this[obj] != 'function') cnt++ } return cnt; }
Set.prototype.add = function (o) { this[o] = true; }
Set.prototype.remove = function (o) { if (this[o]) { delete this[o]; } }
Set.prototype.clear = function () { for (obj in this) { if (this[obj]) delete this[obj]; } }
2012년 8월 9일 목요일
Fit image with css
<img src="" style="width:400px; height: 400px; max-height:100%; max-width:100%" >
2012년 6월 18일 월요일
Start Google Map with address
String address = ""; // Enter address hear
Uri uri = Uri.parse("geo:0,0?q=" + Uri.encode(address)); // if address has special character like '#', it should be encoded.
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
2012년 6월 14일 목요일
Android Connection Check
public boolean isConnected() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
return cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnectedOrConnecting();
}
AndroidManifest.xml <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
AndroidManifest.xml <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
2012년 6월 7일 목요일
Admob을 화면 밑에 ListView를 나머지 공간에 배치하기
<?xml version="1.0" encoding="utf-8">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.ads.AdView
ads:adSize="BANNER"
ads:adUnitId="MY_AD_UNIT_ID"
ads:loadAdOnCreate="true"
android:id="@+id/adView"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true" />
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/adView"/>
</RelativeLayout>
</RelativeLayout>
2012년 5월 22일 화요일
Import csv to MySQL
load data local infile 'contacts.csv' into table contacts fields terminated by ','
enclosed by '"'
lines terminated by '\n'
(name, phone, address)
2012년 5월 14일 월요일
Service routing
Global.asax
// Assign address [/api/project] for ProjectService class. protected void Application_Start(object sender, EventArgs e) { RouteTable.Routes.Add(new ServiceRoute("api/project", new WebServiceHostFactory(), typeof(ProjectService))); }
ProjectService.cs
[ServiceContract] AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class ProjectService {
// Assign address [/api/project/all] for GetAllProjects method
[OperationContract]
[WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json, UriTemplate = "all")]
public List GetAllProjects()
{
// code
}
}
// Assign address [/api/project] for ProjectService class. protected void Application_Start(object sender, EventArgs e) { RouteTable.Routes.Add(new ServiceRoute("api/project", new WebServiceHostFactory(), typeof(ProjectService))); }
ProjectService.cs
[ServiceContract] AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class ProjectService {
URL routing
Global.axas
// Assign address [/project] for [/Project.aspx] protected void Application_Start(object sender, EventArgs e) { RouteTable.Routes.MapPageRoute("", "project", "~/Project.aspx");
}
// Assign address [/project] for [/Project.aspx] protected void Application_Start(object sender, EventArgs e) {
2012년 4월 16일 월요일
2012년 3월 27일 화요일
로그인 유저와 DB 유저 연결하기 MS-SQL
Restore 데이터베이스를 했을 때 DB 유저와 Login 유저가
일치하지 않는 경우가 생긴다.
이를 해결하는 procedure가 sp_change_users_login
로그인 유저 네임이 없을 경우에는 null로 지정하면
DB 유저 네임과 같게 새로 생성해 준다
EXEC sp_change_users_login 'Auto_Fix', '[DB Username]', '[Login Username]', '[Password]';
2012년 3월 23일 금요일
Credit Card Number Rule
Visa: "4###############"
Mastercard: "<51..55>#############"
American Express: "<34|37>#############"
Discover: "6011############"
JCB: "<3|1800|2131>##############"
Diners Club: "<300|301|302|303|304|305|36|38>############"
2012년 3월 21일 수요일
Javascript Object 내용 표시하기
function concatObject(obj) {
str='';
for(prop in obj)
{
str+=prop + " value :"+ obj[prop]+"\n";
}
return(str);
}
2012년 2월 23일 목요일
Get Version in Silverlight
Plug in version
Environment.Version
XAP file viersion Assembly assembly = Assembly.GetExecutingAssembly(); if (assembly.FullName != null) { string versionPart = assembly.FullName.Split(',')[1];
string version = versionPart.Split('=')[1];
}
XAP file viersion Assembly assembly = Assembly.GetExecutingAssembly(); if (assembly.FullName != null) {
2012년 2월 3일 금요일
Convert Javascript Date to JSON string for .Net DateTime
var offset = new Date().getTimezoneOffset() / 60;
if (offset <= -10)
offset = '+' + Math.abs(offset) + '00';
else if (offset > -10 && offset < 0)
offset = '+0' + Math.abs(offset) + '00';
else if (offset == 0)
offset = '';
else if (offset > 0 && offset < 10)
offset = '-0' + offset + '00';
else if (offset >= 10)
offset = '-' + offset + '00';
var d = '\/Date(' + (new Date().getTime()) + offset + ')\/';
2012년 2월 2일 목요일
Copy a column in VBA
Sheets("src").Range("A4", Range("A4").End(xlDown)).Copy _
Destination:=Sheets("dest").Range("A2")
src: worksheet name of source dest: worsheet name of detination A2: a cell to perform copy
src: worksheet name of source dest: worsheet name of detination A2: a cell to perform copy
Select a column in VBA
Range("A4", Range("A4").End(xlDown).Selectz
A4 can be replaced with starting cell
A4 can be replaced with starting cell
2012년 1월 25일 수요일
Get comma separated string from List
List<string> ids;
string cids = string.Join(",", ids.ToArray());
2012년 1월 18일 수요일
Select hierarchical data
with h(id, name, parent, level) as
(
select id, name, parent, 0 as level
from task
where id = 48358
union all
select t.id, t.name, t.parent, t2.level + 1
from task t
inner join h t2 on t.parent = t2.id
)
select * from h;
2012년 1월 6일 금요일
2012년 1월 5일 목요일
Image convert in c#
Image imgInFile = Image.FromFile(inFileName);
imgInFile.Save(outFileName, ImageFormat.Jpeg);
2012년 1월 3일 화요일
IEnumerable to ObserverbleCollection
IEnumerable<Object> ienumerable;
ObserverbleCollection<Object> observableCollection = new ObservableCollection<Object>(ienumerable);
피드 구독하기:
글 (Atom)