End of job check list

I'm about to end my first gig(already end! yay I'm free!) as a programmer, and want to leave a clean desk. So here is a list of things I'm doing and suggest you all do before you move to your next gig: 1. Write about your major infrastructure developments on your wiki or any other system you got, in an easy to understand language. 2. Start lecturing your co-workers about complex parts you developed. 3. Make sure you got full code coverage with unit tests. 4. Search for to-do comments and make sure you do those todo's. 5. If you got unfinished work and think it's worth something make sure someone complete. And the most important: change your phone number :-) (Bazinga).

November 16, 2011 · 1 min · Chen Kinnrot

Startups: reshare very nice research

The Startup Gamble [infographic] | Daily Infographic

October 28, 2011 · 1 min · Chen Kinnrot

Rubymine recommended font for windows

Didn’t find a lot about it on internet so: File->Settings->Editor->colors & fonts->Font first save as current schema than click the … button choose Consolas and set size to 14 looks much better!

September 27, 2011 · 1 min · Chen Kinnrot

MVC Frameworks and dynamic languages

Warning! just figure out a mistake that can happen to every other programmer, and even brogrammers. I defined a method on my model that has the same name as one of the field of the model, because I used a dynamic language (ruby on rails) it was pretty hard to understand this issue (took me more than 1 hour). So a little tip: When thinking about names of actions and fields of your model, work with conventions and guidelines like: Don’t name your fields after action names!!! that’s it.

September 27, 2011 · 1 min · Chen Kinnrot

Boolean parameters

It’s not fun to look at a method call that sends more than 0 boolean parameters. Code SnippetSetBinding(false, false, comboBox); There is 100% guarantee that you will look for the documentation about this parameters and it'll slow your code reading speed. Here is a nice way to avoid the unreadable code and keep on using this meaningless Boolean. Code Snippet SetBinding(/* auto resolve= */ false, /* two way binding? = */ false, comboBox); This is not my idea though, it's from Microsoft pdb's, and I think its awesome.

August 31, 2011 · 1 min · Chen Kinnrot

If you're searching for a good place to grow

http://crossrider.com/pages/jobs I know this guys and worked with them a little, very recommended for any developer.

August 4, 2011 · 1 min · Chen Kinnrot

Dont return and linq on the same line

Just a little tip for writing a friendlier code. If you're method returns an expression, first assign it to a variable and then return him. It'll be much easier to debug inside this method and fetch all results when watching this variable. That's it !

August 2, 2011 · 1 min · Chen Kinnrot

TPLing Background worker in 10 min

Code Snippetusing System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;using System.Threading.Tasks; namespace WpfApplication1{ public class TBackgroundWorker<TResult, TProgress> {  public static TBackgroundWorker<TResult, TProgress> New() { return new TBackgroundWorker<TResult, TProgress>(); }  public TBackgroundWorker<TResult, TProgress> StartWith(Func<object, CancellationToken, TResult> work) { Start = work; return this; }  public TBackgroundWorker<TResult, TProgress> FinishWith(Action<TResult,object> finish) { Finish = finish; return this; }  private readonly CancellationTokenSource _cancelationTokenSource; private CancellationToken _cancellationToken; private readonly TaskScheduler _uiScheduler;   public TBackgroundWorker() { _cancelationTokenSource = new CancellationTokenSource(); _uiScheduler = TaskScheduler.FromCurrentSynchronizationContext(); }  protected Func<object, CancellationToken,TResult> Start { get; set; } protected Action<TResult, object> Finish { get; set; }  public void ReportProgress(Action<TProgress> progressReport,TProgress progress) { Task.Factory.StartNew(()=>progressReport(progress),CancellationToken.None,TaskCreationOptions.None,_uiScheduler); }  public TBackgroundWorker<TResult, TProgress> Begin(object state = null) { _cancellationToken = _cancelationTokenSource.Token; Task<TResult>.Factory. StartNew(()=>Start(state,_cancellationToken),_cancellationToken). ContinueWith(x => Finish(x.Result,state), _uiScheduler);  return this; }  public void Cancel() { _cancelationTokenSource.Cancel(true); } }} usage Code Snippetusing System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes; namespace WpfApplication1{ /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { private TBackgroundWorker<string, int> _bg;  public MainWindow() { InitializeComponent(); }  private void a_Click(object sender, RoutedEventArgs e) { _bg = TBackgroundWorker<string, int>.New(). StartWith(StartSomething). FinishWith(ShowResult). Begin(); }  private void ShowResult(string obj,object state) { a.Content = obj; }  private string StartSomething(object arg, CancellationToken cancellationToken) { int i = 0; while (i < 200) { if (cancellationToken.IsCancellationRequested) { return "Cacncelled"; } i++; Thread.Sleep(50); _bg.ReportProgress(Report,i); }  return "Done"; }  private void Report(int obj) { a.Content = obj; }  private void Button_Click(object sender, RoutedEventArgs e) { _bg.Cancel(); }  }}

June 16, 2011 · 2 min · Chen Kinnrot

Passing complex type through WCF header,The simple always work version.

Recently I tried to find a nice code sample for how to pass complex type through WCF, inside the header, meaning I want to send the client execution context to the server side. All of the samples passes strings or uses custom header that needs to write and read the object manually, I didn’t like it. So I wrote one and it’s working! All you need is 2 classes, and one is just a factory for the other, very simple: using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Dispatcher; using System.Text; namespace debugniv.ComplexTypeOverWcf { class HeaderHandler : IDispatchMessageInspector, IClientMessageInspector { #region Implementation of IDispatchMessageInspector public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext) { // Read the complex type from header var headerIndex = request.Headers.FindHeader(typeof(MyHeader).Name, typeof(MyHeader).Namespace); if (headerIndex >= 0) // found! { var serializer = GenerateDataContractSerializer<MyHeader>(); var myHeader = request.Headers.GetHeader<MyHeader>(headerIndex, serializer); // here you can do something with your header like push it to a global per request context. } return null; } public void BeforeSendReply(ref Message reply, object correlationState) { // nothing here } #endregion #region Implementation of IClientMessageInspector public object BeforeSendRequest(ref Message request, IClientChannel channel) { var myHeader = GetMyHeader(); request.Headers.Add(myHeader); } public void AfterReceiveReply(ref Message reply, object correlationState) { // nothing to do here } #endregion private DataContractSerializer GenerateDataContractSerializer<T>() { return new DataContractSerializer(typeof(T), typeof(T).Name, typeof(T).Namespace, GetKnownTypes()); } private IEnumerable<Type> GetKnownTypes() { // here return all your types inside the header yield return typeof(MyHeader); yield return typeof(SubType); } private MessageHeader GetMyHeader() { var data = new MyHeader(); var serializer = GenerateDataContractSerializer<MyHeader>(); return MessageHeader.CreateHeader(data.GetType().Name, data.GetType().Namespace, data, serializer); } } // this is the header internal class MyHeader { public SubType InternalData { get; set; } } internal class SubType { } } The second thing you’ll need is to attach this stuff to your service and proxy, here is one way to do this using System; using System.ServiceModel.Configuration; namespace debugniv.ComplexTypeOverWcf { public class HeaderExtensionElement : BehaviorExtensionElement { public override Type BehaviorType { get { return typeof (HeaderHandler); } } protected override object CreateBehavior() { return new HeaderHandler(); } } } In you config file add the following

May 2, 2011 · 2 min · Chen Kinnrot

IOC Container warning

Think about a registered component that implement copy constructor. You’ll get a Stack Overflow Exception! So avoid it.

April 23, 2011 · 1 min · Chen Kinnrot