background preloader

Programming

Facebook Twitter

Lockpicking LG #150. By Aurelian Melinte "When two trains approach each other at a crossing, both shall come to a full stop and neither shall start up again until the other has gone. " -- old Kansas statute Overview The dynamic linker allows us to override functions exported by the shared objects that are used by programs. In this article, we will use this interposition functionality and build a library that wraps around the 'pthreads' library to diagnose mutex-related problems, including the well-known deadlock. Deadlocks and how to avoid them Simply put, a deadlock is a run-time condition where threads are waiting for resources in a circular chain. To keep things simple for our debugging library, let's assume the resources that threads are competing for are all mutexes. With pthreads, a thread can also self-deadlock if it attempts to lock a mutex it already owns.

As type PTHREAD_MUTEX_ERRORCHECK. Library interposition Hooking pthreads We need to know which thread acquires and releases what and when. Resources. Design Patterns and Refactoring. Singleton Pattern. Motivation Sometimes it's important to have only one instance for a class. For example, in a system there should be only one window manager (or only a file system or only a print spooler). Usually singletons are used for centralized management of internal or external resources and they provide a global point of access to themselves. The singleton pattern is one of the simplest design patterns: it involves only one class which is responsible to instantiate itself, to make sure it creates not more than one instance; in the same time it provides a global point of access to that instance. Intent Ensure that only one instance of a class is created.Provide a global point of access to the object.

Implementation The implementation involves a static member in the "Singleton" class, a private constructor and a static public method that returns a reference to the static member. You can notice in the above code that getInstance method ensures that only one instance of the class is created. Serialization. Android Development, Part 5a: Starting Activities. This is Part 5a of an ongoing series. The rest of the series is always viewable and up to date at . If you're just checking in, the archives are worth a look. I took a week off, but I'm back with more details on user interfaces. Again, I'm not a designer, nor will I ever claim to be, but I have had a bit of experience with getting a few screens running in the application I'm writing for Pay It Square .

