yicone
yicone
Reputation Top 1%
Yicone Wong
12 Snippets
Published
0 Channels
Created
1 Channel
Following
294 points
Reputation
Top 10% Publisher
Junior Code Generator
Serious Code Generator
Junior Publisher
Serious Publisher
Junior Popular Coder
Serious Popular Coder
Senior Popular Coder
Junior Autobiographer
Serious Autobiographer
Senior Autobiographer
Junior Snip2Coder
Senior Famous Coder
Junior Wise Coder

Recent Snippets See all snippets by yicone

public by  4265  0  4  0

immutable-atomic-value-types

http://www.tracefact.net/csharp-programming/immutable-atomic-value-types.aspx 1、当创建类型的目的是为了存储一组相关的数据,且数据量不是很大的时候,将它声明为Struct比Class会获得更高的效率;2、将类型声明为具有原子性和常量性,可以避免可能出现的数据不一致问题;3、通过在构造函数和Get访问器中,对对象的字段进行深度复制,可以避免在类型的外部修改类型内部数据的问题。: immutable-atomic-value-types.cs
void Main()
{
  string [] phones = { "18668866886", "18612341234" };
	Foo foo = new Foo(phones);
	
	Console.WriteLine(foo.Phones[0]);
	
	phones[0] = "xxx";
	Console.WriteLine(foo.Phones[0]);
	
	foo.Phones[0] = "xxx";
	Console.WriteLine(foo.Phones[0]);
}

// Define other methods and classes here
public class Foo 
{
	private readonly string[] _phones;
	
	public string[] Phones { get{
		var copy = new string[_phones.Length];
		_phones.CopyTo(copy, 0);
		return copy;
	}}
	
	public Foo(string[] phones)
	{
		var copy = new string[phones.Length];
		phones.CopyTo(copy, 0);
		_phones = copy;
	}
}

                        
;

public by yicone  3129  0  4  0

Old Old autoSetFrameHeight

Old Old autoSetFrameHeight: autoSetFrameHeight.js
function autoSetFrameHeight(name) {
    try {
        var iframe;
        if (!name) return;
        iframe = document.getElementById(name);
        if (iframe.contentDocument)
            $("#" + name).height(iframe.contentDocument.height + "px");
        else
            $("#" + name).height(document.frames[name].document.body.scrollHeight + "px");
    } catch (e) {
        // alert(e.message);
    }
}

;

public by yicone  2787  0  4  0

cookie operation js, but have a error about cookie path(I'm not sure).

cookie operation js, but have a error about cookie path(I'm not sure).: cookie-no-jquery.js
// http://www.w3schools.com/js/js_cookies.asp?output=print
function setCookie(c_name, value, exdays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString()) + ';path="/"';
    document.cookie = c_name + "=" + c_value;
}

function getCookie(c_name) {
    var i, x, y, ARRcookies = document.cookie.split(";");
    for (i = 0; i < ARRcookies.length; i++) {
        x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
        y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
        x = x.replace(/^\s+|\s+$/g, "");
        if (x == c_name) {
            return unescape(y);
        }
    }
}

;

public by yicone  3251  1  4  0

load jQuery from Sina CDN

load jQuery from Sina CDN: gistfile1.js
<script type="text/javascript" src="//lib.sinaapp.com/js/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript">        window.jQuery || document.write('<script type="text/javascript" src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")">\x3C/script>')</script>

;

public by yicone  2865  0  4  0

My first code use MonoDevelop edit, for checking error code used situation in a project.

My first code use MonoDevelop edit, for checking error code used situation in a project.: gistfile1.cs
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Xml.Linq;

namespace CheckUnusedErrorCode
{
  class MainClass
	{
		public static void Main (string[] args)
		{
			var allCodes = GetAllErrorCodes ();

			var fileNames = Directory.GetFiles ("EclipseProjectFolder", "*.java", SearchOption.AllDirectories);

			foreach (var code in allCodes) {
				bool found = false;
				foreach (var fileName in fileNames) {
					int counter = 0;
					string line;

					using (StreamReader sr = new StreamReader(fileName)) {
						while ((line = sr.ReadLine()) != null) {
							if (line.Contains (code)) {
								found = true;
								Console.WriteLine (counter.ToString () + ": " + line);
							}
						
							counter++;
						}
					}
				}

				if (!found) {
					Console.WriteLine (string.Format ("Code: {0} not found!", code));
				}
			}

			Console.Read ();
		}

		private  static List<string> GetAllErrorCodes ()
		{
			XElement root = XElement.Load ("ErrorCodes.xml");

			System.Diagnostics.Debug.Assert (root != null);
			
			var query = from e in root.Elements ()
				select e.Attribute ("Code").Value;

			return query.ToList ();
		}
	}
}


;