Objective C 使用CCFollow设置cocos2D摄像机位置

-(void)setPlayerPosition:(CGPoint)position {
	CGPoint tileCoord = [self tileCoordForPosition:position];
	int tileGid = [_meta tileGIDAt:tileCoord];
	if (tileGid) {
		NSDictionary *properties = [_tileMap propertiesForGID:tileGid];
		if (properties) {
			NSString *collision = [properties valueForKey:@"Collidable"];
			if (collision && [collision compare:@"True"] == NSOrderedSame) {
				return;
			}
			NSString *collectable = [properties valueForKey:@"Collectable"];
			if (collectable && [collectable compare:@"True"] == NSOrderedSame) {
				[_meta removeTileAt:tileCoord];
				[_foreground removeTileAt:tileCoord];
				self.numCollected++;
				[_hud numCollectedChanged:_numCollected];
			}
		}
	}
	
	ccTime moveDuration = 0.3;
	id playerMove = [CCMoveTo actionWithDuration:moveDuration position:position];
	id cameraMove = [CCFollow actionWithTarget:_player worldBoundary:CGRectMake(0, 0, (_tileMap.mapSize.width * _tileMap.tileSize.width), (_tileMap.mapSize.height * _tileMap.mapSize.height))];
	[_player runAction:playerMove];
	
	[self runAction:cameraMove];
	
}

C# C#通用类型转换

public class GenericConverter
{
    public static T Parse<T>(string sourceValue) where T : IConvertible
    {
      return (T)Convert.ChangeType(sourceValue, typeof(T));
    }

    public static T Parse<T>(string sourceValue, IFormatProvider provider) where T : IConvertible
    {
      return (T)Convert.ChangeType(sourceValue, typeof(T), provider);
    }
}

C# SQL输出参数

using System.Data;
using System.Data.SqlClient;

if (sqlConn.State == System.Data.ConnectionState.Closed)
    _sqlConn.Conn;

bool suc = false;

SqlCommand insertRow = new SqlCommand(_command, _connString);
insertRow.CommandType = System.Data.CommandType.StoredProcedure;

SqlParameter para = new SqlParameters("@DONE". SqlDbType.Bit);
paraDone.Direction = ParameterDirection.Output;

insertRow.Parameters.AddWithValue("Number", no);
insertRow.Parameters.Add(para);
insertRow.ExecuteNonQuery();

suc = (bool)para.Value;

C# 检查流程实例

using System.Diagnostics;

if (Process.Getprocessbyname(Process.Getcurrentprocess().ProcessName).Length >1)
{
    MessageBox.show("Another instance of this process is already running");
    Application.Exit();
}

C# 检查上行链接

public void CheckUplink(string ip)
{
    Ping pingSender = new Ping();
    PingOptions options = new PingOptions();
    options.DontFragment = true;
    string data = "test";
    byte[] buffer = Encoding.ASCII.GetBytes(data);
    //timeout before trigger
    int timeout = 120;
    PingReply reply = pingSender.Send(ip, timeout, buffer, options);
    if (reply.Status == IPStatus.Success)
    {
        //upon success
    }
    else
    {
        //upon failure
    }
}

C# 计算总文件大小

public int CalculateTotalFileSize(string[] path)
{
    int sumFileSize = 0;
    foreach(string onePath in path)
    {
        FileInfo info = new FileInfo(onePath);
        sumFileSize += Convert.ToInt32(info.Length);
    }
    return sumFileSize;
}

SQL 为字符串生成HASH值

select 'HELLO1', dbms_utility.get_hash_value('HELLO6',5,1232312) from dual;

SQL 仅从日期时间选择日期部分

SELECT CONVERT(VARCHAR(10),GETDATE(),111)

C# WinForms启动可以访问GUI的线程

using System.Threading;

private void btnStart_Click(object sender, EventArgs e)
{
    Thread t = new Thread(new ThreadStart(this.AsyncGetResults));
    t.Start();
}

private void AsyncGetResults()
{

    // Do some not-GUI-touching stuff 
    // ...

    // So some GUI-touching stuff
    if (panellWait.InvokeRequired)
    {
        panelWait.Invoke(new MethodInvoker(delegate
        {
            panelWait.Visible = true;
        }));
    }

    // Do some other not-GUI-touching stuff 
    // ...
}

C# WCF使用扩展方法

        /// <summary>
        /// When calling a WCF service it is not possible to use a using(...) statement to close 
        /// the connection after the service call.  A call to Dispose may cause an exception
        /// which is against MS recommendation. As such when calling a WCF Service you can 
        /// us the Using method to correctly close the connection after your request or requests.
        /// 
        /// <remarks>This can be used with the following code <br/>
        /// <code>
        /// IMyService service = new MyService(); // Gets a proxy to WCF service
        /// service.Using(()=>
        /// {
        ///     service.DoSomthing();
        ///     service.DoSomethingElse("Hello World");
        ///     Console.WriteLine();
        /// });
        /// </code>
        /// </remarks>
        /// </summary>
        /// <param name="service">The IService instance you wish will close after invocation</param>
        /// <param name="action">The Action delegate to execute before the service is closed.</param>
        public static void Using(this IService service, Action action)
        {
            ICommunicationObject communicationObject = service as ICommunicationObject;
            try
            {
                action();
                service.SafeDispose();
            }
            catch (CommunicationException cex)
            {
                Log.Error(String.Format("CommunicationException occured calling service method on {0}", service.GetType().Name), cex);

                if (communicationObject != null)
                    communicationObject.Abort();
                throw;
            }
            catch (TimeoutException tex)
            {
                Log.Error(String.Format("TimeoutException occured calling service method on {0}", service.GetType().Name), tex);

                if (communicationObject != null)
                    communicationObject.Abort();
                throw;
            }
        }