I'm going to cover a technique I use to start new actions. But that's difficult to do because starting activities requires a reference to the context. So, what does this look like? 1: public interface IActivityStarter { 2: void setClassName(String packageName, String className); 3: void putExtra(String name, Serializable value ); 4: void startActivity(); I'm not doing anything too complicated when it comes to starting another activity - a user takes an action on a screen, and that takes them to another screen. Let's back up a step. 2: < intent-filter > 3: @Inject. Singleton Pattern - Web Tutorials - avajava.com. Singleton Pattern Author: Deron Eriksson Description: This Java tutorial describes the singleton pattern, a popular creational design pattern.

Tutorial created using: Windows Vista || JDK 1.6.0_11 || Eclipse JEE Ganymede SR1 (Eclipse 3.4.1) A singleton is a class that is instantiated only once. This is typically accomplished by creating a static field in the class representing the class. A static method exists on the class to obtain the instance of the class and is typically named something such as getInstance(). The creation of the object referenced by the static field can be done either when the class is initialized or the first time that getInstance() is called. The SingletonExample class is an example of a typical singleton class. SingletonExample.java The Demo class obtains a SingletonExample singleton class via the call to the static SingletonExample.getInstance().

Demo.java Singleton classes are a useful way of concentrating access to particular resources into a single class instance. Signs that you're a bad programmer - Software Engineering Tips. Why was this written? Most of these faults were discovered the hard way by the author himself, either because he committed them himself or saw them in the work of others.

This paper is not meant for grading programmers, it was intended to be read by programmers who trust their ability to judge when something is a sign of bad practice, and when it's a consequence of special circumstances. This paper was written to force its author to think, and published because he thinks you lot would probably get a kick out of it, too. 1. Inability to reason about code Reasoning about code means being able to follow the execution path ("running the program in your head") while knowing what the goal of the code is. Symptoms Remedies To get over this deficiency a programmer can practice by using the IDE's own debugger as an aide, if it has the ability to step through the code one line at a time. 2. Object Oriented Programming is an example of a language model, as is Functional or Declarative programming. 3. 4.

Scripting Languages: PHP, Perl, Python, Ruby, Smalltalk. A side-by-side reference sheet sheet one: version | grammar and execution | variables and expressions | arithmetic and logic | strings | regexes | dates and time | arrays | dictionaries | functions | execution control | exceptions | threads sheet two: streams | asynchronous events | files | file formats | directories | processes and environment | option parsing | libraries and namespaces | objects | inheritance and polymorphism | reflection | net and web | gui | databases | unit tests | logging | debugging sheet two: streams | asynchronous events | files | directories | processes and environment | option parsing | libraries and namespaces | objects | inheritance and polymorphism | reflection | net and web | gui | databases | unit tests | logging | debugging version used The versions used for testing code in the reference sheet. show version How to get the version. php: The function phpversion() will return the version number as a string. python: import platform platform.python_version() ruby: <?

Pad. IPC:Sockets. Subsections Sockets provide point-to-point, two-way communication between two processes. Sockets are very versatile and are a basic component of interprocess and intersystem communication. A socket is an endpoint of communication to which a name can be bound. It has a type and one or more associated processes. Sockets exist in communication domains. A socket domain is an abstraction that provides an addressing structure and a set of protocols. Sockets connect only with sockets in the same domain. The UNIX domain provides a socket address space on a single system. Internet domain communication uses the TCP/IP internet protocol suite. Socket types define the communication properties visible to the application. A stream socket -- provides two-way, sequenced, reliable, and unduplicated flow of data with no record boundaries.

A datagram socket -- supports a two-way flow of messages. A sequential packet socket A raw socket provides access to the underlying communication protocols. socket_server.c. Linux Howtos: C/C++ -> Sockets Tutorial. You are here: Programming->C/C++This is a simple tutorial on using sockets for interprocess communication. The client server model Most interprocess communication uses the client server model. These terms refer to the two processes which will be communicating with each other. One of the two processes, the client, connects to the other process, the server, typically to make a request for information.

A good analogy is a person who makes a phone call to another person. Notice that the client needs to know of the existence of and the address of the server, but the server does not need to know the address of (or even the existence of) the client prior to the connection being established. Notice also that once a connection is established, both sides can send and receive information. The system calls for establishing a connection are somewhat different for the client and the server, but both involve the basic construct of a socket.A socket is one end of an interprocess communication channel. 50 Places You Can Learn to Code (for Free) Online. If you’re curious about learning a programming language then you’re in luck: there’s no shortage of resources for learning how to code online.

University-level courses, tutorials, cheat sheets, and coding communities all offer excellent ways to pick up a new language, and maybe even a new job, too. Read on, and you’ll discover 50 great places to learn how to code, for free, online. University Many big names in education including MIT and Stanford offer programming courses, absolutely free. General If you’re just dipping your toes into programming, or you want to find a variety of resources, these sites offer several different ways to learn how to code.

Community Learn how to code on these sites with a heavy community influence ready to offer help to newbs. Language Specific Drill down to the language you really want on these sites, offering expansive learning in one or two specific languages. C++ Exception Handling. An exception is a problem that arises during the execution of a program. A C++ exception is a response to an exceptional circumstance that arises while a program is running, such as an attempt to divide by zero. Exceptions provide a way to transfer control from one part of a program to another. C++ exception handling is built upon three keywords: try, catch, and throw. throw: A program throws an exception when a problem shows up.

This is done using a throw keyword.catch: A program catches an exception with an exception handler at the place in a program where you want to handle the problem. The catch keyword indicates the catching of an exception.try: A try block identifies a block of code for which particular exceptions will be activated. It's followed by one or more catch blocks. Assuming a block will raise an exception, a method catches an exception using a combination of the try and catch keywords. Throwing Exceptions: Catching Exceptions: Division by zero condition! Install Tutorial for NetBeans and Qt on Windows. Install Tutorial for Netbeans and Qt on Windows 1. Install NetBeans IDE and the C/C++ plugin module. Click here to download NetBeans C/C++ 7.0.1 2. Download and install MSYS-1.0.10.exe in the default location.

Click here to download MSYS-1.0.10 3. 4. 5. The C Library Reference Guide.