Tags » Code Snippets

C# Property Interception

Have you ever wanted (or needed!) to encrypt a C# object’s children with potentially different keys or different methods? How, then, do you implement inline object encryption in a way that’s essentially transparent to a developer… 1,575 more words

Security

Calling Synchronous Methods Asynchronously

Calling Asynchronously through Delegate

namespace AsyncFunction
{
    class Program
    {
        static void Main(string[] args)
        {
            LongRequestAsync("Async data to process.. ", (cbr) =>
            {
                Console.WriteLine(cbr);
            });

            Console.WriteLine("Control on main function");

            Console.Read();
        }


        public delegate string LongRequestDelegate(string data);

        public static void LongRequestAsync(string data, Action callback)
        {
            LongRequestDelegate longRequest = LongRequest;
            longRequest.BeginInvoke(data, (ac) =>
            {
                string res = longRequest.EndInvoke(ac);
                callback(res);
            }, null);
        }
    
        public static string LongRequest(string data)
        {
            Thread.Sleep(2000);
            return "long request result";
        }

    }
}
… 62 more words
Code Snippets

Object Oriented Programing with Python - Particle Diffusion Simulation

I’m a newbie to the programming world. I first started programming in Python in May this year, a month after I started this blog, so I still haven’t learnt enough to… 102 more words

Technical

How to deploy multiple Node.js Socket.IO servers with Nginx and SSL

A late post this time. I spent a good part of the past week figuring out how to deploy one or more Socket.IO-based Node.js servers using Nginx. 967 more words

Code Snippets

Hide a Layout Page Div Using JavaScript

There’s so much I need to share; however, I’m usually busy or I forget.  This time, I remembered though; so, here’s a neat snippet that someone might fine useful. 324 more words

Code Snippets

The Builder pattern

The builder pattern – the code should be self explanatory (I hope).

public class Person{
  private String firstname, lastname, phonenumber;

  private Person(PersonBuilder builder){
    this.firstname = builder.firstname;
    this.lastname = builder.lastname;
    this.phonenumber = builder.phonenumber;
  }

  public String getFirstname(){
    return firstname;
  }

  public String toString(){
    return "Firstname: " + firstname + " lastname: " + lastname + " phonenumber: " + phonenumber;
  }

  public static class PersonBuilder {
    private String firstname, lastname, phonenumber;

    public Person build() {
      return new Person(this);
    }

    public PersonBuilder withFirstname(String firstname){
      this.firstname = firstname;
      return this;
    }

    public PersonBuilder withLastname(String lastname){
      this.lastname = lastname;
      return this;
    }

    public PersonBuilder withPhonenumber(String phonenumber){
      this.phonenumber = phonenumber;
      return this;
    }

    /**
     * Just a sprinkle of syntactic sugar
    **/
    public PersonBuilder and(){
      return this;
    }
  }

  public static void main(String[] args){
    Person person = new PersonBuilder()
      .withFirstname("Sonni")
        .and()
      .withLastname("Nielsen")
        .and()
      .withPhonenumber("066123456")
      .build();

    System.out.println(person);
  }
}
Java

How To Use Cache In Magento

In this section we will see how to use cache in our custom modules. Suppose you have a custom module and wanted to save some data in magento cache, lets see how to do it. 114 more words

Magento